trajmsm_ipw {trajmsm} | R Documentation |
Marginal Structural Model and Latent Class of Growth Analysis estimated with IPW
Description
Estimate parameters of LCGA-MSM using IPW.
Usage
trajmsm_ipw(
formula1,
formula2,
family,
identifier,
treatment,
covariates,
baseline,
obsdata,
numerator = "stabilized",
include_censor = FALSE,
censor,
weights = NULL,
treshold = 0.99
)
Arguments
formula1 |
Specification of the model for the outcome to be fitted for a binomial or gaussian distribution. |
formula2 |
Specification of the model for the outcome to be fitted for a survival outcome. |
family |
Specification of the error distribution and link function to be used in the model. |
identifier |
Name of the column of the unique identifier. |
treatment |
Time-varying treatment. |
covariates |
Names of the time-varying covariates (should be a list). |
baseline |
Name of the baseline covariates. |
obsdata |
Dataset to be used in the analysis. |
numerator |
Type of weighting ("stabilized" or "unstabilized"). |
include_censor |
Logical, if TRUE, includes censoring. |
censor |
Name of the censoring variable. |
weights |
A vector of estimated weights. If NULL, the weights are computed by the function |
treshold |
For weight truncation. |
Value
Provides a matrix of estimates for LCGA-MSM, obtained using IPW.
Provides a matrix of estimates for LCGA-MSM, obtained using IPW.
Examples
obsdata_long = gendata(n = 1000, format = "long", total_followup = 6, seed = 945)
years <- 2011:2016
baseline_var <- c("age","sex")
variables <- c("hyper", "bmi")
covariates <- lapply(years, function(year) {
paste0(variables, year)})
treatment_var <- paste0("statins", 2011:2016)
formula_treatment = as.formula(cbind(statins, 1 - statins) ~ time)
restraj = build_traj(obsdata = obsdata_long, number_traj = 3,
formula = formula_treatment, identifier = "id")
datapost = restraj$data_post
trajmsm_long <- merge(obsdata_long, datapost, by = "id")
AggFormula <- as.formula(paste("statins", "~", "time", "+", "class"))
AggTrajData <- aggregate(AggFormula, data = trajmsm_long, FUN = mean)
AggTrajData
trajmsm_long$ipw_group <- relevel(trajmsm_long$class, ref = "1")
obsdata = reshape(data = trajmsm_long, direction = "wide", idvar = "id",
v.names = c("statins","bmi","hyper"), timevar = "time", sep ="")
formula = paste0("y ~", paste0(treatment_var,collapse = "+"), "+",
paste0(unlist(covariates), collapse = "+"),"+",
paste0(baseline_var, collapse = "+"))
resmsm_ipw = trajmsm_ipw(formula1 = as.formula("y ~ ipw_group"),
identifier = "id", baseline = baseline_var, covariates = covariates,
treatment = treatment_var, family = "binomial",
obsdata = obsdata,numerator = "stabilized", include_censor = FALSE, treshold = 0.99)
resmsm_ipw