jmpsteen / medflex

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

Got error when using se = "bootstrap" #8

Closed dasiav7 closed 7 years ago

dasiav7 commented 7 years ago

It was okay when I used se = "robust", however, I got error message when I used se = "bootstrap".

impData <- neImpute(Histology ~ Cigarette + med1 * med2 * med3 * med4 + Age + Gender + Stage + Race, family = binomial("logit"), nMed = 4, data = data)

neMod5 <- neModel(Histology ~ Cigarette0 + Cigarette1 + Age + Gender + Stage + Race, family = binomial("logit"), expData = impData, se = "bootstrap")

lht <- neLht(neMod5, linfct = c("Cigarette0Yes = 0", "Cigarette1Yes = 0", "Cigarette0Yes + Cigarette1Yes = 0"))

The error message is argument is missing, with no default

What's the problem?

jmpsteen commented 7 years ago

This is most likely related to the fact that your original data frame is called 'data'. Please rename (e.g. into 'data2') and try to run updated code (replacing 'data' by 'data2'). I have had similar issues in the past, e.g. by running the code below:

data <- UPBdata

impData <- neImpute(UPB ~ attbin * negaff + gender + educ + age, 
                    family = binomial, data = data)

neMod <- neModel(UPB ~ attbin0 * attbin1 + gender + educ + age, family = binomial, expData = impData)

which illustrates that the error message is not related to the fact that your mediator is vector-valued (as might have been your first guess).

I'm going to see if there's a way to get rid of this bug. In the meantime, please use the suggested modification.

dasiav7 commented 7 years ago

Thank you! It works!

jmpsteen commented 7 years ago

This has now been solved by replacing the line

data <- eval(extrCall(x)$data)

in helper function extrData by

data <- extrCall(x)$data
data <- eval(data, envir = globalenv())