set.seed(100) social.eff <- sample(ads.social,4) ads.social <- 0:100/100 ads.normal <- 0:100/100 ads.animated <- 150:250/250 set.seed(100) social.eff <- sample(ads.social,4) normal.eff <- sample(ads.normal,4) animated.eff <- sample(ads.animated,4) ##100 of each ad type clicks <- c(runif(50*4) contrasts(type) #[,1] [,2] #A 1 0 #B 0 1 #C -1 -1 ##contrasts are set up so that contrasts <- rbind( "Grand mean/intercept"=c(1,0,0), "A alone"= c(1,1,0), "B alone"= c(1,0,1), "C alone"= c(1,-1,-1), "A to B" = c(0,1,-1), "A to C" = c(0,2,1), "B to C" = c(0,1,2)) summary(glht(am2,contrasts)) summary(glht(am2,linfct=mcp(type="Tukey"))) contrasts contrasts[5:7,] summary(glht(am2,contrasts[5:7,])) summary(glht(am2,linfct=mcp(type="Tukey"))) tukey <- glht(am2, linfct=mcp(type="Tukey")) print(tukey) summary(tukey) ##compare to: summary(glht(lmer2,contrast[5:7,])) ##compare to: summary(glht(am2,contrast[5:7,])) ##compare to: summary(glht(am2,contrasts[5:7,])) ##compare to: summary(glht(am2,contrasts[5:7,])) ##compare to: summary(glht(am2,contrasts[5:7,])) ##compare to: summary(glht(am2,contrasts[5:7,])) ##compare to: summary(glht(am2,contrasts[5:7,])) ##compare to: summary(glht(am2,contrasts[5:7,])) contrasts <- rbind( "Grand mean/intercept"=c(1,0,0), "A alone"= c(1,1,0), "B alone"= c(1,0,1), "C alone"= c(1,-1,-1), "A to B" = c(0,1,-1), "A to C" = c(0,2,1), "B to C" = c(0,1,2)) contrasts glht(am2,contrasts) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) summary(glht(am2,contrasts)) am4 <- lme(clicks~type,random=list((~1|ad),(~1|sub)),data=ads) ##both lmer4 <- lmer(clicks~type + (1|ad) + (1|sub),data=ads) contrasts <- rbind( "A to B" = c(0,1,-1), "A to C" = c(0,2,1), "B to C" = c(0,1,2)) summary(glht(lmer2,contrasts)) am4 <- lme(clicks~type,random=list((~1|ad),(~1|sub)),data=ads) ##both lmer4 <- lmer(clicks~type + (1|ad) + (1|sub),data=ads) summary(am4) summary(lmer4) summary(glht(lmer4,contrasts)) summary(glht(am5,contrasts)) ?mcp mcp summary(glht(lmer4,contrasts)) summary(glht(lmer4, linfct=mcp(type="Tukey"))) cw <- ChickWeight cw$logwt <- log(ChickWeight$weight) contrasts(cw$Diet) <- contr.poly(levels(cw$Diet)) cw lmer.cw0 <- lmer(logwt~Time*Diet + (1|Chick), data=cw ) summary(lmer.cw0) Anova(lmer.cw0) library(car) Anova(lmer.cw0) lmer.cw1 <- lmer(logwt~Time+Diet + (1|Chick),data=cw) summary(lmer.cw1) anova(lmer.cw0,lmer.cw1) coef(lmer.cw0) lmer.cw0 summary(lmer.cw0) cor(coef(lmer.cw0)) coef(lmer.cw0) coef(lmer.cw0)$Chick cor(coef(lmer.cw0)$Chick) cor(coef(lmer.cw0)$Chick,use="pairwise.complete") lmer.cw2 <- lmer(logwt~Time*Diet + (1+Time|Chick),data=cw) lmer.cw2b <- lmer(logwt~Time*Diet + (Time|Chick)+ (1|Chick) ,data=cw) summary(glht(lmer.cw2, linfct=mcp(Diet="Tukey"))) summary(glht(lmer.cw2b, linfct=mcp(Diet="Tukey"))) summary(lmer.cw2) Anova(lmer.cw2) summary(lmer.cw2) pr.cw <- profile(lmer.cw2) confint(pr.cw) pr.wc pr.cw pr.cw <- profile(lmer.cw2) confint(pr.cw) ads$clicks1 <- ads$clicks+0 library(ez) ezm <- ezMixed(data=ads,dv=.(clicks1), random=.(sub,ad), fixed=.(type)) print(ezm) mz <- (ezm$models$type$unrestricted) summary(mz) summary(glht(mz, linfct=mcp(type="Tukey"))) ezMixed ?ezMixed