Re: [R] Question about curve fitting...

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 11 Aug 2005 - 10:37:35 EST

Note that even if you decide that this distinction is applicable, you may still wish to run a linear model prior to nls to get the starting values.

On 8/10/05, Dimitris Rizopoulos <dimitris.rizopoulos@med.kuleuven.be> wrote:
> I think here it's important to consider how the errors term come into
> the model. If "y = k1 * x^k2 * e" then in the log-scale you have a
> linear model; however if you assume that "y = k1 * x^k2 + e", the you
> want a nonlinear model (i.e., nls()). For instance,
>
> x <- runif(500, 1, 3)
> y <- 1 * x^2 + rnorm(500)
> m <- nls(y ~ exp(k1 + k2 * log(x)), start = c("k1" = 1, "k2" = 2))
> c(exp(coef(m)[1]), coef(m)[2])

>
>
> I hope it helps.
>
> Best,
> Dimitris
>
> ----
> Dimitris Rizopoulos
> Ph.D. Student
> Biostatistical Centre
> School of Public Health
> Catholic University of Leuven
>
> Address: Kapucijnenvoer 35, Leuven, Belgium
> Tel: +32/16/336899
> Fax: +32/16/337015
> Web: http://www.med.kuleuven.be/biostat/
> http://www.student.kuleuven.be/~m0390867/dimitris.htm
>
>
> ----- Original Message -----
> From: "Dan Bolser" <dmb@mrc-dunn.cam.ac.uk>
> To: "S.O. Nyangoma" <S.O.Nyangoma@amc.uva.nl>
> Cc: "R mailing list" <r-help@stat.math.ethz.ch>
> Sent: Wednesday, August 10, 2005 4:53 PM
> Subject: Re: [R] Question about curve fitting...
>
>
> > On Wed, 10 Aug 2005, S.O. Nyangoma wrote:
> >
> >>I see that
> >>log(y)=log(k1)+k2*log(x)
> >>use lm?
> >
> > Thats a nice solution in this instance, but in general how do I get
> > R to
> > fit a particular function (formula) and return the parameters?
> >
> > Cheers,
> > Dan.
> >
> >>
> >>----- Original Message -----
> >>From: Dan Bolser <dmb@mrc-dunn.cam.ac.uk>
> >>Date: Wednesday, August 10, 2005 11:41 am
> >>Subject: [R] Question about curve fitting...
> >>
> >>>
> >>> Meta:
> >>> This question is somewhat long and has two parts, I would be very
> >>> happyfor someone just to nudge me in the right direction with the
> >>> manual /
> >>> tutorial, as I am somewhat lost...
> >>>
> >>>
> >>> 1) How do I fit a curve of the form "y = k1 * x^k2" ?
> >>>
> >>> I want to estimate values of k1 and k2 given the x/y data I have,
> >>> and I
> >>> can't work out how to get R to calculate and return their
> >>> estimates.
> >>>
> >>>
> >>> 2) Given the value of k1 and k2 for population A, how can I test
> >>> if
> >>> population B has significantly different values of k1 and k2?
> >>>
> >>> Sorry for the basic question. I think I just need to read up on a
> >>> few
> >>> functions.
> >>>
> >>>
> >>> I have about 50 xy pairs in total if that makes a difference.
> >>>
> >>> Dan.
> >>>
> >>> ______________________________________________
> >>> R-help@stat.math.ethz.ch mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> PLEASE do read the posting guide!
> >>> http://www.R-project.org/posting-
> >>> guide.html
> >>
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Aug 11 10:47:22 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:13:14 EST