Tuesday, October 8, 2013

Power Regression in R

The power equation has the general form of y = bX^m. I found a good example to calculate the power regression using Excel but I couldn't find a direct method to calculate the power regression in R. In this blog, I will try to explain the same technique using R.
XY
0.021505
0.062182
0.20255.3
0.52322.2
1.00811.3
3.3204.17
7.2901.75

The basic idea is to get the linear regression between log(X) and log(Y), then map the coefficient to the power log m and b. The code in R could be as the following:
x=c(0.021,0.062,0.202,0.523,1.008,3.320,7.290) y=c(505,182,55.3,22.2,11.3,4.17,1.75) fit=lm(log10(x)~log10(y)) fit Call: lm(formula = log10(x) ~ log10(y)) Coefficients: (Intercept) log10(y) 1.124 -1.037 plot(x,y,type="p",col="black") lines(x, 10^ fit$coefficients[1] * x^fit$coefficients[2],type="l",col="red")

No comments:

Post a Comment