0

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

1
  • Welcome to SO. You maximise your chance of getting a useful answer if you provide a minimal reproducible example. This post may help. Here, we would need to see (some of) your data and in indication of the packages you are using. Commented Jan 14, 2024 at 8:17

1 Answer 1

0

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 NAs in your dataset that you should deal with first before fitting your model with the glm() function.

Under the hood, the glm() function runs na.omit() on the data before fitting the model which removes all rows with at least one missing value in any column. From the glm() arguments help page:

na.action: a function which indicates what should happen when the data contain NAs. The default is set by the na.action setting of options, and is na.fail if that is unset. The ‘factory-fresh’ default is na.omit. Another possible value is NULL, no action. Value na.exclude can be useful.

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 NAs and 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.