[R] how to successfully remove missing values for a repeated measures analysis
Bob Green
bgreen at dyson.brisnet.org.au
Sun Jun 18 12:16:33 CEST 2006
Hello ,
I am hoping for some advice. I want to run a repeated measures ANOVA. The
primary problem is that my attempt to remove missing values created a
dataset of missing values.
The data set consists of 92 rows (1 row per participant) x 186 variables.
The steps of the analysis undertaken are outlined below (#). Any assistance
is appreciated in relation to how to remove the missing values so the
analysis is run. Feedback regarding the prior steps is also welcomed .
Bob Green
#Step 1
study1dat <- read.csv("c:\\study1.csv",header=T)
attach (study1dat)
outcome <- c(t1frq, t2frq,t3frq,t4frq)
grp <- factor( rep(group, 2,length=368) )
time <- gl(4,92,length=368)
subject <- gl(92,1,length=368)
data.frame(subject, grp, time, outcome)
# there are 3 missing values in $outcome
#Step 2 - create a new data frame removing missing values from variable
$outcome
d2<-study1dat[!is.na(outcome),]
#the previous step generates NA values.
#Step 3 detach original data set & attach dataset without missing values
detach(study1dat)
attach(d2)
The following object(s) are masked _by_ .GlobalEnv : time
The following object(s) are masked from package:datasets
: sleep
#Step 4 run analysis
library(nlme)
anova(lme(outcome ~ grp * time, random = ~ 1 | subject))
#The data is the format below
subject grp time outcome
1 1 0 1 4
2 2 0 1 3
3 3 0 1 7
4 4 0 1 0
5 5 0 1 1
6 6 0 1 7
7 7 0 1 7
8 8 0 1 7
9 9 0 1 7
10 10 0 1 5
More information about the R-help
mailing list