| UP |
Firstly, we need to create a data.frame. On this dataframe we execute a mixed effect model. (see also multifactor anova)
Steps to follow:
| 1) |
Create the data-frame on the data (textfile ch23pr12 ; right click on the file and save on C:\Temp ). Look to the file in R by File/display file. |
| 2) | Create factors in the frame |
| 3) | Execute the ANOVA three-way but make sure the interpretation is
for mixed model;
Check the the graphically the predictions, residuals, QQ-plot, Cook distance plot...for every ANOVA and note your observations |
| 5) | If appropiate execute multiple comparison or test specific contrast questions. |
We create a data-frame by typing (or copy/paste) the red letters after > followed by <ENTER> The blue letters are the answer from the R-programme. We check the content by typing in the name of the data-frame. Remark systems like R originate in Unix in which they discriminate uppercase and undercase and replace the usual backslash "\" by two "\\".
>Ch24pr20<-read.table("c:\\temp\\Ch23pr12.txt");Ch24pr20
V1 V2 V3 V4 V5
1 1250
1 1 1 1
2 1175
1 1 1 2
3 1236
1 1 1 3
4 1239
1 1 1 4
(rest of dataset)
Or directly from the webserver:
Ch24pr20<-read.table("http://www.biw.kuleuven.be/VAKKEN/statisticsbyR/datasetsTXT/CH23PR12.txt")
We give names to the variables.
names(Ch24pr20)=c("Time","Gender","Sequence","Experience","Replic")
We attach the data.frame for direct access to the data.
attach(Ch24pr20)
Important is to transfrom the qualitative variables expressed by numbers into factors.
Gender<-factor(Gender);Sequence<-factor(Sequence);Experience<-factor(Experience)
Assume factor A (Gender) and C (Experience) as fixed and B
(Sequence) as a random factor.
The analysis can be done by a linear model. The interpretation is however specific. See Neter et al, 1996, pag 1007 for the formulas of the EMS.
ResLM=lm(minutes~gender*sequence*experience);anova(ResLM)
Analysis of Variance Table
Response: Time
Df Sum Sq
Mean Sq F value
Pr(>F)
Gender
1 540361
540361 629.7603 < 2.2e-16 ***
Sequence
2 49320
24660 28.7396
6.22e-09 ***
Experience
1 382402
382402 445.6679 < 2.2e-16 ***
Gender:Sequence
2
543
271 0.3161
0.7305
Gender:Experience
1
91
91 0.1064
0.7457
Sequence:Experience
2
911
456 0.5310
0.5914
Gender:Sequence:Experience 2
19
10 0.0111
0.9890
Residuals
48 41186
858
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
See Neter et al (1996) problem 24.20 page 1007
a,b & c) AC interactions ? B main effects? Compose the test and execute on a=5%
d) apply MLS procedure to estimate σβ2 with a confidence interval of 95%.
Remark (niet voor Proeftechniek & under CONSTRUCTION):
This analysis can also be done by specific functions for random and mixed models:
Firstly load the package nlme (standard but not in the base); and use lme. This function one has to specify
The nlme package prefers to work with GroupedData, which are composed by the data.frame and the formula
formGD=formula(Time~Gender:Experience|Sequence)
Ch24pr20GD=groupedData(formGD,Ch24pr20)
Ch24pr20GD$Gender<-factor(Ch24pr20GD$Gender);
Ch24pr20GD$Sequence<-factor(Ch24pr20GD$Sequence);
Ch24pr20GD$Experience<-factor(Ch24pr20GD$Experience)
ResLme=lme(Time~ Gender*Experience, random=~1|Sequence,data=Ch24pr20GD);summary(ResLme)
This is a mixed model procedure. In this case not a LS criterium is used
but the REML ( REstricted Maximum Likelihood) is used for fitting. This procedure is
also appropiate for unbalanced data.
plot(ResLme)
intervals(ResLme)
| UP |
28 April, 2003 by Guido Wyseure