#install.packages(c("MASS"))
#install.packages(c("multcomp"))
library(multcomp)
library(MASS)
library(nlme)
library(foreign)
library(car)
library(stats)
sem <- read.spss("e:\\POST-HOC FOR ZIPPING\\DEMO POST-HOC\\WITHIN2.sav")
attach(sem)
type2 <- recode(type, "1='A'; 2='B'; 3='C';4='D'")
sem <- data.frame(y,id,type2)
Lme.mod <- lme(y ~ type2, random = ~1 | id/type2, data = sem) 
anova(Lme.mod)
summary(glht(Lme.mod, linfct=mcp(type2="Tukey")))

# OUTPUTTED TUKEY STANDARD ERROR = SQRT[2X(MSE/{N PER GROUP)}] = sqrt[2x (1.05/10)] =0.46

> summary(glht(Lme.mod, linfct=mcp(type2="Tukey")))

         Simultaneous Tests for General Linear Hypotheses

Multiple Comparisons of Means: Tukey Contrasts


Fit: lme.formula(fixed = y ~ type2, data = sem, random = ~1 | id/type2)

Linear Hypotheses:
           Estimate Std. Error z value Pr(>|z|)    
B - A == 0  -0.7000     0.4603  -1.521  0.42490    
C - A == 0  -1.7000     0.4603  -3.693  0.00126 ** 
D - A == 0  -2.6000     0.4603  -5.649  < 0.001 ***
C - B == 0  -1.0000     0.4603  -2.173  0.13090    
D - B == 0  -1.9000     0.4603  -4.128  < 0.001 ***
D - C == 0  -0.9000     0.4603  -1.955  0.20496    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)
