[R] Fit non-linear regressor
Tony Plate
tplate at acm.org
Fri Jan 9 21:58:45 CET 2004
It's reasonably straightforward to use nls() for this:
> d <-
data.frame(x=c(37,42,47,52,57,62,67,72,77,82),y=c(2.8150,3.5239,4.0980,4.5845,5.0709,5.4824,5.8427,6.3214,6.7349,7.3651))
> fit <- nls(y~R*exp(x*A),start=list(R=2,A=0.1),data=d)
> plot(x,y)
> lines(x, coef(fit)[1]*exp(x*coef(fit)[2]))
>
You might want to check that your objective does not have local optima (in
which case the assumption that minimizing the sum-squared residual will
minimize your objective may be false).
hope this helps,
Tony Plate
At Friday 04:35 PM 1/9/2004 -0200, 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.3651)
>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?
>
>
>Thanks in advance
>
>Bernardo Rangel Tura, MD, MSc
>National Institute of Cardiology Laranjeiras
>Rio de Janeiro Brazil
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Tony Plate tplate at acm.org
More information about the R-help
mailing list