average_predictions {beeca}R Documentation

Average over counterfactual predictions

Description

average_predictions() averages counterfactual predictions stored within a glm object. This is pivotal for estimating treatment contrasts and associated variance estimates using g-computation. The function assumes predictions are generated via predict_counterfactuals().

Usage

average_predictions(object)

Arguments

object

a fitted glm object augmented with counterfactual predictions named: counterfactual.predictions

Details

The average_predictions() function calculates the average over the counterfactual predictions which can then be used to estimate a treatment contrast and associated variance estimate.

The function appends a glm object with the averaged counterfactual predictions.

Note: Ensure that the glm object has been adequately prepared with predict_counterfactuals() before applying average_predictions(). Failure to do so may result in errors indicating missing components.

Value

an updated glm object appended with an additional component counterfactual.means.

See Also

predict_counterfactuals() for generating counterfactual predictions.

estimate_varcov() for estimating the variance-covariate matrix of mariginal effects

get_marginal_effect() for estimating marginal effects directly from an original glm object

Examples


# Use the trial01 dataset
data(trial01)

# ensure the treatment indicator is a factor
trial01$trtp <- factor(trial01$trtp)

# fit glm model for trial data
fit1 <- glm(aval ~ trtp + bl_cov, family = "binomial", data = trial01)

# Preprocess fit1 as required by average_predictions
fit2 <- fit1 |>
  predict_counterfactuals(trt = "trtp")

# average over the counterfactual predictions
fit3 <- average_predictions(fit2)

# display the average predictions
fit3$counterfactual.means


[Package beeca version 0.1.3 Index]