[R] bug in dummy.coef?
Martin Maechler
maechler at stat.math.ethz.ch
Mon Oct 28 13:37:38 CET 2013
>>>>> Rolf Turner <r.turner at auckland.ac.nz>
>>>>> on Sat, 26 Oct 2013 09:34:14 +1300 writes:
> On 10/25/13 19:24, Alexandra Kuznetsova wrote:
>> Thank you for the reply! I need to use it in the package
>> for constructing the contrast matrices.
> Really?
>> Renaming a variable like y2 <- y^2 will not be a solution
>> for me...
> With sufficient effort and diligence (and programming
> skill) I am sure that this technique could be made to work
> in your context.
>> Will try to look whether the function dummy.coef can be
>> modified to work this issue.
> As I said before, the problem is really buried inside
> the all.vars() function, whose workings are buried in the
> R internals. This would not be at all easy (and would
> probably be dangerous) to modify.
Well, I've now spent much too much time on this now, trying to
explore possible changes.
It's definitely an order more complicated than you think, Rolf.
A change to all.vars() would break other cases and other code.
But I now strongly believe it's not even that part of
dummy.coef.lm() that needs to be amended.
Consider example(dummy.coef) 's examples,
and also the test case from R/tests/reg-tests-1a.R, i.e., the
following block
## PR 1048 bug in dummy.coef.lm, Adrian Baddeley, 2001-08-10
## modified to give a sensible test
old <- getOption("contrasts")
options(contrasts=c("contr.helmert", "contr.poly"))
DF <- data.frame(x=1:20,y=rnorm(20),z=factor(1:20 <= 10))
dummy.coef(lm(y ~ z * I(x), data=DF))
dummy.coef(lm(y ~ z * poly(x,1), data=DF))
## failed in 1.3.0. Second one warns: deficiency of the method.
options(contrasts=old)
where interestingly, there is no warning anymore, even though
the comment says there would be one, and I think I see the warning
in dummy.coef.lm's code ... which would been triggered somewhere in the
past ...
Many years ago, partly in S / S+ times, we used to advocate the
use of model.tables() over dummy.coef(), but as you can see on
its help page, it is neither implemented for all cases.
Martin Maechler, ETH Zurich
More information about the R-help
mailing list