Description Usage Arguments Details Value References Examples
Performs g-estimation of a structural nested mean model (SNMM), based on the outcome regression methods described in Sjolander and Vansteelandt (2016) and Dukes and Vansteelandt (2018). We expect a dataset that holds an end of study outcome that is either binary or continuous, time-varying and/or baseline confounders, and a time-varying exposure that is either binary, continuous or categorical.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
data |
A data frame in long format containing the data to be analysed. See description for details. |
idvar |
Character string specifying the name of the ID variable in the data. |
timevar |
Character string specifying the name of the time variable in the data. Note that timevar must specify time periods as integer values starting from 1 (must not begin at 0). |
Yn |
Character string specifying the name of the end of study outcome variable. |
An |
Character string specifying the name of the time-varying exposure variable. |
Cn |
Optional character string specifying the name of the censoring indicator variable. The variable specified in Cn should be a numeric vector taking values 0 or 1, with 1 indicating censored. |
outcomemodels |
a list of formulas or formula objects specifying the outcome models for Yn prior to adjustment by propensity score. The i'th entry of the list specifies the outcome model for the counterfactuals up to time i. See description for details. |
propensitymodel |
A formula or formula object specifying the propensity score model for An. |
censoringmodel |
A formula or formula object specifying the censoring model for Cn. |
type |
Value from 1-4 specifying SNMM type to fit. See details. |
EfmVar |
Character string specifying the name of the effect modifying variable for types 2 or 4. |
... |
Additional arguments, currently not in use. |
Given a time-varying exposure variable, A_t and time-varying confounders, L_t measured over time periods t=1,…,T, and an end of study outcome Y
measured at time T+1, gest
estimates the causal parameters ψ of a SNMM of the form
E(Y(\bar{a}_{t},0)-Y(\bar{a}_{t-1},0)|\bar{a}_{t-1},\bar{l}_{t})=ψ z_ta_t \;\forall\; t=1,…,T
if Y is continuous or
\frac{E(Y(\bar{a}_{t},0)|\bar{a}_{t-1},\bar{l}_{t})}{E(Y(\bar{a}_{t-1},0)|\bar{a}_{t-1},\bar{l}_{t})}=exp(ψ z_ta_t)\;\forall\; t=1,…,T
if Y is binary. The SNMMs form is defined by the parameter z_t, which can be controlled by the input type
as follows
type=1
sets z_t=1. This implies that ψ is the effect of exposure at any time t on Y.
type=2
sets z_t=c(1,l_t), and adds affect modification by EfmVar
, which we denote L_t.
Now ψ=c(ψ_0,ψ_1) where ψ_0 is the effect of exposure at any time t on Y when l_t=0 for all t, modified by
ψ_1 for each unit increase in l_t at all times t. Note that effect modification
is currently only supported for binary (written as a numeric 0,1 vector) or continuous confounders.
type=3
allows for time-varying causal effects. It sets z_t to a vector of zeros of length T with a 1 in the t'th position. Now ψ=c(ψ_1,…,ψ_T)
where ψ_t is the effect of A_t on Y.
type=4
allows for a time-varying causal effect that can be modified by EfmVar
, denoted l_t, that is it allows for both time-varying effects and effect modification. It sets z_t to a vector of zeros of length T with c(1,l_t) in the t'th position.
Now ψ=(\underline{ψ_1},…,\underline{ψ_T}) where \underline{ψ_t}=c(ψ_{0t},ψ_{1t}). Here ψ_{0t} is the effect of exposure at time t on Y when l_t=0 modified by
ψ_{1t} for each unit increase in l_t. Note that effect modification
is currently only supported for binary (written as a numeric 0,1 vector) or continuous confounders.
The data must be in long format, where we assume the convention that each row with time=t
contains A_t,L_t and C_{t+1} and Y_{T+1}. Thus the censoring indicator for each row
should indicate that a user is censored AFTER time t. The end of study outcome Y_{T+1} should be repeated on each row. If either A or Y are binary, they must be written as numeric vectors taking values either 0 or 1.
The same is true for any covariate that is used for effect modification.
The data must be rectangular with a row entry for every individual for each exposure time 1 up to T. Data rows after censoring should be empty apart from the ID and time variables. This can be done using the function FormatData
.
The input outcomemodels should be a list with T elements (the number of exposure times), where element i describes the outcome model for the counterfactuals at time i.
List of the fitted causal parameters of the posited SNMM. These are labeled as follows for each SNMM type, where An
is
set to the name of the exposure variable, i is the current time period, and and EfmVar is the effect modifying variable.
|
|
|
|
.
|
|
|
|
The function also returns a summary of the propensity scores and censoring scores via PropensitySummary
and CensoringSummary
,
along with Data
, holding the original dataset with the propensity and censoring scores as a tibble dataset.
Vansteelandt, S., & Sjolander, A. (2016). Revisiting g-estimation of the Effect of a Time-varying Exposure Subject to Time-varying Confounding, Epidemiologic Methods, 5(1), 37-56. <doi:10.1515/em-2015-0005>.
Dukes, O., & Vansteelandt, S. (2018). A Note on g-Estimation of Causal Risk Ratios, American Journal of Epidemiology, 187(5), 1079–1084. <doi:10.1093/aje/kwx347>.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | datas <- dataexamples(n = 1000, seed = 123, Censoring = FALSE)
data <- datas$datagest
data <- FormatData(
data = data, idvar = "id", timevar = "time", An = "A",
varying = c("Y", "A", "L"), GenerateHistory = TRUE, GenerateHistoryMax = 1
)
idvar <- "id"
timevar <- "time"
Yn <- "Y"
An <- "A"
Cn <- NA
outcomemodels <- list("Y~A+L+U+Lag1A", "Y~A+L+U+Lag1A", "Y~A+L+U+Lag1A")
propensitymodel <- c("A~L+U+as.factor(time)+Lag1A")
censoringmodel <- NULL
EfmVar <- NA
gestSingle(data, idvar, timevar, Yn, An, Cn, outcomemodels, propensitymodel,
censoringmodel = NULL, type = 1, EfmVar)
# Example with censoring
datas <- dataexamples(n = 1000, seed = 123, Censoring = TRUE)
data <- datas$datagest
data <- FormatData(
data = data, idvar = "id", timevar = "time", An = "A", Cn = "C",
varying = c("Y", "A", "L"), GenerateHistory = TRUE, GenerateHistoryMax = 1
)
Cn <- "C"
EfmVar <- "L"
outcomemodels <- list("Y~A+L+U+A:L+Lag1A", "Y~A+L+U+A:L+Lag1A", "Y~A+L+U+A:L")
censoringmodel <- c("C~L+U+as.factor(time)")
gestSingle(data, idvar, timevar, Yn, An, Cn, outcomemodels, propensitymodel,
censoringmodel = censoringmodel, type = 2, EfmVar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.