# How to handle missing data in the univariate analysis

Can someone please advise me on how to handle missing data in a univariate analysis (e.g. t-test, chi-squared test)?

Given that multiple imputation techniques (MICE package) are for multivariate analysis, do I simply drop or ignore missing data when it comes to the aforementioned univariate analysis? If so, will the following codes/analyses take care of the missing data for me automatically?

t.test(data$Prescore, data$Postscore, paired = TRUE)
chisq.test(data$Prescore_cat,data$Postscore_cat, correct = TRUE)

• This isn't actually a univariate analysis. You can use the "pre" score to predict the "post" score, and vice versa. The data are already in a wide format. Are you saying you're missing both pre and post values in your analysis? Nov 30, 2021 at 19:50
• What do you mean by these are not univariate analyses? And, I only have missing pre-scoring (ie. some participants did not come back from post-tests) Nov 30, 2021 at 20:58

#### Simulating the Data

First things first, you do not need to drop data. That is the whole point behind imputation...it seeks to complete your data so you don't have to sacrifice precision or power.

I'm not sure if this fits the profile of a chi-squared test, as they usually require counts of categorical variables. Additionally, the base R t-test isn't easily coded into MICE functions. However, there is an easy workaround for the t-test case by using regression instead. Since you mention MICE, I will use R below to show what I mean. First you can load the requisite libraries, create the data, and pivot it into long format:

#### Load Libraries ####
library(mice)
library(tidyverse)

#### Create Data ####
pre <- c(45,50,NA,NA,40,55,60,65,45,60)
post <- c(30,20,10,NA,NA,NA,20,25,10,NA)
df <- data.frame(pre,post)
piv <- df %>%
pivot_longer(cols = everything(),
names_to = "Group",
values_to = "Score")
piv


Which should look like this:

# A tibble: 20 × 2
Group Score
<chr> <dbl>
1 pre      45
2 post     30
3 pre      50
4 post     20
5 pre      NA
6 post     10
7 pre      NA
8 post     NA
9 pre      40
10 post     NA
11 pre      55
12 post     NA
13 pre      60
14 post     20
15 pre      65
16 post     25
17 pre      45
18 post     10
19 pre      60
20 post     NA


#### Imputation

Then you impute the data, pool the estimates, and summarize them:

#### Impute ####
imp <- mice(piv)
fit <- with(imp,
lm(Score ~ Group))
p <- pool(fit)
summary(p)


Giving you this summary, which shows that the difference between the groups is significant (here the post test group is the reference criterion/intercept):

         term estimate std.error statistic       df     p.value
1 (Intercept)     26.7  5.831524  4.578563 5.255213 0.005265395
2    Grouppre     24.6  6.913272  3.558373 9.015110 0.006118499


In general, an imputation model should be as complex or more complex than the analysis model. I.e. just because you look at one variable in the analysis does not mean you would restrict yourself to that one variable when doing imputation.

Of course, if you know nothing else but that one variable, then you cannot use anything else for imputation. However, in that case (at least in most real-life scenarios) it's entirely possible (and depending on the circumstances even likely) that your analysis will be completely invalid and give very wrong answers.