[R] fitting allometric equation using a for a power model
peter dalgaard
pdalgd at gmail.com
Fri Jun 1 01:03:54 CEST 2012
On Jun 1, 2012, at 00:14 , Benjamin Caldwell wrote:
> temppow<-lm(log(y)~log(x))
> plot(log(y)~log(x))
> plot(residuals(temppow), main="pow")
> abline(temppow)
> plot(y~x, main="pow")
> tempsum<-summary(temppow)$adj.r.squared
> tempint<-summary(temppow)$coefficients[1,1] #intercept of power function
> tempslope<-summary(temppow)$coefficients[2,1] #slope of power function
> tempmin<-min(x)
> tempmax<-max(x)
> lngth<-c(tempmin:tempmax) # vector from the minimum to the maximum values
> of independent variable
> prediction<-exp(tempint)*((lngth)^tempslope)*exp((summary(temppow)$sigma^2)/2)
> # exp((summary(temppow)$sigma^2)/2) is the bias correction
> #prediction<-exp(tempint+tempslope*log(lngth))*exp((summary(temppow)$sigma^2)/2)
> lines(prediction)
It does help considerably to use lines(length, prediction)!
(And that bias correction looks really dubious to me, but let's not go there...)
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list