Mediation analysis with a tobit regression is failing to find the outcome variable

I am trying to run a mediation analysis with the mediation package in R. My outcome variable needs to be modeled with a tobit model (censored data).

When I try to run it, it claims that the outcome variable cannot be found, although it is in the dataframe. See reproducable example:

library(mediation)
test <- data.frame(mediator = c(0.333,0.201,0.343,0.133,0.240),
                   DV = c(0.152,2.318,0.899,0.327,1.117),
                   outcome=c(1.715,1.716,0.544,3.284,3.599))
mediator_model <- lm(mediator ~ DV, data = test)
outcome_model <- vglm(outcome ~ mediator + DV,
                      tobit(Upper = 4, Lower = -4), link = "identity",data = test)

med <- mediate(mediator_model, outcome_model, treat = "DV", mediator = "mediator")

When I run this, I get the error Error in eval(predvars, data, env) : object 'outcome' not found, even though the outcome model runs without a problem.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation