Closed heledi closed 6 years ago
This issue seems to be the same as in Issue #6, but this time for 'xFit' argument.
Minimal (not) working example (function content taken from the example section of neModel)
rm(list = ls())
data(UPBdata)
x <- function() {
expFit <- glm(att ~ gender + educ + age, data = UPBdata)
impData <- neImpute(UPB ~ att * negaff + gender + educ + age,
family = binomial, data = UPBdata)
impFit2r <- neModel(UPB ~ att0 * att1, family = binomial,
expData = impData, xFit = expFit, se = "robust")
}
x()
The issue can be solved in a similar manner as #6 by adding args$xFit <- quote(xFit)
to the function 'neModel' prior to the evaluation, e.g. after line 335 in https://github.com/jmpsteen/medflex/blob/master/R/neModel.R
For users: To mitigate the issue in the current CRAN version, one can name the object which is passed to the argument xFit by the same name 'xFit'.
Many thanks for noticing and for offering a solution! Should work now.
Can you please verify if you get rid of all errors?
Yes, I did. Thank you very much!
Hi, there seems to be a problem with the xFit=expFit argument in a simulation environment. Though the expFit model is defined in the simulation, the model object is not found when it is called in the neModel-function. The error message says: Error in eval(args$xFit) : object 'expFit' not found. All packages are installed (R-Version 3.4.4). The problem does not occur outside a simulation environment. Here is a simple example:
library(simcausal) library(medflex) set.seed(41188)
M <- DAG.empty() M <- M + node("c",
distr="rnorm", mean=0, sd=1)+ node("a", distr = "rbern", prob = plogis(0.1-c)) + node("m", distr="rnorm", mean=10-2a+c, sd=2)+ node("y", distr="rnorm", mean=15-3a+0.2*m+c, sd=3) Mset <- set.DAG(M)
ATE<--3.4 NDE<--3 NIE<--0.4 true_dec<-c(ATE, NDE, NIE)
mysimulation <- function(runs=2,N=10000,B=100){ param <- 3 #total effect, natural direct and natural indirect effect M1_est<- matrix(NA,nrow=param,ncol=runs) # Point estimates
for(r in 1:runs)try({
simdat <- simcausal::sim(DAG = Mset, n = N, verbose=F)
})
M1_ub <- apply(M1_est[,!apply(M1_est,2,is.na)[1], drop=FALSE],1,mean, na.rm=TRUE) BIAS <- cbind(abs(M1_ub-true_dec)) results <- list(M1_est, BIAS) } set.seed(4118) sim <- mysimulation() sim
Thank you for your help!