jmpsteen / medflex

Flexible mediation analysis using natural effect models in R
20 stars 6 forks source link

neEffdecomp - error n varterms[sapply(cov, grep, varterms)] : invalid subscript type 'list' #24

Open juliabenner opened 2 years ago

juliabenner commented 2 years ago

Hi, when I want to use the neEffdecomp function to extract the natural direct, indirect and total causal effect estimates from my natural effect model, this error appears. Is it because my natural effect model (neMod) is stored as a list?

thank you for your help!

tarensanders commented 2 years ago

This happens when you have covariates that are substrings of each other. Reprex:

library("medflex")
data("UPBdata")

UPBdata$gender_educ <- UPBdata$educ
# Note that 'educ' is now a substring of 'gender_educ

expData <- neImpute(UPB ~ att * negaff + gender + gender_educ + age,
  family = binomial("logit"), data = UPBdata
)
neMod2 <- neModel(UPB ~ att0 * att1 + gender + gender_educ + age,
  family = binomial("logit"), expData = expData, se = "robust"
)

effdecomp <- neEffdecomp(neMod2)
#> Error in varterms[sapply(cov, grep, varterms)]: invalid subscript type 'list'

Created on 2022-09-01 by the reprex package (v2.0.1)

To resolve, just rename your variables until there are no substrings.