doubly_robust {CausalModels} | R Documentation |
Doubly Robust Model
Description
`doubly_robust`
trains both an outcome model and a propensity model to generate predictions
for the outcome and probability of treatment respectively. By default, the model uses
standardization
and propensity_scores
to form a
doubly-robust model between standardization and IP weighting. Alternatively, any outcome and treatment
models can be provided instead, but must be compatible with the predict
generic function in R.
Since many propensity models may not predict probabilities without additional arguments into the
predict function, the predictions themselves can be given for both the outcome and propensity scores.
Usage
doubly_robust(
data,
out.mod = NULL,
p.mod = NULL,
f = NA,
family = gaussian(),
simple = pkg.env$simple,
scores = NA,
p.f = NA,
p.simple = pkg.env$simple,
p.family = binomial(),
p.scores = NA,
n.boot = 50,
...
)
Arguments
data |
a data frame containing the variables in the model.
This should be the same data used in |
out.mod |
(optional) a regression model that predicts the outcome. NOTE: the model given
must be compatible with the |
p.mod |
(optional) a propensity model that predicts the probability of treatment. NOTE: the model given
must be compatible with the |
f |
(optional) an object of class "formula" that overrides the default parameter |
family |
the family to be used in the general linear model.
By default, this is set to |
simple |
a boolean indicator to build default formula with interactions. If true, interactions will be excluded. If false, interactions will be included. By default, simple is set to false. |
scores |
(optional) use calculated outcome estimates. |
p.f |
(optional) an object of class "formula" that overrides the default formula for the denominator of the IP weighting function. |
p.simple |
a boolean indicator to build default formula with interactions for the propensity models. If true, interactions will be excluded. If false, interactions will be included. By default, simple is set to false. NOTE: if this is changed, the coefficient for treatment may not accurately represent the average causal effect. |
p.family |
the family to be used in the underlying propensity model.
By default, this is set to |
p.scores |
(optional) use calculated propensity scores. |
n.boot |
an integer value that indicates number of bootstrap iterations to calculate standard error. |
... |
additional arguments that may be passed to the underlying |
Value
doubly_robust
returns an object of class
"doubly_robust".
The functions print
, summary
, and predict
can be used to interact with
the underlying glm
model.
An object of class "doubly_robust"
is a list containing the following:
out.call |
the matched call of the outcome model. |
p.call |
the matched call of the propensity model. |
out.model |
the underlying outcome model. |
p.model |
the underlying propensity model. |
y_hat |
the estimated outcome values. |
p.scores |
the estimated propensity scores. |
ATE |
the estimated average treatment effect (risk difference). |
ATE.summary |
a data frame containing the ATE, SE, and 95% CI of the ATE. |
data |
the data frame used to train the model. |
Examples
library(causaldata)
data(nhefs)
nhefs.nmv <- nhefs[which(!is.na(nhefs$wt82)), ]
nhefs.nmv$qsmk <- as.factor(nhefs.nmv$qsmk)
confounders <- c(
"sex", "race", "age", "education", "smokeintensity",
"smokeyrs", "exercise", "active", "wt71"
)
init_params(wt82_71, qsmk,
covariates = confounders,
data = nhefs.nmv
)
# model using all defaults
model <- doubly_robust(data = nhefs.nmv)
summary(model)
# use alternative outcome model
out.mod <- propensity_matching(data = nhefs.nmv)
db.model <- doubly_robust(
out.mod = out.mod,
data = nhefs.nmv
)
db.model
# give calculated outcome predictions and give formula for propensity scores
db.model <- doubly_robust(
scores = predict(out.mod),
p.f = qsmk ~ sex + race + age,
data = nhefs.nmv
)
db.model