1
$\begingroup$

I have data on the effect sizes for 14 variables (var1-var14). Each value is the effect size of a specific treatment on a certain variable. Missing values are due to that some articles did not consider certain variables. A positive value show promoting while a negative value shows the inhibiting effect of that treatment on the variable. I want (1) to do a pairwise linear regression that runs through each and every variable and compare if there is an association between variables, (2) consider var1 as the dependent variable and var2-var14 all as independent variables to find the best-fit model and show changes in which variables are most important for change in var1.

Here is what I have done so far using sample data (d):

d <- 
paste0('Var_', 1:14) |>
Map(f = \(.) sample(c(-20:14, NA),
                  size = 64,
                  prob = c(rep(.49/35, 35), .51),
                  replace = TRUE
)
) |>
as.data.frame()

#you get the pairwise associations in terms of the correlation matrix like so:

d |> cor(use = 'pairwise.complete.obs')

# and a basic column-wise imputation (replacing NA with the mean value) this way:

d_imputed <- d |>
apply(2, \(var) replace(var, is.na(var), mean(var, na.rm = TRUE)))

#Finally you can obtain the regression coefficients of the predictors (columns) for each column like so:

lm_coff <- d_imputed |> 
apply(2, FUN = \(var) coef(lm(var ~ ., as.data.frame(d_imputed))))

My question are

(1) Is it statistically correct to replace the NA with the mean values? (2) Although I have got the regression coefficients of the predictors, how can I get the p-value? (3) I am not very much satisfied with this approach, can this be improved or suggested another approach?

Thanks

$\endgroup$
1
  • $\begingroup$ Please include the library you've loaded in your code. The pipe-operator doesn't work for me. $\endgroup$ Commented Jul 5, 2023 at 10:06

1 Answer 1

1
$\begingroup$

Hia! Welcome to the wonderful and mysterious world of missing variables. Biased if you impute, biased if you dont ;)

Before considering any imputations, I recommend exploring, examining and analysing your missing data, as this is needed to inform your decision making. The {naniar} package has some amazing tools for exploring missing data, so I strongly recommend you play around with its functions (https://cran.r-project.org/web/packages/naniar/vignettes/getting-started-w-naniar.html).

Use the naniar functions, along with knowledge of your data set to determine if your missing variables are either:

a) missing completely at random (MCAR) - generally speaking, these are incredibly rare, but occur when there is no pattern to your missing data. Any type of imputation can be used to deal with MCAR, but some methods are better than others.

b) missing at random (MAR) - somewhat misnamed - as the missingness of data will be associated with the values of observed data. For MAR, I believe your best bet is using chained imputation methods (such as MICE).

c) Missing not at random (NMAR) - there is a relationship between the propensity of a value to be missing and its values. For example: Within a drug trial, the participants more affected by negative side effects are more likely to drop out of the study. However, I think an MNAR can also occur if a NULL value is mislabelled as an NA. MNAR variables can be very tricky to deal with, so I recommend reading up on them.

Generally speaking, it is a bad idea to use mean imputation to deal with NA's, as it will bias your results.

For more information I recommend checking out: https://bookdown.org/mike/data_analysis/imputation-missing-data.html

After you have sorted out all the joys of missing data, you can move on to the regression. I'd recommend creating a new dataset with your imputed variables, and then running a the easy way of getting regression coefficients and p-values:

summary(lm(outcome ~ predictor_1 + predictor_2, imputed_dataset))

Hope that all helps, and good luck with the pesky missing variables.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.