I want to get a test of linear trend from an ordered factor, but I don’t want all the extra polynomial trend tests that R spits out automatically (e.g. quadratic, cubic etc)
Here’s some toy data
d <- data.frame(f_ord = factor(x = rep(letters[1:5],each=5),
ordered = TRUE),
f_nonOrd = factor(x = rep(letters[1:5],each=5),
ordered = FALSE)
score = as.vector(sapply(seq(0,20,5), function(i) rnorm(n=5,i,2))))
When we do a simple regression on this data with the ordered factor as the predictor
summary(lm(score ~ f, data = d))
# Coefficients:
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 9.8472 0.4723 20.850 4.87e-15 ***
# f.L 16.0248 1.0561 15.174 1.95e-12 ***
# f.Q 1.5136 1.0561 1.433 0.1672
# f.C -0.5138 1.0561 -0.487 0.6319
# f^4 1.9568 1.0561 1.853 0.0787 .
The output gives us polynomial trend tests all the way up to quarternary.
Is there any way either to
(1) Remove the higher-order trend tests from the ordered factor
(2) Specify a single set of contrast coefficients to the non-ordered factor
Any help much appreciated.