2

For my repeated measures analysis using lme function I could omit not-available (na) data with the command: na.action=na.omit.

anova_lme_loc<-lme(data=rm1, fixed=Nmin~location*date, random=~1|subject,
                   na.action=na.omit)

However, when I try to do the same using the ezANOVA function I got the following notification:

anova_ez_loc=ezANOVA(data=rm1, dv=Nmin, wid=subject, within=date, 
                     between=location, na.action=na.omit)

Error in ezANOVA(data = rm1, dv = Nmin, wid = subject, within = date, : unused argument(s) (na.action = na.omit)

how can I omit my na data in ezANOVA? - solved using:

rm1_na <- na.omit(rm1)

but now I get the following error:

anova_ez_loc=ezANOVA(data=rm1_na, dv=Nmin, wid=subject, within=date, between=location)

Warning: Converting "subject" to factor for ANOVA.

Warning: Data is unbalanced (unequal N per group). Make sure you specified a well-considered value for the type argument to ezANOVA().

Error in ezANOVA_main(data = data, dv = dv, wid = wid, within = within, : One or more cells is missing data. Try using ezDesign() to check your data.

4

2 回答 2

2

ezANOVA doesn't handle missing data, as the author outlines in this reponse to a similar question. You have two options:

  1. Remove the missing data manually. The function complete.cases may be of help here.
  2. Mike Lawrence alternatively suggests checking out ezMixed from the same package, which is more complicated but can handle missing data.

To remove the data manually, you would do something like this:

rm1.complete <- rm1[complete.cases(rm1),]

Then use rm1.complete in your analysis.

于 2012-12-21T02:12:19.500 回答
0

补充@Jonathan Christensen 的回答:

使用主体内因素时,complete.cases它不起作用,因为它按行考虑案例,而您需要删除包含不完整案例 ID 的所有行。

这是一个小脚本,它扩展complete.cases到一个名为的自定义函数complete.cases.within,它为您完成所有工作:

if(!require(tidyverse)) install.packages("tidyverse"); library(tidyverse) #useful package for clean code

#helper function that returns ALL indices of matches of x in table instead of just the first one
#we need this to get all rows containing the ID of incomplete cases.
matchAll = function(x, table, nomatch=NA_integer_, incomparables=NULL) {
  which(!is.na(match(table, x, nomatch, incomparables)))
}

complete.cases.within = function(data, dv, wid) {
  incomplete = data %>% select(dv) %>% complete.cases() %>% !. #boolean vector containing incomplete rows
  toRemove = data %>% select(wid) %>% filter(incomplete) %>% .[,1] %>% unique() #all IDs containing incomplete rows
  positions = matchAll(toRemove, data[,wid])
  return(if (length(positions)==0) data else data[-positions,]) #drop all rows matching toRemove IDs
}
于 2017-11-23T10:15:48.753 回答