'singular contrast matrix error in ANOVA contrasts

The short version is this: I am trying to run a series of planned contrasts on a one-way ANOVA with a long list of factors (18) using the contrasts() function. Up to four contrasts seems to work fine, but when the fifth is added we suddenly get a 'singular contrast matrix'

treat<-as.factor(c("T09", "T15", "T19", "T20", "T07", "T04", "T22", "T21", "T23", "T08", "T01", "T16", "T03", "T02", "T06", "T10", "T17", "T03", "T16", "T23", "T08", "T20", "T04", "T01", "T19", "T22", "T06", "T09", "T07", "T15", "T02", "T17", "T14", "T21", "T10", "T01","T09", "T16", "T08", "T19", "T07", "T10", "T20", "T22", "T03", "T14", "T23", "T15", "T04", "T21", "T02", "T17", "T06"))


mat<-cbind(c(2, -1, -1, -1,  2,  2, -1, -1, -1,  2 , -1, -1, -1,  2,  2, -1, -1, -1),
           c(0,  1,  1,  1,  0,  0, -1, -1, -1,  0,  1,  1,  1,  0,  0, -1, -1, -1),
           c(0,  1,  -1,  0,  0,  0, 1, -1, 0,  0,  1,  -1,  0,  0,  0, 1, -1, 0),
           c(0,  1,  0, -1,  0,  0,  1,  0, -1,  0,  1,  0, -1,  0,  0,  1,  0, -1),
           c(0,  0,  1, -1,  0,  0,  0,  1, -1,  0,  0,  1, -1,  0,  0,  0,  1, -1))

contrasts(treat) <- cr.mat[, c(1:5)]

If I remove a contrasts, any of the five, it works fine, so it is not an issue with a particular one.

From past posts here I have learned that certain combinations of factors/contrasts are going to create singular matrices, but from a practical standpoint, there must be some kind of work-around for this type of problem? I've even tried adding some additional contrasts just to see if I could 'even it out' but I get the same problem.

Any and all suggestions welcome.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source