View source: R/calculate_treatment_effects.R
treatment.effects | R Documentation |
Calculates covariate conditional treatment effects using estimated benefit scores
treatment.effects(x, ...) ## Default S3 method: treatment.effects(x, ...) treat.effects( benefit.scores, loss = c("sq_loss_lasso", "logistic_loss_lasso", "poisson_loss_lasso", "cox_loss_lasso", "owl_logistic_loss_lasso", "owl_logistic_flip_loss_lasso", "owl_hinge_loss", "owl_hinge_flip_loss", "sq_loss_lasso_gam", "poisson_loss_lasso_gam", "logistic_loss_lasso_gam", "sq_loss_gam", "poisson_loss_gam", "logistic_loss_gam", "owl_logistic_loss_gam", "owl_logistic_flip_loss_gam", "owl_logistic_loss_lasso_gam", "owl_logistic_flip_loss_lasso_gam", "sq_loss_xgboost", "custom"), method = c("weighting", "a_learning"), pi.x = NULL, ... ) ## S3 method for class 'subgroup_fitted' treatment.effects(x, ...)
x |
a fitted object from |
... |
not used |
benefit.scores |
vector of estimated benefit scores |
loss |
loss choice USED TO CALCULATE |
method |
method choice USED TO CALCULATE |
pi.x |
The propensity score for each observation |
A List with elements delta
(if the treatment effects are a difference/contrast,
i.e. E[Y|T=1, X] - E[Y|T=-1, X]) and gamma
(if the treatment effects are a ratio,
i.e. E[Y|T=1, X] / E[Y|T=-1, X])
fit.subgroup
for function which fits subgroup identification models.
print.individual_treatment_effects
for printing of objects returned by
treat.effects
or treatment.effects
library(personalized) set.seed(123) n.obs <- 500 n.vars <- 25 x <- matrix(rnorm(n.obs * n.vars, sd = 3), n.obs, n.vars) # simulate non-randomized treatment xbetat <- 0.5 + 0.5 * x[,21] - 0.5 * x[,11] trt.prob <- exp(xbetat) / (1 + exp(xbetat)) trt01 <- rbinom(n.obs, 1, prob = trt.prob) trt <- 2 * trt01 - 1 # simulate response delta <- 2 * (0.5 + x[,2] - x[,3] - x[,11] + x[,1] * x[,12]) xbeta <- x[,1] + x[,11] - 2 * x[,12]^2 + x[,13] xbeta <- xbeta + delta * trt # continuous outcomes y <- drop(xbeta) + rnorm(n.obs, sd = 2) # time-to-event outcomes surv.time <- exp(-20 - xbeta + rnorm(n.obs, sd = 1)) cens.time <- exp(rnorm(n.obs, sd = 3)) y.time.to.event <- pmin(surv.time, cens.time) status <- 1 * (surv.time <= cens.time) # create function for fitting propensity score model prop.func <- function(x, trt) { # fit propensity score model propens.model <- cv.glmnet(y = trt, x = x, family = "binomial") pi.x <- predict(propens.model, s = "lambda.min", newx = x, type = "response")[,1] pi.x } subgrp.model <- fit.subgroup(x = x, y = y, trt = trt01, propensity.func = prop.func, loss = "sq_loss_lasso", nfolds = 3) # option for cv.glmnet trt_eff <- treatment.effects(subgrp.model) str(trt_eff) trt_eff library(survival) subgrp.model.cox <- fit.subgroup(x = x, y = Surv(y.time.to.event, status), trt = trt01, propensity.func = prop.func, loss = "cox_loss_lasso", nfolds = 3) # option for cv.glmnet trt_eff_c <- treatment.effects(subgrp.model.cox) str(trt_eff_c) trt_eff_c
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.