SMHS MissingData
Contents
Scientific Methods for Health Sciences - Missing Data
Questions
Overview
Many research studies encounter incomplete (missing) data that require special handling (e.g., processing, statistical analysis, visualization). There are a variety of methods (e.g., multiple imputation) to deal with missing data, detect missingness, impute the data, analyze the completed data-set and compare the characteristics of the raw and imputed data.
Multiple imputation involves 3 steps.
1) Impute: Create sets of plausible values for the missing observations that reflect uncertainty about the non-response model. Each of these sets of plausible values can be used to “fill-in” or complete the data-set.
2) Analyze: process each of these imputed data-sets using complete-data methods.
3) Combine: synthesize the results accounting for the uncertainty within each imputation round.
In a general regression setting, let’s denote the scalar, or vector valued, outcomes by Y, and the corresponding vector of predictors by X. For a given case (e.g., subject, unit), these quantities are either observed (obs) or missing (mis). Thus, Yobs and Xobs represent the observed component of the outcome and the predictors; and Ymis and Xmis denote the unobserved components of the outcome and predictors, respectively. Imputation involves the estimation of the regression parameters β governing the conditional distribution of Y given X: f(Y|X,β). The efficiency, bias and precision of the estimates are important in this process.
The type of missingness in the data is an important factor in the imputation process. The basic patterns of missingness include:
• Missing completely at random (MCAR) assumes that the missing data is not related to any factor, known or unknown, in the study.
• Missingness at random (MAR) assumes that the missingness depends only on observed quantities, which may include outcomes and/or predictors.
• Non-ignorable missingness occurs when the missing data depends on unobserved quantities.
Multiple Imputation Protocol
(1) Imputation: Generate a set of m > 1 plausible values for Zmis= Y(mis,Xmis).
The imputation step relies upon assumptions regarding the cause of missingness in the dataset. The goal of the imputation is to account for the relationships between the unobserved and observed variables, while taking into account the uncertainty of the imputation. The commonly made MAR assumption for missing data is untestable without additional information. With MAR assumption we can generate imputations (Z{1},Z{2},...Z{m}) from the distribution f(Zmis |Zobs, since after conditioning on Zobs, the missingness is assumed to be random.
The missingness is monotone when the data matrix can be rearranged so that there is a hierarchy of missingness where observing a particular variable Zb for a subject implies that Za is observed, for a < b. In monotone condition settings many imputation methods may be employed including (for continuous variables) propensity methods, predictive mean matching, and (for discrete variables) discriminant analysis or logistic regression. For non-monotonic missingness, Markov Chain Monte Carlo (MCMC) approaches may be used.
Each method has its own assumptions. For instance, predictive mean matching and MCMC approaches require multivariate normality. Predictive mean matching approach employs linear regression for the distribution of a partially observed variable, conditional on other factors. To impute the data using the predictive mean matching approach for a variable Zi with missing values, we fit a model using complete observations for Z1, . . . , Z(i-1) (not monotonicity assumption!):
E[Zi |φ] = φ0 + φ1 Z1 + φ2 Z2 + · · · + φ(i-1) Z(i-1)
Next, new parameters φ* are randomly drawn from the distribution of the parameters (since these values are estimated instead of exactly known). For the 1≤l≤m imputation, the missing values are replaced by:
Zil = φ0* + φ1* Z1 + φ2* Z2 + · · · + φ(i-1)* Z(i-1)+σ* ϵ,
where σ* is the estimate of variance from the model and ϵ is a Gaussian, N(0,1). This is the simple regression method. We can impute the observed value of Zi that is closest to predicted Z i=Zil in the dataset – this is the predictive mean matching method.
The propensity score method uses an alternative model for imputation where the values are imputed from observations that are equally likely to be missing, by fitting a logistic regression model for the missingness indicators. In some situations, propensity score imputation may lead to serious bias for missing covariates. For discrete incomplete variables, discriminant analysis or dichotomous logistic regression may be employed to impute values based on the estimated probability that a missing observation takes on a certain value.
(2) Analysis: Analyze the m datasets using complete-case methods. This second step in the protocol involves carrying out the analysis of interest for each of the m imputed complete-observation datasets and storing the parameter vectors (e.g., effect-size coefficients, β’s) and their standard error estimates
(3) Combination: Combine the results from the m analyses and calculate the estimates of the within imputation and between imputation variability. If the imputation model is correct (assumptions are valid), these statistics account for the variability of the imputations and provide consistent estimates of the parameters and their standard errors.
Examples
Simulated example
set.seed(123) # create MCAR missing-data generator create.missing <- function (data, pct.mis = 10) { n <- nrow(data) J <- ncol(data) if (length(pct.mis) == 1) { n.mis <- rep((n * (pct.mis/100)), J)
} else { if (length(pct.mis) < J) stop("The length of missing does not equal to the column of the data") n.mis <- n * (pct.mis/100)
} for (i in 1:ncol(data)) { if (n.mis[i] == 0) { # if column has nothing missing, do nothing. data[, i] <- data[, i] } else { data[sample(1:n, n.mis[i], replace = FALSE), i] <- NA # For each given column (i), sample the row indices (1:n), # a number of indices to replace as “missing”, n.mis[i], “NA”, # without replacement } } return(as.data.frame(data)) }
# Simulate some real multivariate data sim_data={y,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10} # n <- 1000; u1 <- rbinom(n, 1, .5); v1 <- log(rnorm(n, 5, 1)); x1 <- u1*exp(v1) u2 <- rbinom(n, 1, .5); v2 <- log(rnorm(n, 5, 1)); x2 <- u2*exp(v2) x3 <- rbinom(n, 1, prob=0.45); x4 <- ordered(rep(seq(1, 5),n)[sample(1:n, n)]); x5 <- rep(letters[1:10],n)[sample(1:n, n)]; x6 <- trunc(runif(n, 1, 10)); x7 <- rnorm(n); x8 <- factor(rep(seq(1,10),n)[sample(1:n, n)]); x9 <- runif(n, 0.1, .99); x10 <- rpois(n, 4); y <- x1 + x2 + x7 + x9 + rnorm(n)
# package the simulated data as a data frame object sim_data <- cbind.data.frame(y, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)
# randomly create missing values sim_data_30pct_missing <- create.missing(sim_data, pct.mis=30); head(sim_data_30pct_missing); summary(sim_data_30pct_missing)
# install.packages("mi") # install.packages("betareg") library("betareg"); library("mi")
# get show the missing information matrix mdf <- missing_data.frame(sim_data_30pct_missing) show(mdf); mdf@patterns; image(mdf) # remember the visual pattern of this MCAR
# Next try to impute the missing values … imputations <- mi(sim_data_30pct_missing, n.iter=10, n.chains=3, verbose=TRUE) hist(imputations)
# Extracts several multiply imputed data.frames from “imputations” object data.frames <- complete(imputations, 3)
# Compare the summary stats for the original data (prior to introducing missing # values) with missing data and the re-completed data following imputation summary(sim_data); summary(sim_data_30pct_missing); summary(data.frames1); lapply(data.frames, summary)
!!!!INSERT TABLE
# Check imputation convergence (details provided below) round(mipply(imputations, mean, to.matrix = TRUE), 3) Rhats(imputations, statistic = "moments") # assess the convergence of MI algorithm
plot(imputations); hist(imputations); image(imputations); summary(imputations)
# Finally, pool over the m = 5 imputed datasets when we fit the “model” # Pool from across the 4 chains – in order to estimate a linear regression model model_results <- pool(y ~ x1+x2+x3+x4+x5+x6+x7+x8+x9+x10, data=imputations, m=5 ) display (model_results); summary (model_results) # Report the summaries of the imputations data.frames <- complete(imputations, 3) # extract the first 3 chains lapply(data.frames, summary)
TBI Data Example
See [ttp://wiki.socr.umich.edu/index.php/SMHS_MissingData#Raw_TBI_data these traumatic brain injury (TBI) data]:
Ind | ID | Age | Sex | TBI | field.gcs | er.gcs | icu.gcs | worst.gcs | X6m.gose | X2013.gose | skull.fx | temp.injury | surgery | spikes.hr | min.hr | max.hr | acute.sz | late.sz | ever.sz |
1 | 1 | 19 | M | Fall | 10 | 10 | 10 | 10 | 5 | 5 | 0 | 1 | 1 | NA | NA | NA | 1 | 1 | 1 |
2 | 2 | 55 | M | Blunt | NA | 3 | 3 | 3 | 5 | 7 | 1 | 1 | 1 | 168.74 | 14 | 757 | 0 | 1 | 1 |
3 | 3 | 24 | M | Fall | 12 | 12 | 8 | 8 | 7 | 7 | 1 | 0 | 0 | 37.37 | 0 | 351 | 0 | 0 | 0 |
4 | 4 | 57 | F | Fall | 4 | 4 | 6 | 4 | 3 | 3 | 1 | 1 | 1 | 4.35 | 0 | 59 | 0 | 0 | 0 |
5 | 5 | 54 | F | Peds_vs_Auto | 14 | 11 | 8 | 8 | 5 | 7 | 0 | 1 | 1 | 54.59 | 0 | 284 | 0 | 0 | 0 |
6 | 6 | 16 | F | MVA | 13 | 7 | 7 | 7 | 7 | 8 | 1 | 1 | 1 | 75.92 | 7 | 180 | 0 | 1 | 1 |
# Load the (raw) data from the table into a plain text file "08_EpiBioSData_Incomplete.csv" TBI_Data <- read.csv("https://umich.instructure.com/files/720782/download?download_frd=1", na.strings=c("",".","NA")) summary(TBI_Data)
# Get information matrix of the data # (1) Convert to a missing_data.frame # library("betareg"); library("mi") mdf <- missing_data.frame(TBI_Data) # warnings about missingness patterns show(mdf); mdf@patterns
# (2) change things: mi::change() method changes the family, imputation method, # size, type, and so forth of a missing variable. It’s called # before calling mi to affect how the conditional expectation of each # missing variable is modeled. mdf <- change(mdf, y = "spikes.hr", what = "transformation", to = "identity")
Arg | Description |
y | A character vector naming one or more missing variables within the missing_data.frame specified by the data argument, or a vector of integers or a logical vector indicating which missing_variables to change. |
what | A character string naming what is to be changed, such as "family", "imputation_method", "size","transformation", "type", "link", or "model." |
to | A character string naming what y should be changed to, such as one of the admissible families, imputation methods, transformations, or types. If missing, then possible choices for the "to" argument will be helpfully printed on the screen. |
# (3) examine missingness patterns summary(mdf); hist(mdf); image(mdf)
# (4) Perform initial imputation imputations <- mi(mdf, n.iter=30, n.chains=5, verbose=TRUE) hist(imputations)
# (5) Extracts several multiply imputed data.frames from “imputations” object data.frames <- complete(imputations, 5)
# (6) Report a list of “summaries” for each element (imputation instance) lapply(data.frames, summary)
# (6.a) To cast the imputed numbers as integers (not necessary, but may be useful) indx <- sapply(data.frames5, is.numeric) # get the indices of numeric columns data.frames5[indx] <- lapply(data.frames5[indx], function(x) as.numeric(as.integer(x))) # cast each value as integer
# (7) Save results out write.csv(data.frames5, "C:\\Users\\Dinov\\Desktop\\TBI_MIData.csv")
# (8) Complete Data analytics functions: # library("mi") #lm.mi(); glm.mi(); polr.mi(); bayesglm.mi(); bayespolr.mi(); lmer.mi(); glmer.mi()
# (8.1) Define Linear Regression for multiply imputed dataset – Also see Step (10) ##linear regression for each imputed data set - 5 regression models are fit fit_lm1 <- glm(ever.sz ~ surgery + worst.gcs + factor(sex) + age, data.frames$`chain:1`, family = "binomial"); summary(fit_lm1); display(fit_lm1)
# Fit the appropriate model and pool the results (estimates over MI chains) model_results <- pool(ever.sz ~ surgery + worst.gcs + factor(sex) + age, family = "binomial", data=imputations, m=5) display (model_results); summary (model_results)
# Report the summaries of the imputations data.frames <- complete(imputations, 3) # extract the first 3 chains lapply(data.frames, summary)
# (9) Validation: we now verify whether enough iterations were conducted. # Validation criteria demands that the mean of each completed variable should # be similar for each of the k chains (in this case k=5). # mipply is wrapper for sapply invoked on mi-class objects to compute the col means round(mipply(imputations, mean, to.matrix = TRUE), 3)
# Rhat convergence statistics compares the variance between chains to the variance # across chains. # Rhat Values ~ 1.0 indicate likely convergence, # Rhat Values > 1.1 indicate that the chains should be run longer # (use large number of iterations) Rhats(imputations, statistic = "moments") # assess the convergence of MI algorithm
# When convergence is unstable, we can continue the iterations for all chains, e.g. imputations <- mi(imputations, n.iter=20) # add additional 20 iterations
# To plot the produced mi results, for all missing_variables we can generate # a histogram of the observed, imputed, and completed data. # We can compare of the completed data to the fitted values implied by the model # for the completed data, by plotting binned residuals. # hist function works similarly as plot. # image function gives a sense of the missingness patterns in the data plot(imputations); hist(imputations); image(imputations); summary(imputations)
# (10) Finally, pool over the m = 5 imputed datasets when we fit the “model” # Pool from across the 4 chains – in order to estimate a linear regression model # and impact ov various predictors
model_results <- pool(ever.sz ~ surgery + worst.gcs + factor(sex) + age, data = imputations, m = 5 ); display (model_results); summary (model_results)
# Report the summaries of the imputations data.frames <- complete(imputations, 3) # extract the first 3 chains lapply(data.frames, summary) # report summaries
Parkinson's Disease Case Study
Background: See: http://wiki.socr.umich.edu/index.php/SOCR_Data_PD_BiomedBigMetadata
#imputation for logistic regression # load the data: 08_PPMI_GSA_clinical.csv ppmi_new<-read.csv("https://umich.instructure.com/files/330401/download?download_frd=1",header=TRUE)
# install.packages("psych") library(psych) # report descriptive statistics
ppmi_new$\$$ResearchGroup <- ifelse(ppmi_new$\$$ResearchGroup == "Control", "Control", "Patient") ppmi_new$\$$ResearchGroup <- as.factor(ppmi_new$\$$ResearchGroup): table(ppmi_new$\$$ResearchGroup)
# Reduce the Dataset: extract only the columns of interest (to ensure real time calculations) ppmi_new_1 <- as.data.frame(ppmi_new)[, c("ResearchGroup","R_fusiform_gyrus_Curvedness","Sex","Age","chr12_rs34637584_GT","UPDRS_Part_I_Summary_Score_Baseline","UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline","UPDRS_Part_III_Summary_Score_Baseline", "UPDRS_Part_IV_Summary_Score_Baseline")]
descript <- describe(ppmi_new_1); descript # reports means, SE’s, etc.
dim(ppmi_new); dim(ppmi_new_1) # check dimensions before
# imputation 1 # install.packages("mi"); install.packages("betareg") library(mi); library(betareg)
mdf<-missing_data.frame(ppmi_new_1[-1,]) apply(ppmi_new_1[-1,],1,mean) imputations<-mi(mdf, seed=900); summary(imputations) ppmi_complete<-complete(imputations)
# Save the imputation # again you may want to cast imputed numerical values as integers, perhaps # (indx <- sapply(data.frames5, is.numeric) # get the indices of numeric columns # data.frames5[indx] <- lapply(data.frames5[indx], function(x) as.numeric(as.integer(x))) # cast each value # write.csv(ppmi_complete,"C:\\Users\\Dinov\\Desktop\\ppmi_new_1_complete.csv") write.csv(ppmi_complete,"ppmi_new_1_complete.csv")
# Get the imputations of 4 iterations ppmi_complete_1<- ppmi_complete1; ppmi_complete_2<- ppmi_complete2; ppmi_complete_3<- ppmi_complete3; ppmi_complete_4<- ppmi_complete4
# average the imputations ppmi_updrs <- (ppmi_complete_1+ppmi_complete_2+ppmi_complete_4+ppmi_complete_3)/4 # ppmi_top<-cbind(ppmi_new_1[-1,1:335], ppmi_updrs) #delete the first observation # colnames(ppmi_top)<-colnames(ppmi_new[,1:393])
# Save results – complete dataset # write.csv(ppmi_top,"C:\\Users\\Dinov\\Desktop\\ppmi_top_complete_1.csv") # write.csv(ppmi_top,"ppmi_top_complete_1.csv")
# Now, run some Data analytics on complete data: # library("mi") #lm.mi(); glm.mi(); polr.mi(); bayesglm.mi(); bayespolr.mi(); lmer.mi(); glmer.mi() # Define Linear Regression for multiply imputed dataset ##linear regression for each imputed data set - 5 regression models are fit
model_results <- pool(ResearchGroup ~ R_fusiform_gyrus_Curvedness + factor(Sex) + Age + factor(chr12_rs34637584_GT) + UPDRS_Part_I_Summary_Score_Baseline + UPDRS_Part_II_Patient_Questionnaire_Summary_Score_Baseline + UPDRS_Part_III_Summary_Score_Baseline, family = "binomial", data=imputations, m=3) display (model_results); summary (model_results)
Appendix
See also
- The SOCR Simulated HELP data activity provides additional missing data management examples.
- Multiple Imputation FAQs.
- SOCR Home page: http://www.socr.umich.edu
Translate this page: