Solved – Logarithmic Regression by hand

nonlinear regressionregression

I'm trying to write some code to do a regression on data weight (x) and time (y). As best as I can tell, the model should be y = b1 + b2ln(x), but I don't know how you can do this by hand (I know how to in R…). I know how to do a simple linear regression by hand. Appreciate it.

Best Answer

You say that you'd calculate the slope as follows:

So normally you would calculate

$$S_{XX} = \sum_i (x_i-\bar x)^2\\ S_{XY} = \sum_i ((x_i-\bar x)(y_i-\bar y))\\ S_{YY} = \sum(y_i-\bar y)^2$$

Then $b_2 = S_{XY}/S_{XX}$.

So imagine you have a set of x-values and y-values:

    y       x
1 2.3 0.36772
2 5.3 1.64873
3 6.5 7.38910

Step 1:

calculate a new $x$, $x_1 = \ln(x)$

    y   x1
1 2.3 -1.0
2 5.3  0.5
3 6.5  2.0

Now regress $y$ on this new $x_1$ as usual

 SXX = 4.50; SXY= 6.30; SYY = 9.36

 b2 = SXY/SXX = 1.4

 b1 = mean(y) - b2 . mean(x) = 4.7 - 1.4 . 0.5 = 4

enter image description here

Related Question