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
mids
object from themice
package- 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.- 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_dir
set 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,
i
selects 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"
)
print(fit_m0)
#> Please inspect the Wald test to determine if the exposures collectively predict significant variation in the outcome compared to a model without exposure terms.
#> We strongly suggest only conducting history comparisons if the test is significant.
#>
#> Wald test
#> Variance: HC0 robust (adjusted for estimation of weights)
#>
#> Model 1: D.3 ~ A.1 + A.2 + A.3
#> Model 2: D.3 ~ 1
#>
#> Res.Df Df Chisq Pr(>Chisq)
#> 1 46
#> 2 49 3 17.511 0.0005548 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#>
#> The marginal model, m0, is summarized below:
#> +-------------+--------+-----------------+-------+
#> | | (1) |
#> +-------------+--------+-----------------+-------+
#> | | Est. | CI | p |
#> +=============+========+=================+=======+
#> | (Intercept) | 0.224 | [-0.011, 0.460] | 0.062 |
#> +-------------+--------+-----------------+-------+
#> | A.1 | 0.350 | [0.141, 0.560] | 0.001 |
#> +-------------+--------+-----------------+-------+
#> | A.2 | -0.186 | [-0.432, 0.060] | 0.139 |
#> +-------------+--------+-----------------+-------+
#> | A.3 | -0.284 | [-0.682, 0.114] | 0.163 |
#> +-------------+--------+-----------------+-------+
#> | Num.Obs. | 50 | | |
#> +-------------+--------+-----------------+-------+
fit_m1 <- fitModel(
data = data, weights = w,
outcome = "D.3", model = "m1",
covariates = c("C")
)
print(fit_m1)
#> Please inspect the Wald test to determine if the exposures collectively predict significant variation in the outcome compared to a model without exposure terms.
#> We strongly suggest only conducting history comparisons if the test is significant.
#>
#> Wald test
#> Variance: HC0 robust (adjusted for estimation of weights)
#>
#> Model 1: D.3 ~ A.1 + A.2 + A.3 + C
#> Model 2: D.3 ~ C
#>
#> Res.Df Df Chisq Pr(>Chisq)
#> 1 45
#> 2 48 3 17.633 0.0005236 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#>
#> The marginal model, m1, is summarized below:
#> +-------------+--------+-----------------+--------+
#> | | (1) |
#> +-------------+--------+-----------------+--------+
#> | | Est. | CI | p |
#> +=============+========+=================+========+
#> | (Intercept) | 0.222 | [-0.013, 0.458] | 0.064 |
#> +-------------+--------+-----------------+--------+
#> | A.1 | 0.352 | [0.143, 0.561] | <0.001 |
#> +-------------+--------+-----------------+--------+
#> | A.2 | -0.185 | [-0.432, 0.062] | 0.142 |
#> +-------------+--------+-----------------+--------+
#> | A.3 | -0.287 | [-0.689, 0.116] | 0.163 |
#> +-------------+--------+-----------------+--------+
#> | C | -0.044 | [-0.277, 0.188] | 0.708 |
#> +-------------+--------+-----------------+--------+
#> | Num.Obs. | 50 | | |
#> +-------------+--------+-----------------+--------+
fit_m2 <- fitModel(
data = data, weights = w,
outcome = "D.3", model = "m2",
int_order = 2
)
print(fit_m2)
#> Please inspect the Wald test to determine if the exposures collectively predict significant variation in the outcome compared to a model without exposure terms.
#> We strongly suggest only conducting history comparisons if the test is significant.
#>
#> Wald test
#> Variance: HC0 robust (adjusted for estimation of weights)
#>
#> Model 1: D.3 ~ A.1 + A.2 + A.3 + A.1 + A.2 + A.3 + A.1:A.2 + A.1:A.3 + A.2:A.3
#> Model 2: D.3 ~ 1
#>
#> Res.Df Df Chisq Pr(>Chisq)
#> 1 43
#> 2 49 6 19.785 0.003024 **
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#>
#> The marginal model, m2, is summarized below:
#> +-------------+--------+-----------------+-------+
#> | | (1) |
#> +-------------+--------+-----------------+-------+
#> | | Est. | CI | p |
#> +=============+========+=================+=======+
#> | (Intercept) | 0.207 | [-0.031, 0.446] | 0.089 |
#> +-------------+--------+-----------------+-------+
#> | A.1 | 0.404 | [0.161, 0.647] | 0.001 |
#> +-------------+--------+-----------------+-------+
#> | A.2 | -0.145 | [-0.420, 0.131] | 0.303 |
#> +-------------+--------+-----------------+-------+
#> | A.3 | -0.318 | [-0.650, 0.013] | 0.060 |
#> +-------------+--------+-----------------+-------+
#> | A.1 × A.2 | 0.234 | [-0.036, 0.505] | 0.089 |
#> +-------------+--------+-----------------+-------+
#> | A.1 × A.3 | -0.018 | [-0.364, 0.328] | 0.918 |
#> +-------------+--------+-----------------+-------+
#> | A.2 × A.3 | 0.247 | [-0.090, 0.584] | 0.152 |
#> +-------------+--------+-----------------+-------+
#> | Num.Obs. | 50 | | |
#> +-------------+--------+-----------------+-------+
fit_m3 <- fitModel(
data = data, weights = w,
outcome = "D.3", model = "m3",
int_order = 2, covariates = c("C")
)
print(fit_m3)
#> Please inspect the Wald test to determine if the exposures collectively predict significant variation in the outcome compared to a model without exposure terms.
#> We strongly suggest only conducting history comparisons if the test is significant.
#>
#> Wald test
#> Variance: HC0 robust (adjusted for estimation of weights)
#>
#> Model 1: D.3 ~ A.1 + A.2 + A.3 + A.1 + A.2 + A.3 + C + A.1:A.2 + A.1:A.3 + A.1:C + A.2:A.3 + A.2:C + A.3:C
#> Model 2: D.3 ~ C
#>
#> Res.Df Df Chisq Pr(>Chisq)
#> 1 39
#> 2 48 9 23.536 0.005098 **
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#>
#> The marginal model, m3, is summarized below:
#> +-------------+--------+------------------+--------+
#> | | (1) |
#> +-------------+--------+------------------+--------+
#> | | Est. | CI | p |
#> +=============+========+==================+========+
#> | (Intercept) | 0.187 | [-0.058, 0.432] | 0.134 |
#> +-------------+--------+------------------+--------+
#> | A.1 | 0.422 | [0.182, 0.662] | <0.001 |
#> +-------------+--------+------------------+--------+
#> | A.2 | -0.126 | [-0.411, 0.159] | 0.387 |
#> +-------------+--------+------------------+--------+
#> | A.3 | -0.353 | [-0.654, -0.053] | 0.021 |
#> +-------------+--------+------------------+--------+
#> | C | -0.137 | [-0.360, 0.087] | 0.231 |
#> +-------------+--------+------------------+--------+
#> | A.1 × A.2 | 0.238 | [-0.067, 0.542] | 0.126 |
#> +-------------+--------+------------------+--------+
#> | A.1 × A.3 | 0.013 | [-0.352, 0.377] | 0.946 |
#> +-------------+--------+------------------+--------+
#> | A.1 × C | 0.156 | [-0.102, 0.414] | 0.236 |
#> +-------------+--------+------------------+--------+
#> | A.2 × A.3 | 0.281 | [-0.051, 0.614] | 0.097 |
#> +-------------+--------+------------------+--------+
#> | A.2 × C | 0.199 | [-0.055, 0.454] | 0.124 |
#> +-------------+--------+------------------+--------+
#> | A.3 × C | -0.080 | [-0.432, 0.271] | 0.655 |
#> +-------------+--------+------------------+--------+
#> | Num.Obs. | 50 | | |
#> +-------------+--------+------------------+--------+