Bob Green
2006-Jun-18 10:16 UTC
[R] how to successfully remove missing values for a repeated measures analysis
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
Spencer Graves
2006-Jun-20 03:04 UTC
[R] how to successfully remove missing values for a repeated measures analysis
I don't see enough information for me to diagnose the problem. If it were my problem, I'd print out some assessment of the results of every step you've described below. This should expose the step in which things disappear. Hope this helps. Spencer Graves p.s. I almost never attach a data.frame. It can be done, but I just find the mechanisms too subtle for my brain. I use "with" routinely, but I know I can't include an assignment inside "with", because "with" creates a frame and then discards it after it's done. Anything I created inside "with" gets thereby discarded. p.p.s. If you'd like more help from this listserve, PLEASE do read the posting guide! "www.R-project.org/posting-guide.html". People who follow that posting guide seem more likely to solve their own problems in the process of preparing a question for the listserve. If that fails, they are more likely to get a useful reply quickly. Clean, crisp questions sometimes generate a feeding frenzy of replies. Questions that are harder to understand often get ignored. Bob Green wrote:> 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 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html