I will consider putting methods for AIC and logLik into the next version
of minpack.lm (contributions welcome).
For now, the following should work for logLik, where 'object' is the
return value of nls.lm.
logLik.nls.lm <- function(object, REML = FALSE, ...)
{
res <- object$fvec
N <- length(res)
val <- -N * (log(2 * pi) + 1 - log(N) + log(sum(res^2)))/2
## the formula here corresponds to estimating sigma^2.
attr(val, "df") <- 1L + length(coef(object))
attr(val, "nobs") <- attr(val, "nall") <- N
class(val) <- "logLik"
val
}
On Tue, 16 Feb 2010, Baudron, Alan Ronan wrote:
> Hi there,
>
> I'm a PhD student investigating growth patterns in fish. I've been
using
> the minpack.lm package to fit extended von Bertalanffy growth models
> that include explanatory covariates (temperature and density). I found
> the nls.lm comand a powerful tool to fit models with a lot of
> parameters. However, in order to select the best model over the possible
> candidates (without covariates, with both covariates, or with only one
> of them) I'd like to compare them based on their AIC criterion.
However,
> it seems that the nls.lm comand doesn't return an AIC, or a Log
> Likelihood. Does someone have any idea of how I could proceed to get
> such informations about my models?
>
> Thanks for your help. Best regards,
>
> Alan Baudron
>
>
> The University of Aberdeen is a charity registered in Scotland, No
SC013683.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>