I am having trouble using a linear (log-log) model to approximate the predictions of a nonlinear (power) model.
I wish to plot the predictions of the linear model on untransformed axes, and I believe they should approximate those of the nonlinear model. But, I can't make it work.
Here is a toy example with reproducible code:
set.seed(50) x<-rnorm(100,10,2) #make random x data z<-2+rnorm(100,1,0.1) #make random z coefficient y<-3*x^z #make random y data plot(x,y) #plot #fit nonlinear (power) model, and plot predictions m<-nls(y~c*x^z,start=list(c=3,z=2)) plot(y~x);xx<-seq(min(x),max(x),length=100);lines(xx,predict(m,list(x=xx))) #fit linear (log-log) model, and add its predictions to existing plot m2<-lm(log(y,10)~log(x,10)) xx<-seq(min(x),max(x),length=100);lines(x,predict(m2,x=xx),col=2)
As you can see in the image below, the predictions of the nonlinear (black line) and linear model (red line) are not even close.
I am sure I'm doing something wrong, and so would really appreciate any help or tips you might be able to provide! Thank you.