Ordered factors , was:[R] surrogate poisson models
BXC
BXC at NOVO.dk
Wed May 5 11:35:54 CEST 1999
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).
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 ?
Bendix Carstensen
\\\|///
\\ - - /
( @ @ )
+------------------o00o-(_)-o00o------------------+
| Bendix Carstensen tel: 44 43 87 38 |
| Statistiker SDC: 44 43 90 42 |
| Steno Diabetes Center fax: 44 43 82 32 |
| Niels Steensens Vej 2 e-mail: bxc at novo.dk |
| 2820 Gentofte |
| Ooooo |
+------------------ooooO----( )-----------------+
( ) ) /
\ ( (_/
\_)
> -----Original Message-----
> From: Thomas Lumley [mailto:thomas at biostat.washington.edu]
> Sent: 4. maj 1999 16:00
> To: Simon Bond
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] surrogate poisson models
>
>
> On Tue, 4 May 1999, Simon Bond wrote:
>
> >
> > Call:
> > glm(formula = terms(Fr ~ treatment * age + (treatment + age) *
> > repair, keep.order = T), family = poisson, data = overall)
> >
>
> >
> > Coefficients:
> > Estimate Std. Error z value Pr(>|z|)
> > (Intercept) 0.68441 0.28979 2.362 0.01819 *
> > treatment -0.28096 0.43716 -0.643 0.52043
> > age.L 0.55595 0.42669 1.303 0.19259
> > age.Q 0.03404 0.42817 0.079 0.93664
> > treatment.age.L -1.31805 0.66813 -1.973 0.04853 *
> > treatment.age.Q -0.37452 0.67332 -0.556 0.57805
> > repair.L 1.53962 0.54255 2.838 0.00454 **
> > repair.Q -0.49447 0.40128 -1.232 0.21787
> > treatment.repair.L -3.93138 0.96310 -4.082 4.46e-05 ***
> > treatment.repair.Q -0.58937 0.62739 -0.939 0.34753
> > age.L.repair.L -2.08339 0.67093 -3.105 0.00190 **
> > age.Q.repair.L -0.47257 0.59116 -0.799 0.42406
> > age.L.repair.Q -0.04208 0.42881 -0.098 0.92183
> > age.Q.repair.Q -0.64314 0.42800 -1.503 0.13293
> > - ---
>
> >
> > How do you interpret the suffixes .L and .Q in the
> summary? I tried
> > redefining overall$age_ordered(.... labels=c(...)), to no
> avail. When the
> > factors are unordered, the suffixes are the labels, but the
> fitted model is
> > different.
>
> For an ordered factor polynomial contrasts are used by
> default (this can
> be set with options(contrasts=)). Polynomial contrasts decompose the
> effect of a variable into orthogonal linear, quadratic,
> cubic,... terms.
> Based on the analysis above you might argue that all the
> quadratic terms
> are relatively small and not statistically significant and
> that the linear
> terms capture most of the variation.
>
> You can see what the contrast matrix looks like by typing eg
> R> contr.poly(3)
> .L .Q
> [1,] -7.071068e-01 0.4082483
> [2,] -7.850462e-17 -0.8164966
> [3,] 7.071068e-01 0.4082483
>
> to get the polynomial contrasts for a three-level ordered factor.
>
> For an unordered factor we use treatment contrasts by default
> (that is,
> indicator variables for all but one level of the factor).
> Any full rank
> set of contrasts gives the same model, but the coefficients
> are different,
> and allow you to answer different questions. The choice of contrasts
> depends on which questions you want to answer.
>
> Thomas Lumley
> Assistant Professor, Biostatistics
> University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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