Fits weighted marginal outcome model as a generalized linear model of the user's choosing, relating exposure main effects to outcome using IPTW weights.
Arguments
- data
data in wide format as: a data frame, list of imputed data frames, or
midsobject from themicepackage- obj
initialized MSM object from
initMSM()- weights
list of IPTW weights output from
createWeights()- outcome
name of outcome variable with ".timepoint" suffix. See
initMSM()for details on suffix- model
character indicating one of the following outcome models:
"m0" (exposure main effects)
"m1" (exposure main effects & covariates)
"m2" (exposure main effects & their interactions)
"m3" (exposure main effects, their interactions, & covariates)
- int_order
integer specification of highest order exposure main effects interaction, required for interaction models ("m2", "m3")
- covariates
list of characters reflecting variable names of covariates, required for covariate models ("m1", "m3")
- family
(optional) family function specification for
WeightIt::glm_weightit()model. Note that this should be specified as as a function, not a character string unless you have a multinomial outcome, in which case set this to "multinomial", or if you have an ordinal outcome with more than 2 levels, in which case set this to "ordinal". (default is gaussian)- link
(optional) link function specification for
WeightIt::glm_weightit()model.- verbose
(optional) TRUE or FALSE indicator for printing output to console. default is FALSE.
- save.out
(optional) Either logical or a character string. If
TRUE, it will output the result to a default file name withinhome_dirset ininitMSM(). You can load the data withx <- readRDS(file). To use a non-default file name, specify a character string with the file name. It will save relative tohome_dir. There might be naming conflicts where two objects get saved to the same file. In these cases, users should specify a custom name. default is FALSE.- x
devMSM_models object from
fitModel- i
For multiply imputed datasets,
iselects which imputation to print results for. Default isi = 1. Withi = TRUE, all imputed datasets will be looped over. Withi = NULL, will average over all imputed datasets and summarize that. Ignored for non-imputed data.- ...
ignored
Value
list containing WeightIt::glm_weightit() model output. It is the length
of the number of datasets (1 for a data.frame or the number of imputed datasets)
See also
WeightIt::glm_weightit() for more on family/link specifications.
Examples
library(devMSMs)
data <- data.frame(
ID = 1:50,
A.1 = rnorm(n = 50),
A.2 = rnorm(n = 50),
A.3 = rnorm(n = 50),
B.1 = rnorm(n = 50),
B.2 = rnorm(n = 50),
B.3 = rnorm(n = 50),
C = rnorm(n = 50),
D.3 = rnorm(n = 50)
)
obj <- initMSM(
data,
exposure = c("A.1", "A.2", "A.3"),
ti_conf = c("C"),
tv_conf = c("B.1", "B.2", "B.3", "D.3")
)
f <- createFormulas(obj, type = "short")
w <- createWeights(data = data, formulas = f)
fit_m0 <- fitModel(
data = data, weights = w,
outcome = "D.3", model = "m0"
)
#> Error in all_fits[[1]]: subscript out of bounds
print(fit_m0)
#> Error: object 'fit_m0' not found
fit_m1 <- fitModel(
data = data, weights = w,
outcome = "D.3", model = "m1",
covariates = c("C")
)
#> Error in all_fits[[1]]: subscript out of bounds
print(fit_m1)
#> Error: object 'fit_m1' not found
fit_m2 <- fitModel(
data = data, weights = w,
outcome = "D.3", model = "m2",
int_order = 2
)
#> Error in all_fits[[1]]: subscript out of bounds
print(fit_m2)
#> Error: object 'fit_m2' not found
fit_m3 <- fitModel(
data = data, weights = w,
outcome = "D.3", model = "m3",
int_order = 2, covariates = c("C")
)
#> Error in all_fits[[1]]: subscript out of bounds
print(fit_m3)
#> Error: object 'fit_m3' not found
data <- data.frame(
ID = 1:50,
A.1 = rnorm(n = 50),
A.2 = rnorm(n = 50),
A.3 = rnorm(n = 50),
B.1 = rnorm(n = 50),
B.2 = rnorm(n = 50),
B.3 = rnorm(n = 50),
C = rnorm(n = 50),
D.3 = c(rep(c("A", "B", "C"), 16), "A", "B")
)
obj <- initMSM(
data,
exposure = c("A.1", "A.2", "A.3"),
ti_conf = c("C"),
tv_conf = c("B.1", "B.2", "B.3", "D.3")
)
f <- createFormulas(obj, type = "short")
w <- createWeights(data = data, formulas = f)
fit_m0 <- fitModel(
data = data, weights = w,
outcome = "D.3", model = "m0", family = "multinomial"
)
print(fit_m0)
#> Error: There are duplicate labels in the estimates table. Call `get_estimates()` to see the available identifiers, and use the `shape` argument to specify the (potentially nested or grouped) nature of parameters. Alternatively, duplication can happen when you use `coef_map` or `coef_rename` to assign the same label to multiple variables, but these variables are part of the same model. Please check your `coef_map` and `coef_rename` arguments.