[R] anova() for nlm or nls

Douglas Bates bates at stat.wisc.edu
Tue Mar 26 22:26:21 CET 2002


Roland Regoes <rregoes at emory.edu> writes:

> Dear R community,
> 
> I am currently fitting non-linear models using nlm and nls.
> 
> 1) I would like to compare the different models analogous to the
> comparison of linear models with anova(). Is there a function in R which
> allows to do that?

For nls there is an anova.nls function that can be used to compare two
or more models.  It is in the nls package.

Because nlm is a general optimization routine it would not be possible
to write a model comparison function for two models fit by nlm.  You
would need to be more specific about what the criterion means
statistically.  For example, if the criterion is the log-likelihood
then you can compare the fitted models via a likelihood ratio test
with p-values determined from a chi-square distribution.

> 2) I would like to constrain the parameter ranges to positive values
> only. Is there an option in nlm or nls which allows to constrain
> parameter ranges? (So far I constrained them "manually" by incorporating
> the constraints into the definition of the functions fitted.)

For nonlinear models I prefer to incorporate the constraints into the
definition of the parameters.  If a parameter such as a rate constant
can only take on positive values then I do the optimization with
respect to the logarithm of the rate constant.  In most such cases the
residual sum of squares is closer to being quadratic in the scale of
the logarithm of the rate constant than in the scale of the rate
constant.  Your mileage may vary.

If you prefer to use constraints you should try the optim function
which offers a constrained optimization method.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list