[R] fitting nonlinear model

cls59 chuck at sharpsteen.net
Wed Sep 9 21:35:56 CEST 2009




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.




More information about the R-help mailing list