I was trying to run a binary logistic regression with interaction effect between two variables with binary category.
My R code is below:
md1 <- glm(Diabetes_Cate_3 ~ Age_Years+factor(Gender)+
Education_Year+factor(Marital_Status)+
factor(Currently_Working)+factor(Smoked)+
MUAC+BMI+factor(Wealth_Index)+
Area*Year, family=binomial(link="logit"),
data=Diabetes1)
Here:
Dibetes_Cate_3 = "Diabetic" and "Nondiabetic"
Area = "Rural" and "Urban"
Year = "2011" and "2017"
I was trying to see the interaction of the risk of diabetes between Area and yeear adjusting all other factors.
While running interactionR function from the interactionR packages I was getting the follwoning error.
table_object = interactionR(md1, exposure_names = c("Area", "Year" ),
ci.type = "mover",
ci.level = 0.95, em=FALSE, recode = T)
Error in `[[<-.data.frame`(`*tmp*`, beta1, value = logical(0)) :
replacement has 0 rows, data has 8144
I will be grateful if anyone help fix this problem.
Thanks and Regards
Author of the package here. The error you are getting is usually a result of your model fitting step and not the interaction estimation step. The error indicates you have
NAsin your dataset that you should deal with first before fitting your model with theglm()function.Under the hood, the
glm()function runsna.omit()on the data before fitting the model which removes all rows with at least one missing value in any column. From theglm()arguments help page:This is better explained here with suggested fixes in a related question: Error in dataframe *tmp* replacement has x data has y. It involves removing unrequired columns for the model with many
NAsand ensuring factor levels are also not empty. Once you sort out the missing values issues you can then proceed with generating your interaction estimates using the package.