I’ve been running an lmer on a data set has missing values. I’ve managed to impute the missing values and run my model and successfully and get a summary of the pooled fit. However, I need the ANOVA table for reporting and the estimated means for plotting. The code I’ve been using is below, which I’ve cobbled together from various sources as a total newbie. Please let me know if you see problems in it.
# remove unneeded columns before imputation
columns_to_remove = c(1,3,15:19,21:30)
dataset_with_missing_values <- dataset_with_missing_values[, -columns_to_remove]
md.pattern(dataset_with_missing_values) # show pattern of missing data
dat <- dataset_with_missing_values
original <- dat
impmethod <- character(ncol(dat))
init <- mice(dat, maxit = 0)
meth <- init$method
predM <- init$predictorMatrix
predM["Subject", ] <- 0
impmethod["dependent_variable"] <- "2l.lmer"
set.seed(103)
imputed <- mice(dataset_with_missing_values, method = meth, predictorMatrix = predM, m = 10)
complete_imputed <- complete(imputed)
sapply(original, function(x) sum(is.na(x))) # check to see missing values have been imputed
sapply(complete_imputed, function(x) sum(is.na(x)))
mean(original$dependent_variable, na.rm = TRUE) # compare means re
mean(complete_imputed$dependent_variable, na.rm = TRUE)
fit <- with(data = imputed,
exp = lme4::lmer(dependent_variable ~ Factor_1 * Factor_2 * Sex * Time + (1 | Subject)))
pooled_fit <- pool(fit)
plot_summs(pooled_fit) # get summary of fit
summary <- summary(pooled_fit)`
I have tried anova(pooled_fit) but get the error:
no applicable method for ‘anova’ applied to an object of class “c(‘mipo’, ‘data.frame’)”
aov(pooled_fit) gives:
rror in x$terms %||% attr(x, “terms”) %||% stop(“no terms component nor attribute”) :
no terms component nor attribute
Apato Sagashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.