Skip to content
Back to formatted view

Raw Message

Message-ID: <XFMail.040109203406.Ted.Harding@nessie.mcc.ac.uk>
Date: 2004-01-10T09:21:06Z
From: (Ted Harding)
Subject: Fit non-linear regressor
In-Reply-To: <6.0.1.1.2.20040109163309.02c51010@pop.centroin.com.br>

On 09-Jan-04 Bernardo Rangel Tura wrote:
> Hi R masters,
> 
> Sorry for first mensage, this is orignal text...
> 
> y<-c(2.8150,3.5239,4.0980,4.5845,5.0709,5.4824,5.8427,6.3214,6.7349,7.36
> 51)
> x<-c(37,42,47,52,57,62,67,72,77,82)
> 
> I need fit R and A in y=f(x)=R*exp(A*x), with minimize sd=
> sqrt(SRR/(n-2)) where SRR is Sum of the Square of the Residuals 
> and n is number of data points (in this case 10)
> 
> How do I make this?

What is your objection, with these data, to a linear regression
of log(y) on x? This would give you log(R) as intercept
and A as slope, and you can get back to y by exponentiating;
though it would not quite minimise what you want, rather minimising
the SS of residuals of log(y).

Or indeed, now that I look more closely, even a simple linear
regression of y on x?

[Perhaps you need the fitted relationship to be "realistic" over
 the unobserved range (0,36) of x; but the lower end of this will
 be poorly estimated.]

  y<-c(2.8150,3.5239,4.0980,4.5845,5.0709,
       5.4824,5.8427,6.3214,6.7349,7.3651)
  x<-c(37,42,47,52,57,62,67,72,77,82)
  lm1<-lm(y~x)
  lm2<-lm(log(y)~x)
  plot(x,y,xlim=c(0,85),ylim=c(0,8))
  a<-lm1$coefficients[1];b<-lm1$coefficients[2]
  lR<-lm2$coefficients[1];A<-lm2$coefficients[2]
  u<-(0:85)
  lines(u,a+b*u,col="red")
  lines(u,exp(lR+A*u))

shows that the the fit lm(y~x) fits the data better than lm(log(y)~x),
over the range of X considered. The data do not match the curvature
of the exponentiated lm2 fit.

I tend to doubt that taking the trouble to do a non-linear fit which
minimises the residuals of y would make a meaningful improvement on
lm(log(y)~x) over this range!

More interesting, perhaps, is the apparent sinusoidal effect -- slight,
but clearly visible relative to the above fitted straight line ...

... what does "x" represent?

With best wishes,
Ted.