Fits subgroup identification models
fit_subgroup_2part(
x,
y,
trt,
propensity.func = NULL,
propensity.func.positive = NULL,
match.id = NULL,
augment.func.zero = NULL,
augment.func.positive = NULL,
cutpoint = 1,
larger.outcome.better = TRUE,
penalize.ate = TRUE,
y_eps = 1e-06,
...
)The design matrix (not including intercept term)
The nonnegative response vector
treatment vector with each element equal to a 0 or a 1, with 1 indicating treatment status is active.
function that inputs the design matrix x and the treatment vector trt and outputs
the propensity score, ie Pr(trt = 1 | X = x). Function should take two arguments 1) x and 2) trt. See example below.
For a randomized controlled trial this can simply be a function that returns a constant equal to the proportion
of patients assigned to the treatment group, i.e.:
propensity.func = function(x, trt) 0.5.
function that inputs the design matrix x and the treatment vector trt and outputs
the propensity score for units with positive outcome values, ie Pr(trt = 1 | X = x, Z = 1). Function should take
two arguments 1) x and 2) trt. See example below.
For a randomized controlled trial this can simply be a function that returns a constant equal to the proportion
of patients assigned to the treatment group, i.e.:
propensity.func = function(x, trt) 0.5.
a (character, factor, or integer) vector with length equal to the number of observations in x
indicating using integers or levels of a factor vector which patients are
in which matched groups. Defaults to NULL and assumes the samples are not from a matched cohort. Matched
case-control groups can be created using any method (propensity score matching, optimal matching, etc). If each case
is matched with a control or multiple controls, this would indicate which case-control pairs or groups go together.
If match.id is supplied, then it is unecessary to specify a function via the propensity.func argument.
A quick usage example: if the first patient is a case and the second and third are controls matched to it, and the
fouth patient is a case and the fifth through seventh patients are matched with it, then the user should specify
match.id = c(1,1,1,2,2,2,2) or match.id = c(rep("Grp1", 3),rep("Grp2", 4))
the covariates x, and trt and outputs predicted values (on the probability scale) for the response using a model
constructed with x. augment.func.zero() can also be simply
a function of x and y. This function is used for efficiency augmentation.
When the form of the augmentation function is correct, it can provide efficient estimation of the subgroups. Some examples of possible
augmentation functions are:
Example 1: augment.func <- function(x, y) {lmod <- glm(y ~ x, family = binomial()); return(fitted(lmod))}
Example 2:
augment.func <- function(x, y, trt) {
data <- data.frame(x, y, trt)
lmod <- glm(y ~ x * trt, family = binomial())
## get predictions when trt = 1
data$trt <- 1
preds_1 <- predict(lmod, data, type = "response") ## get predictions when trt = -1
data$trt <- -1
preds_n1 <- predict(lmod, data, type = "response")
## return predictions averaged over trt
return(0.5 * (preds_1 + preds_n1))
}
(similar to augment.func.positive) function which inputs the
indicators of whether each response is positive (1*(y > 0)),
the covariates x, and trt for all samples and outputs predicted values (on the link scale) for the response using a model
constructed with x. augment.func.positive() can also be simply
a function of x and y. This function is used for efficiency augmentation.
(similar to augment.func.zero) function which inputs the positive part response
(ie all observations in y which are strictly positive),
the covariates x, and trt and outputs predicted values (on the link scale) for the response using a model
constructed with x. augment.func.positive() can also be simply
a function of x and y. This function is used for efficiency augmentation.
numeric value for patients with benefit scores above which
(or below which if larger.outcome.better = FALSE)
will be recommended to be in the treatment group. Defaults to 1, since the benefit score is a risk ratio
boolean value of whether a larger outcome is better/preferable. Set to TRUE
if a larger outcome is better/preferable and set to FALSE if a smaller outcome is better/preferable. Defaults to TRUE.
should the treatment main effect (ATE) be penalized too?
positive value above which observations in y will be considered positive
options to be passed to cv.hd2part
# NOT RUN {
set.seed(42)
dat <- sim_semicontinuous_data(250, n.vars = 15)
x <- dat$x
y <- dat$y
trt <- dat$trt
prop_func <- function(x, trt)
{
propensmod <- glm(trt ~ x, family = binomial())
propens <- unname(fitted(propensmod))
propens
}
fitted_model <- fit_subgroup_2part(x, y, trt, prop_func, prop_func)
fitted_model
## correlation of estimated covariate-conditional risk ratio and truth
cor(fitted_model$benefit.scores, dat$treatment_risk_ratio, method = "spearman")
# }
Run the code above in your browser using DataLab