Note that the toy example you provided is garbage. It has nothing to do with contrasts (i.e. constraints) -- the DESIGN is singular: The (2) - (1) difference for factor A is exactly the same as the (3,4,5) average - (1,2)average for B. I suspect you need to use a mixed effects model treating batch as random, not fixed, but that is just a guess as I do not know in detail what you have done.
So unless you have misstated or I have misunderstood, this indicates that your statistical understanding is wanting and you should consult a local statistical expert (of which there must be many) instead of proceeding on your own. This is **NOT** about R and is off topic here. Also, if you do wish to post here on R questions in future, please follow the posting guide and post in plain text, not HTML. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Wed, Jul 1, 2015 at 12:30 PM, Davide Risso <davide.ri...@berkeley.edu> wrote: > Dear list, > > I have the following anova that I want to fit in R: > > y_{ijk} = \mu + \alpha_i + \beta_{j(i)} + \epsilon_{ijk} > > This is an application in biology, in which we are measuring a certain > (continuous) characteristic of a group of cells. > Hence y_{ijk} corresponds to the measurement on cell k of type i in batch j. > > Batch is nested in type, meaning that we have multiple batches for each > cell type and each batch contains only cells of a given type. To complicate > things, the design is unbalanced. > > I can "manually" fit the model, with the following constraints: > \sum_{i=1}^m \alpha_i = 0 > and > \sum_{j=1}^{n_i} \beta_{j(i)} = 0. > > This gives me m + 1 constraints, where m is the number of types. > > A minimal (toy) example in R is: > > a <- as.factor(c(rep(1, 4), rep(2, 6))) > b <- as.factor(rep(1:5, each=2)) > y <- rnorm(10) > > fit <- lm(y ~ a + b) > > This call to lm will fit the wrong model, using two constraints (with the > "contr.sum" specification), \sum_{i=1}^m \alpha_i = 0 and \sum_{j=1}^{n} > \beta_{j} = 0, and resulting in a singular design matrix. > Is there a way to specify the right constraints in lm? > > Thanks in advance for any help, > davide > > -- > Davide Risso, PhD > Post Doctoral Scholar > Division of Biostatistics > School of Public Health > University of California, Berkeley > 344 Li Ka Shing Center, #3370 > Berkeley, CA 94720-3370 > E-mail: davide.ri...@berkeley.edu > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.