s-news
[Top] [All Lists]

Re: question on nls

To: Spencer Graves <spencer.graves@pdf.com>
Subject: Re: question on nls
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Thu, 4 Mar 2004 08:17:06 +0000 (GMT)
Cc: Tropmedres <pan@tropmedres.ac>, <s-news@wubios.wustl.edu>
In-reply-to: <404675FB.9070306@pdf.com>
My version of S-PLUS has 

> methods("AIC")
     nlme3    nlme3        nlme3     nlme3        nlme3     nlme3
 "AIC.gls" "AIC.lm" "AIC.lmList" "AIC.lme" "AIC.logLik" "AIC.nls"

so I think all you need to do is to call AIC on the fitted object. I
believe that to be true for all versions with nlme3 (which was around in
S+2000) and possibly earlier.

It works essentially as Spencer describes, calling logLik.nls.  (It seems 
to allow for weights in the fit.)

On Wed, 3 Mar 2004, Spencer Graves wrote:

>       Recall that nls assumes normal, independent errors.  Thus, the 
> likelihood is
> 
>       prod( (1/(sigma*sqrt(2*pi))*exp(-0.5*(resid[i]/sigma)^2)). 
> 
> Therefore, the log(likelihood) is
> 
>       (-0.5)*( N*log(2*pi*sigma^2) + sum(resid[i]^2)/sigma^2). 
> 
>       You can somehow get the MLE of "sigma", plug this into this 
> formula, and get the log(likelihood).  The AIC is 
> (-2)*(log(likelihood)+k), where k = number of parameters estimated, 
> including sigma. 
> 
>       I don't know the simplest way to get this, and I don't have time 
> to play with it, but ?nls contains a pointer to ?nls.object.  The latter 
> says it has a component "residuals".  From this, you can compute "sigma" 
> = sum(residuals^2)/N, where N = total number of observations.  NOTE:  
> You want to use the MLE here, not (N-k) for the unbiased estimate. 
> 
>       There is probably a much easier way to get this, but I can't think 
> of it right now. 
> 
>       hope this helps. 
>       spencer graves
> 
> Tropmedres wrote:
> 
> >Hello
> >
> >I am doing the curve fitting using the non-linear regression (nls). I am not
> >sure how to select the best model when I cannot get the AIC as in usual lm,
> >glm, gam model. I cannot use the stepAIC function from the MASS library
> >neither. For the nested models I have been using 'anova.nls with test=chisq'
> >but what about the non-nested models?
> >
> >Thank you in advance
> >
> >Wirichada

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>