[R] puzzle about contrasts

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Tue Sep 9 18:49:52 CEST 2008


Peter Dalgaard skrev:
> Prof Brian Ripley skrev:
>   
>> -0.5*(A+B) is not a contrast, which is the seat of your puzzlement.
>>
>> All you can get from y ~ x is an intercept (a column of ones) and a
>> single 'contrast' column for 'x'.
>>
>> If you use y ~ 0+x you can get two columns for 'x', but R does not
>> give you an option of what columns in the case: see the source of
>> contrasts(). So you would need to replace contrasts(), which I think
>> will be hard as model.matrix.default will look in the 'stats'
>> namespace.  It would probably be easier to create the model matrix
>> yourself.
>>
>>     
> Or accept the default and do the parameter transformations yourself.
>
> l <- lm(y~x)
> T <- rbind(
> c(-1,-.5),
> c(0,1))
>
> c2 <- T%*%coef(l)
> V2 <- T%*%vcov(l) %*% t(T)
>
> cbind(coef=c(c2), s.e.=sqrt(diag(V2)))
>   

I forgot: Also have a look at estimable() from the gmodels packages.

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list