Skip to content

Opening previous workspace in Windows (PR#2890) (fwd)

7 messages · Torsten Hothorn, Brian Ripley, Peter Dalgaard

#
Filing the response on R-bugs.

It's quite possible that uninstalling R will damage this, but I would have 
expected it to be removed entirely.
1 day later
#
Hi,

I spent some time now trying to understand how functions for the
computation of contrasts

contr.foo(n, contrasts=TRUE)

passed to model.matrix are called. My problem is
that for the computation of some contrasts one needs `n' to be the number
of observations at each level of the factor of interest and for others the
number of levels is sufficient. For example, `contr.treatment' has code
for handling vector valued `n' (and ?contrasts states that `n' may be a vector).

Where can I find the condition under which `n = nlevel(x)' or `n =
table(x)' or how can I define what I would like to see?

Best,

Torsten
#
On Wed, 7 May 2003, Torsten Hothorn wrote:

            
line 1626 (in R-devel and probably also 1.7.0).
#
Thank you! Therefore one cannot compute contrasts that depend on
the number of observations at each level, right? Looking at the code in
`contr.treatment' that handles this case: may I conclude that this is on
the wishlist?

Torsten
#
On Thu, 8 May 2003, Torsten Hothorn wrote:

            
BTW, I don't think contr.treatment does this.  It is documented to take 
either the set of levels or the number of levels, not a table of counts: 
it is coincidental that it works with the latter since it only looks at 
the length.
But you can, just not from inside model.matrix.  Contrast functions have
other uses, including computing contrast matrices to pass to model-fitting
functions via a `contrasts.arg' or 'contrasts' argument.

I don't think altering model.matrix is on anyone's wishlist (look at the C
code if you need dissuading), and it could only assume a minimal spec for
the contrast functions supplied: there are several user-written ones out
there.  E.g. contr.sdif (MASS) will not give sensible labels when supplied
a table of counts.
#
Torsten Hothorn <Torsten.Hothorn@rzmail.uni-erlangen.de> writes:
That's not what it does. It just allows you to give the vector of
levels instead of the count. At the moment, this seems to be used only
for labeling:
3 2 1
4 0 0 0
3 1 0 0
2 0 1 0
1 0 0 1

Notice that C() allows a matrix argument, so even if model.matrix
doesn't use this feature, you could still use y~C(g,contr.xxx(levs))
in modeling.

One place where something like this might be useful, but (one of my
ancient gripes) isn't, is for generating polynomial contrasts over a
non-equidistant level set.
#
On 8 May 2003, Peter Dalgaard BSA wrote:

            
How could one detect that?  A level set is just a set of labels, in order
for an ordered factor.  One needs more information as to how (or whether)
to interpret it as `non-equidistant'.  Given such information (e.g. in a
"score.levels" attribute) we could do this fairly easily: but one can also
set the contrast matrix via a contrasts arg, via contrasts<-() or (more
clumsily I think given the way the model is printed) via C().