[R] A problem with anova()
Peter Dalgaard
P.Dalgaard at biostat.ku.dk
Fri May 9 14:08:59 CEST 2008
Christian Ritz wrote:
> Hi Peter,
>
> I think one option for what anova could do in the nonlinear case is to
> report the analysis of variance (or deviance) table obtained when
> doing a lack-of-fit test, that is comparing the nonlinear regression
> model to an appropriate ANOVA model. This is for example the use of
> anova in the package 'drc':
>
> ## Using the package 'drc' from CRAN
> library(drc)
>
> ## Fitting the 4-par log-logistic model
> ryegrass.ll <- drm(rootl ~ conc, data = ryegrass, fct = LL.4())
>
> ## ANOVA table for the lack-of-fit test
> anova(ryegrass.ll)
>
I think I prefer to do that explicitly. You don't always have an
"appropriate ANOVA model" with which to compare. And anova.nls() will do
this just fine, you just have to remember to put the nonlinear model
first (because of S3 dispatching).
> boc <-
read.table("http://staff.pubhealth.ku.dk/~pd/varians_regression/data/bif.txt",header=T)
> a.fit <- lm(boc~factor(days), data=boc)
> n.fit <- nls(boc~gamma*exp(-beta/days), start=c(gamma=250, beta=0.8),
data=boc)
> anova(n.fit,a.fit)
Analysis of Variance Table
Model 1: boc ~ gamma * exp(-beta/days)
Model 2: boc ~ factor(days)
Res.Df Res.Sum Sq Df Sum Sq F value Pr(>F)
1 22 2585.39
2 18 2130.50 4 454.89 0.9608 0.4527
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list