Ordered factors , was:[R] surrogate poisson models

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed May 5 14:30:08 CEST 1999


On Wed, 5 May 1999, BXC wrote:

> For ordered factor the natural contrast coding would be to parametrize by
> the succsessive differences between levels, which does not assume equal
> spacing
> of factor levels as does the polynomial contrasts (implicitly at least).

What is `natural' is a matter of opinion, of course, and does not
facilitate reducing the number of dfs given to the factor.  If the levels
are known not to be equally spaced, and it is know how they are spaced then
I suggest you have rather more than an ordinal varaible, which is what
ordered factors are designed for. In that case, use poly on a set of scores
for the levels.

> This requires the contr.cum, which could be:
> 
> contr.cum <- function (n, contrasts = TRUE) 
> {
>     if (is.numeric(n) && length(n) == 1) 
>         levs <- 1:n
>     else {
>         levs <- n
>         n <- length(n)
>     }
>     contr <- array(0, c(n, n), list(levs, levs))
>     contr[col(contr) <= row(contr)] <- 1
>     if (contrasts) {
>         if (n < 2) 
>             stop(paste("Contrasts not defined for", n - 1, "degrees of
> freedom"))
>         contr <- contr[, -1, drop = FALSE]
>     }
>     contr
> }
> 
> Why is this not part of the standard R distribution ?

Well, there are lots of things we could add, but this one is 
precisely (as far as I can see) contr.sdif in the MASS library.


-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list