I agree that this seems to be a bug, but OTOH the help for dummy.coef() 
*does* say:

> The method used has some limitations, and will give incomplete results 
> for terms such as |poly(x, 2)|.

(Note that it says it will "give incomplete results" not "throw an error"!)

Looking into the code of dummy.coef.lm() I find that the problem seems 
to reside in all.vars().
When all.vars(Terms) is applied inside dummy.coef.lm() it returns

> [1] "group" "x"

rather than
> [1] "group"  "x"      "I(x^2)"

which is what I think it should return.  The workings of all.vars() are 
buried in
the bowels of the internal structure, so I can take it no farther.  
Whether there
is a practical way to make all.vars() "do the right thing" in this 
setting I know
not.  Perhaps one of the Big Guns can provide some insight.

As a workaround, you can do:

     x2 <- x^2
     lm.D9 <- lm(weight ~ group + x + x2)
     dummy.coef(lm.D9)

This worked for me, at least.

     cheers,

     Rolf Turner


On 10/24/13 21:51, Alexandra Kuznetsova wrote:
> Dear all,
>
> Running the following code produces an error in dummy.coef. I guess it might 
> be a bug..
>
>> ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
>> trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
>> group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
>> weight <- c(ctl, trt)
>> x <- rnorm(length(weight))
>> lm.D9 <- lm(weight ~ group + x + I(x^2))
>> dummy.coef(lm.D9)
> Error in rep.int(xl[[i]][1L], nl) : invalid 'times' value
>
>
>
>> sessionInfo()
> R version 3.0.1 (2013-05-16)
>
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
>
>
> locale:
>
> [1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252    
> LC_MONETARY=Danish_Denmark.1252
>
> [4] LC_NUMERIC=C                    LC_TIME=Danish_Denmark.1252
>
>
>
> attached base packages:
>
> [1] parallel  splines   stats     graphics  grDevices utils     datasets  
> methods   base
>
>
>
> other attached packages:
>
>   [1] pbkrtest_0.3-5    MASS_7.3-26       Hmisc_3.12-2      Formula_1.1-1     
> survival_2.37-4   numDeriv_2012.9-1
>
>   [7] lmerTest_2.0-1    lme4_1.1-1        Matrix_1.0-12     lattice_0.20-15
>
>
>
> loaded via a namespace (and not attached):
>
> [1] cluster_1.14.4 gdata_2.13.2   gplots_2.11.3  grid_3.0.1     gtools_3.0.0  
>  minqa_1.2.1    nlme_3.1-109
>
> [8] rpart_4.1-1    tools_3.0.1

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to