I only have 4 data points and want to fit a curve. It does not work in "modreg" due to too few data. Do you have any idea? Many thanks!
fitting nonlinear model
7 messages · Bill Hyman, Charlie Sharpsteen, milton ruser
My data look like: Np year 96 2 91 5 89 7 85 10 ----- Original Message ---- From: Bill Hyman <billhyman1 at yahoo.com> To: r-help at r-project.org Sent: Wednesday, September 9, 2009 11:23:26 AM Subject: [R] fitting nonlinear model I only have 4 data points and want to fit a curve. It does not work in "modreg" due to too few data. Do you have any idea? Many thanks! ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Bill Hyman wrote:
My data look like: Np year 96 2 91 5 89 7 85 10
And which equation are you trying to fit to this data? -Charlie ----- Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University
View this message in context: http://www.nabble.com/fitting-nonlinear-model-tp25370697p25371220.html Sent from the R help mailing list archive at Nabble.com.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090909/72022d11/attachment-0001.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090909/e2e77216/attachment-0001.pl>
Bill Hyman wrote:
Hi Milton, Thanks for your help. Actually, I would like to fit a non-linear fashion. For some data like below, 'lm' may not work very well. Do you have idea? Thanks again!
That's why information equation you are trying to fit is very important. For example, the BOD data set in R is:
BOD
Time demand
1 1 8.3
2 2 10.3
3 3 19.0
4 4 16.0
5 5 15.6
6 7 19.8
BOD demand can be modeled as a function of Time using the following
equation:
demand = BODu * ( 1 - exp( -K * Time ) )
Where BODu and K are the unknown parameters of the model. One way of doing a
non-linear fit in R is to use nls(), the nonlinear least-squares function:
model <- nls( demand ~ BODu * ( 1 - exp( -K * Time ) ),
data = BOD,
start = list( BODu = max( BOD[['demand']]), k = 0.1 )
)
Note that with nls(), it is necessary to provide starting guesses for the
parameters as a list using the "start" parameters of the nls function.
Hope this helps!
-Charlie
P.S.
Providing an example of the equation you are trying to fit to your data will
help us provide an answer that is more specific to your situation.
-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
View this message in context: http://www.nabble.com/fitting-nonlinear-model-tp25370697p25371862.html Sent from the R help mailing list archive at Nabble.com.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090909/22109e82/attachment-0001.pl>