Skip to content

fitting nonlinear model

7 messages · Bill Hyman, Charlie Sharpsteen, milton ruser

#
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!
#
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:
And which equation are you trying to fit to this data?

-Charlie

-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
#
Bill Hyman wrote:
That's why information equation you are trying to fit is very important. For
example, the BOD data set in R is:
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