Title: | Methods for Causal Inference with Interference |
---|---|
Description: | Provides methods for estimating causal effects in the presence of interference described in B. Saul and M. Hugdens (2017) <doi:10.18637/jss.v082.i02>. Currently it implements the inverse-probability weighted (IPW) estimators proposed by E.J. Tchetgen Tchetgen and T.J. Vanderweele (2012) <doi:10.1177/0962280210386779>. |
Authors: | Bradley Saul |
Maintainer: | Bradley Saul <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.2 |
Built: | 2025-01-03 04:15:16 UTC |
Source: | https://github.com/bsaul/inferference |
Plot histograms of weights from an interference object
diagnose_weights(obj, allocations = NULL, ...)
diagnose_weights(obj, allocations = NULL, ...)
obj |
an |
allocations |
optional numeric vector of allocations for which to print histogram. If NULL (the default), five allocations selected evenly from the first allocation to the last are printed. |
... |
additional arguments passed to |
histogram of group-level weights
Retrieves the population average direct causal effect for a
specified allocation:
.
direct_effect(object, allocation = NULL, trt.lvl1 = 0)
direct_effect(object, allocation = NULL, trt.lvl1 = 0)
object |
an object of class |
allocation |
the allocation scheme for which to estimate direct effects. If NULL, then returns all direct effects. |
trt.lvl1 |
Defaults to 0. |
a data.frame with requested values
Extracts the names of the arguments from a function, and creates a list of those arguments where they exist in ... .
get_args(FUN, args_list = NULL, ...)
get_args(FUN, args_list = NULL, ...)
FUN |
function for which to find arguments |
args_list |
a list of arguments. Defaults to NULL. |
... |
any arguments. Those necessary for FUN must be named as appropriate for FUN |
list of arguments for FUN
myargs <- get_args(lm, formula = Sepal.Length ~ Sepal.Width, data = iris ) summary(do.call('lm', myargs))
myargs <- get_args(lm, formula = Sepal.Length ~ Sepal.Width, data = iris ) summary(do.call('lm', myargs))
Retrieves the population average indirect causal effect for
specified allocations:
.
This is the effect due to the coverage (allocation) levels.
indirect_effect(object, allocation1, allocation2 = NULL, trt.lvl = 0) ie(object, allocation1, allocation2 = NULL, trt.lvl = 0)
indirect_effect(object, allocation1, allocation2 = NULL, trt.lvl = 0) ie(object, allocation1, allocation2 = NULL, trt.lvl = 0)
object |
an object of class |
allocation1 |
the allocation scheme for which to estimate indirect effects |
allocation2 |
the allocation scheme for which to estimate indirect effects. If NULL, then returns all indirect effects compared to allocation1. |
trt.lvl |
Defaults to 0. |
a data.frame with requested values
Interference occurs when the treatment of one unit affects outcomes of other units. This package provides methods for estimating causal effects in the presence of interference. Currently it implements the IPW estimators proposed by Tchetgen Tchetgen and Vanderweele (2012) (doi:10.1177/0962280210386779) and developed further in Heydrich-Perez et al. (2014) (doi:10.1111/biom.12184).
Saul, B. and Hugdens, M. G. (2017). A Recipe for inferference: Start with Causal Inference. Add Interference. Mix Well with R. Journal of Statistical Software, 82(2), 1-21. doi:10.18637/jss.v082.i02
Estimate Causal Effects in presence of interference
interference( formula, propensity_integrand = "logit_integrand", loglihood_integrand = propensity_integrand, allocations, data, model_method = "glmer", model_options = list(family = stats::binomial(link = "logit")), causal_estimation_method = "ipw", causal_estimation_options = list(variance_estimation = "robust"), conf.level = 0.95, rescale.factor = 1, integrate_allocation = TRUE, runSilent = TRUE, ... )
interference( formula, propensity_integrand = "logit_integrand", loglihood_integrand = propensity_integrand, allocations, data, model_method = "glmer", model_options = list(family = stats::binomial(link = "logit")), causal_estimation_method = "ipw", causal_estimation_options = list(variance_estimation = "robust"), conf.level = 0.95, rescale.factor = 1, integrate_allocation = TRUE, runSilent = TRUE, ... )
formula |
The formula used to define the causal model. Has a minimum
of 4 parts, separated by |
propensity_integrand |
A function, which may be created by the user,
used to compute the IP weights. This defaults to
and |
loglihood_integrand |
A function, which may be created by the user, that
defines the log likelihood of the logit model used for |
allocations |
a vector of values in (0, 1). Increasing the number of elements of the allocation vector greatly increases computation time; however, a larger number of allocations will make plots look nicer. A minimum of two allocations is required. |
data |
the analysis data frame. This must include all the variables
defined in the |
model_method |
the method used to estimate or set the propensity model
parameters. Must be one of |
model_options |
a list of options passed to the function in
|
causal_estimation_method |
currently only supports |
causal_estimation_options |
A list. Current options are: (1) |
conf.level |
level for confidence intervals. Defaults to |
rescale.factor |
a scalar multiplication factor by which to rescale outcomes
and effects. Defaults to |
integrate_allocation |
Indicator of whether the integrand function uses the allocation parameter. Defaults to TRUE. |
runSilent |
if FALSE, status of computations are printed to console. Defaults to TRUE. |
... |
Used to pass additional arguments to internal functions such as
|
The following formula includes a random effect for the group: outcome |
exposure ~ propensity covariates + (1|group) | group
. In this instance, the
group variable appears twice. If the study design includes a "participation"
variable, this is easily added to the formula: outcome | exposure |
participation ~ propensity covariates | group
.
logit_integrand
has two options that can be passed via the ...
argument:
randomization
: a scalar. This is the in the formula just
above. It defaults to 1 in the case that a
participation
vector is not
included. The vaccine study example demonstrates use of this argument.
integrate_allocation
: TRUE/FALSE
. When group sizes grow
large (over 1000), the product term of logit_integrand
tends quickly to 0.
When set to TRUE
, the IP weights tend less quickly to 0.
Defaults to FALSE
.
If the true propensity model is known (e.g. in simulations) use
variance_estimatation = 'naive'
; otherwise, use the default
variance_estimatation = 'robust'
. Refer to the web appendix of
Heydrich-Perez et al. (2014) (doi:10.1111/biom.12184)
for complete details.
Returns a list of overall and group-level IPW point estimates, overall and group-level IPW point estimates (using the weight derivatives), derivatives of the loglihood, the computed weight matrix, the computed weight derivative array, and a summary.
Saul, B. and Hugdens, M. G. (2017). A Recipe for inferference: Start with Causal Inference. Add Interference. Mix Well with R. Journal of Statistical Software, 82(2), 1-21. doi:10.18637/jss.v082.i02
Perez-Heydrich, C., Hudgens, M. G., Halloran, M. E., Clemens, J. D., Ali, M., & Emch, M. E. (2014). Assessing effects of cholera vaccination in the presence of interference. Biometrics, 70(3), 731-741.
Tchetgen Tchetgen, E. J., & VanderWeele, T. J. (2012). On causal inference in the presence of interference. Statistical Methods in Medical Research, 21(1), 55-75.
Used by score_matrix
to compute the log likelihood.
log_likelihood(parameters, integrand, ...)
log_likelihood(parameters, integrand, ...)
parameters |
vector of parameters passed to |
integrand |
Defaults to logit_integrand |
... |
additional arguments passed to |
value of log likelihood
Computes the following function:
where is the randomization scheme.
is the covariate(s) vectors.
is the vector of fixed effects.
is the random (group-level) effect.
is the random effect variance.
logit_integrand(b, X, A, parameters, allocation = A, randomization = 1)
logit_integrand(b, X, A, parameters, allocation = A, randomization = 1)
b |
vector argument of values necessary for |
X |
n by length(fixed effects) matrix of covariates. |
A |
vector of binary treatments |
parameters |
vector of fixed effect (and random effect if applicable). Random effect should be last element in vector. |
allocation |
The allocation strategy. Defaults to A so that is essentially ignored if allocation is not set to a value within (0, 1). |
randomization |
Randomization probability. Defaults to 1. |
value of the integrand
Retrieves the population average overall causal effect:
overall_effect(object, allocation1, allocation2 = NULL) oe(object, allocation1, allocation2 = NULL)
overall_effect(object, allocation1, allocation2 = NULL) oe(object, allocation1, allocation2 = NULL)
object |
an object of class |
allocation1 |
the allocation scheme for which to estimate overall effects |
allocation2 |
the allocation scheme for which to estimate overall effects |
a data.frame with a single row with requested values
Prints a summary of an interference object
## S3 method for class 'interference' print(x, ...)
## S3 method for class 'interference' print(x, ...)
x |
object of class 'interference' |
... |
ignored |
Used by score_matrix
to log likelihood derivatives for
a single group.
score_calc(parameters, integrand, hide.errors = TRUE, ...)
score_calc(parameters, integrand, hide.errors = TRUE, ...)
parameters |
vector of parameters passed to |
integrand |
function to used for the integrand.
Defaults to |
hide.errors |
Hide errors printed from |
... |
additional arguments pass to the integrand function. |
length(theta) vector of scores
Calculate matrix of log Likelihood derivatives
score_matrix(integrand, X, A, G, parameters, runSilent = TRUE, ...)
score_matrix(integrand, X, A, G, parameters, runSilent = TRUE, ...)
integrand |
function passed to |
X |
covariate matrix |
A |
vector of treatment assignments |
G |
vector of group assignments |
parameters |
vector of parameters passed to |
runSilent |
If FALSE, prints errors to console. Defaults to TRUE. |
... |
additional arguments passed to |
N X length(params) matrix of scores
Retrieves the population average total causal effect for
specified allocations:
total_effect(object, allocation1, allocation2 = NULL, trt.lvl1 = 0) te(object, allocation1, allocation2 = NULL, trt.lvl1 = 0)
total_effect(object, allocation1, allocation2 = NULL, trt.lvl1 = 0) te(object, allocation1, allocation2 = NULL, trt.lvl1 = 0)
object |
an object of class |
allocation1 |
the allocation scheme for which to estimate total effects |
allocation2 |
the allocation scheme for which to estimate total effects If NULL, then returns all indirect effects compared to allocation1. |
trt.lvl1 |
Defaults to 0. |
a data.frame with requested values
A sample dataset based on the simulations of a cholera vaccine trial in Heydrich-Perez et al. (2014) (doi:10.1111/biom.12184) except with 3000 individuals in 250 groups rather than 10000 in 500.
a dataset with 6 variables and 3000 rows
Ythe outcome (0 - no cholera; 1 - cholera)
X1an individual's age (in decades)
X2an individual's distance from river
Aan indicator of vaccination (0 - no vaccine; 1 - vaccine)
Ban indicator of participation (0 - did not participant in vaccine trial, 1 - did participate)
groupgroup membership
Perez-Heydrich, C., Hudgens, M. G., Halloran, M. E., Clemens, J. D., Ali, M., & Emch, M. E. (2014). Assessing effects of cholera vaccination in the presence of interference. Biometrics, 70(3), 731-741.
A dataset of a voting contagion experiment. See Nickerson (2008) for more details. The variables used in the package vignette are documented here.
a dataset with 21 variables and 7722 rows
familyhousehold ID
denver1 = subject in Denver, 0 = Minneapolis
treatment1 = voting encouragement, 2 = recycling message, 3 = not contacted
reached1 = subject answered door, 0 = not
hsecontact1 = household contacted by canvassers, 0 = not
voted02p1 = voted in '02 primary, 0 = not
partyparty affiliation
ageage
gendergender
Nickerson, D. W. (2008). Is voting contagious? Evidence from two field experiments. American Political Science Review, 102(01), 49-57. doi:10.1017/S0003055408080039
Calculates the IPW for a single group. Used by wght_matrix
to
create a matrix of weights for each group and allocation scheme.
wght_calc(parameters, integrand, allocation, integrate_allocation = TRUE, ...)
wght_calc(parameters, integrand, allocation, integrate_allocation = TRUE, ...)
parameters |
vector of parameter values |
integrand |
function to pass to the argument 'f' of |
allocation |
the allocation ratio for which to compute the weight |
integrate_allocation |
Indicator of whether the integrand function uses the allocation parameter. Defaults to TRUE. |
... |
other arguments passed to integrand. |
If allocation
is an argument in the integrand function and
integrate_allocation == TRUE
, then the weight is calcuated as:
Otherwise, the weight is computed by:
scalar result of the integral
Uses wght_deriv_calc
to compute the weight derivatives for each
group per coverage level
wght_deriv_array( parameters, integrand, allocations, X, A, G, runSilent = TRUE, integrate_allocation = TRUE, ... )
wght_deriv_array( parameters, integrand, allocations, X, A, G, runSilent = TRUE, integrate_allocation = TRUE, ... )
parameters |
vector of parameters passed to |
integrand |
function to pass to the argument 'f' of |
allocations |
coverage levels in [0, 1]. Can be vector. |
X |
covariate matrix |
A |
vector of treatment assignments |
G |
vector of group assignments |
runSilent |
if FALSE, errors are printed to console. Defaults to TRUE. |
integrate_allocation |
Indicator of whether the integrand function uses the allocation parameter. Defaults to TRUE. |
... |
other arguments passed to integrand. |
a length(unique(group)) X length(params) X length(alphas) array of group weight derivatives
Takes the derivative of the wght_calc
function with respect to each
parameter in params
.
wght_deriv_calc( integrand, parameters, allocation, integrate_allocation = TRUE, ... )
wght_deriv_calc( integrand, parameters, allocation, integrate_allocation = TRUE, ... )
integrand |
function to pass to the argument 'f' of |
parameters |
vector of parameter values |
allocation |
the allocation ratio for which to compute the weight |
integrate_allocation |
Indicator of whether the integrand function uses the allocation parameter. Defaults to TRUE. |
... |
other arguments passed to integrand. |
vector of derivatives with respect to element of params
Groups should be numbered 1, ..., N
wght_matrix( integrand, allocations, X, A, G, parameters, runSilent = TRUE, integrate_allocation = TRUE, ... )
wght_matrix( integrand, allocations, X, A, G, parameters, runSilent = TRUE, integrate_allocation = TRUE, ... )
integrand |
function to pass to the argument 'f' of |
allocations |
coverage levels in [0, 1]. Can be vector. |
X |
covariate matrix |
A |
vector of treatment assignments |
G |
vector of group assignments |
parameters |
vector of parameters passed to |
runSilent |
if FALSE, errors are printed to console. Defaults to TRUE. |
integrate_allocation |
Indicator of whether the integrand function uses the allocation parameter. Defaults to TRUE. |
... |
other arguments passed to integrand. |
a length(unique(group)) X length(alphas) matrix of group weights