[R] How to specified contrasts in anova (lm)

Davide Risso davide.risso at berkeley.edu
Thu Jul 2 05:05:33 CEST 2015


Update:

I was able to fit the desired model by manually specifying the proper
contrast for the second factor, i.e. (going on with my example).

mat <- matrix(c(1, -1, 0, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 1, -1), ncol=3)
fit <- lm(y~a+b, contrasts = list(a=contr.sum, b=mat))

I guess that the proper way would be to write a function analogous to
contr.sum() to specify the contrast matrix.

Best,
davide

On Wed, Jul 1, 2015 at 2:43 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
> You do not set constraints in R you set contrasts. See the relevant
> sections of e.g. Venables and Ripley's MASS book.
>
> ?contrasts  ## what else!
> ?C
>
> for details.
>
> Beyond this, I cannot help.
>
> -- 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 2:14 PM, Davide Risso <davide.risso at berkeley.edu> wrote:
>> Hi Bert,
>>
>> I apologize for the HTML. I will pay more attention in the future.
>>
>> I know that the lm() command of my toy example fits the wrong model
>> with a singular design, maybe I shouldn't have included it.
>>
>> I believe that the model with the additional constraint(s) is not
>> garbage. But I don't know how to specify the additional constraints in
>> lm() (hence, I believe it's an R question).
>>
>> I also know that I can fit a mixed effect model, but this was not the
>> point of my previous email.
>>
>> Best,
>> 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.risso at berkeley.edu



More information about the R-help mailing list