[R] Error in nlme with factors in R 2.4.1
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Mar 27 16:39:48 CEST 2007
HERBICIDE is already a factor, and this works without the unneeded
factor() calls.
Notice that you used a different version of nlme in R 2.4.0 and R 2.4.1,
so you have not established that the change in R version is responsible.
In fact, it is not: it is caused by the update of nlme to 3.1-78 and
AFAICS by this change (r4013)
2006-12-06 Douglas Bates <bates at stat.wisc.edu>
* R/nlme.R (contrMat): Ensure that the constrasts component is a
list of matrices by expanding function names if necessary.
On Tue, 20 Mar 2007, Christian Ritz wrote:
> Hi,
>
> the following R lines work fine in R 2.4.0, but not in R 2.4.1 or any devel versions of R
> 2.5.0 (see below for details).
>
>
> library(drc) # to load the dataset 'PestSci'
>
> library(nlme)
>
>
> ## Setting starting values
> sv <- c(0.43355869, 2.49963220, 0.05861799, 1.73290589, 0.38153146, 0.24316978)
>
>
> ## No error
> m1 <-
> nlme(SLOPE ~ c + (d-c)/(1+exp(b*(log(DOSE)-log(e)))),
> fixed = list(b+c+d+e~1),
> random = d~1|CURVE,
> start = sv[c(2:5)], data = PestSci)
>
>
> ## No error
> m2 <- nlme(SLOPE ~ c + (d-c)/(1+exp(b*(log(DOSE)-log(e)))),
> fixed = list(b~HERBICIDE, c+d+e~1),
> random = d~1|CURVE,
> start = sv[c(1:5)], data = PestSci)
>
>
> ## Error in R 2.4.1!
> m3 <-
> nlme(SLOPE ~ c + (d-c)/(1+exp(b*(log(DOSE)-log(e)))),
> fixed = list(b~factor(HERBICIDE)-1, c~1, d~1, e~factor(HERBICIDE)-1),
> random = d~1|CURVE,
> start = sv, data = PestSci)
>
> Error in dimnames(data) <- dimnames : length of 'dimnames' [1] not equal to array extent
>
>
> An ensuing call to traceback() yields:
>
> 7: array(0, c(n, n), list(levs, levs))
> 6: contr.treatment(n = 0)
> 5: do.call(contr[[nm]], list(n = length(levs)))
> 4: FUN("factor(HERBICIDE)"[[1]], ...)
> 3: lapply(nms, contrMat, contr = contr, data = dataMix)
> 2: nlme.formula(SLOPE ~ c + (d - c)/(1 + exp(b * (log(DOSE) - log(e)))),
> fixed = list(b ~ factor(HERBICIDE) - 1, c ~ 1, d ~ 1, e ~
> factor(HERBICIDE) - 1), random = d ~ 1 | CURVE, start = sv,
> data = PestSci)
> 1: nlme(SLOPE ~ c + (d - c)/(1 + exp(b * (log(DOSE) - log(e)))),
> fixed = list(b ~ factor(HERBICIDE) - 1, c ~ 1, d ~ 1, e ~
> factor(HERBICIDE) - 1), random = d ~ 1 | CURVE, start = sv,
> data = PestSci)
>
>
>
>
>
> Output from sessionInfo() for R 2.4.0
>
> R version 2.4.0 (2006-10-03)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=Danish_Denmark.1252;LC_CTYPE=Danish_Denmark.1252;LC_MONETARY=Danish_Denmark.1252;LC_NUMERIC=C;LC_TIME=Danish_Denmark.1252
>
> attached base packages:
> [1] "methods" "stats" "graphics" "grDevices" "utils" "datasets"
> [7] "base"
>
> other attached packages:
> drc plotrix nlme MASS lattice
> "1.0-7" "2.1-1" "3.1-77" "7.2-29" "0.14-9"
>
>
> Output from sessionInfo() for R 2.4.1
>
> R version 2.4.1 (2006-12-18)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=Danish_Denmark.1252;LC_CTYPE=Danish_Denmark.1252;LC_MONETARY=Danish_Denmark.1252;LC_NUMERIC=C;LC_TIME=Danish_Denmark.1252
>
> attached base packages:
> [1] "stats" "graphics" "grDevices" "utils"
> [5] "datasets" "methods" "base"
>
> other attached packages:
> drc plotrix nlme MASS lattice
> "1.0-7" "2.1-6" "3.1-78" "7.2-30" "0.14-16"
>
>
>
>
>
>
> Christian
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Brian D. Ripley, ripley at 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
More information about the R-help
mailing list