[R] LM/two way analysis/classic parametrisation
Rolf Turner
rolf.turner at xtra.co.nz
Mon Jun 6 02:07:05 CEST 2011
On 06/06/11 03:01, kfl wrote:
> Thank you for your reply.
>
> However, I don't undestand what your are telling me.
>
> I would be pleased if you could give me the synstax in the following
> examples:
>
> #Exampel page side 372
> trt<-gl(3,4,12,labels=c("T1","T2","T3"))
> blk<-gl(4,1,12,labels=c("B1","B2","B3","B4"))
> res<-c(13,7,9,3,6,6,3,1,11,5,15,5)
> p372<-data.frame(trt,blk,res)
> attach(p372)
>
> model<-lm(res~trt+blk)
> summary(model)
> anova(model)
> model.matrix(model)
>
> I want to have a print from the classic parametrisation
>
> What should be added in the model statement ?
Nothing. Did you ***read*** the help for contrasts() as you were
advised to do?
To spell it out:
trt<- gl(3,4,12,labels=c("T1","T2","T3"))
blk<- gl(4,1,12,labels=c("B1","B2","B3","B4"))
contrasts(trt)<- "contr.sum"
contrasts(blk)<- "contr.sum"
# Alternatively set the contrasts equal to "contr.sum" globally:
# options(contrasts=c("contr.sum","contr.poly"))
res<- c(13,7,9,3,6,6,3,1,11,5,15,5)
p372<- data.frame(trt,blk,res)
fit<- lm(res ~ trt + blk,data=p372) # DON'T use attach()! Use the data argument for lm().
summary(fit)
cheers,
Rolf Turner
More information about the R-help
mailing list