Learn R Programming

clarify (version 0.2.1)

transform.clarify_est: #' Transform and combine clarify_est objects

Description

transform() modifies a clarify_est object by allowing for the calculation of new quantities from the existing quantities without re-simulating them. cbind() binds two clarify_est objects together.

Usage

# S3 method for clarify_est
transform(`_data`, ...)

# S3 method for clarify_est cbind(..., deparse.level = 1)

Value

A clarify_est object, either with new columns added (when using transform()) or combining two clarify_est objects. Note that any type attributes corresponding to the sim_apply() wrapper used (e.g., sim_ame()) is lost when using either function. This can affect any helper functions (e.g., plot()) designed to work with the output of specific wrappers.

Arguments

_data

the clarify_est object to be transformed.

...

for transform(), arguments in the form name = value, where name is the name of a new quantity to be computed and value is an expression that is a function of the existing quantities corresponding to the new quantity to be computed. See Details. For cbind(), clarify_est objects to be combined.

deparse.level

ignored.

Details

For transform(), the expression on the right side of the = should use the names of the existing quantities (e.g., `E[Y(1)]` - `E[Y(1)]`), with ` appropriately included when the quantity name include parentheses or brackets. Alternatively, it can use indexes prefixed by .b, e.g., .b2 - .b1, to refer to the corresponding quantity by position. This can aid in computing derived quantities of quantities with complicated names. (Note that if a quantity is named something like .b1, it will need to be referred to by position rather than name, as the position-based label takes precedence). See examples. Setting an existing value to NULL will remove that quantity from the object.

cbind() does not rename the quanities or check for uniqueness of the names, so it is important to rename them yourself prior to combining the objects.

See Also

Examples

Run this code
data("lalonde", package = "MatchIt")

# Fit the model
fit <- lm(re78 ~ treat * (age + educ + race +
             married + re74 + re75),
           data = lalonde)

# Simulate coefficients
set.seed(123)
s <- sim(fit, n = 100)

# Average adjusted predictions for `treat` within
# subsets of `race`
est_b <- sim_ame(s, var = "treat", verbose = FALSE,
                 subset = race == "black")
est_b

est_h <- sim_ame(s, var = "treat", verbose = FALSE,
                 subset = race == "hispan")
est_h

# Compute differences between adjusted predictions
est_b <- transform(est_b,
                   diff = `E[Y(1)]` - `E[Y(0)]`)
est_b

est_h <- transform(est_h,
                   diff = `E[Y(1)]` - `E[Y(0)]`)
est_h

# Bind estimates together after renaming
names(est_b) <- paste0(names(est_b), "_b")
names(est_h) <- paste0(names(est_h), "_h")

est <- cbind(est_b, est_h)
est

# Compute difference in race-specific differences
est <- transform(est,
                 `diff-diff` = .b6 - .b3)

summary(est,
        parm = c("diff_b", "diff_h", "diff-diff"))

# Remove last quantity by using `NULL`
transform(est, `diff-diff` = NULL)

Run the code above in your browser using DataLab