| Title: | Sensitivity Analysis for Covariates Observed in Two-Phase Samples |
|---|---|
| Description: | Provides a structured method-comparison sensitivity-analysis workflow for linear regression when important continuous adjustment covariates are observed only in a Phase-2 subsample. Implements naive analysis, complete-case analysis, fully conditional specification multiple imputation, joint-model multiple imputation, inverse probability weighting, and augmented inverse probability weighting, with standardized tables, diagnostics, and publication-style forest plots. Methodological background is provided by Little and Rubin (2019) <doi:10.1002/9781119482260> for general missing-data methods, White and Carlin (2010) <doi:10.1002/sim.3944> for complete-case analysis with missing covariates, White, Royston and Wood (2011) <doi:10.1002/sim.4067> and van Buuren and Groothuis-Oudshoorn (2011) <doi:10.18637/jss.v045.i03> for chained-equations multiple imputation, Quartagno, Grund and Carpenter (2019) <doi:10.32614/RJ-2019-028> for joint-model multiple imputation, Robins, Rotnitzky and Zhao (1994) <doi:10.1080/01621459.1994.10476818> for inverse-probability weighting with missing regressors, and Bang and Robins (2005) <doi:10.1111/j.1541-0420.2005.00377.x> for doubly robust estimation. |
| Authors: | Rophence Ojiambo [aut, cre] (ORCID: <https://orcid.org/0000-0002-6798-9066>), Jemar Bather [aut] (ORCID: <https://orcid.org/0000-0002-0285-3678>) |
| Maintainer: | Rophence Ojiambo <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-23 10:04:47 UTC |
| Source: | https://github.com/rophenceojiambo/twophasesens |
Returns method-level information from a twophase_sensitivity() fit. The
default view contains analysis status, sample-size information, stochastic
settings, multiple-imputation settings, and available IPW/AIPW weight
diagnostics. More focused views can be requested with type.
diagnostics(x, ...) ## S3 method for class 'twophase_sensitivity' diagnostics( x, type = c("all", "status", "weights", "mi"), outcome = NULL, method = NULL, ... )diagnostics(x, ...) ## S3 method for class 'twophase_sensitivity' diagnostics( x, type = c("all", "status", "weights", "mi"), outcome = NULL, method = NULL, ... )
x |
An object. |
... |
Additional arguments passed to methods. |
type |
Diagnostic view. One of |
outcome |
Optional character vector selecting one or more outcomes. |
method |
Optional character vector selecting one or more methods.
Method names are normalized in the same way as in
|
The function reports diagnostics but does not automatically label values as acceptable or unacceptable. Interpretation of weight variability, effective sample size, imputation behavior, and method failures should be based on the study design and scientific context.
A data frame with one row per selected outcome-method combination.
dat <- twophase_example_data(n = 200, seed = 2026) fit <- twophase_sensitivity( data = dat, outcome = "outcome1", exposure = "exposure", covariates = c("age", "sex"), phase2_covariates = c("marker1", "marker2", "marker3"), phase2 = "phase2", methods = c("naive", "cca", "ipw"), seed = 1001 ) diagnostics(fit)dat <- twophase_example_data(n = 200, seed = 2026) fit <- twophase_sensitivity( data = dat, outcome = "outcome1", exposure = "exposure", covariates = c("age", "sex"), phase2_covariates = c("marker1", "marker2", "marker3"), phase2 = "phase2", methods = c("naive", "cca", "ipw"), seed = 1001 ) diagnostics(fit)
Creates a publication-style forest plot from a twophase_sensitivity()
object. Each method is shown with a method-specific color and symbol,
horizontal confidence interval, and optional right-side text columns for the
formatted coefficient/CI and p value. With multiple outcomes, outcomes are
shown in separate facets.
plot_sensitivity( x, outcome = NULL, method = NULL, outcome_labels = NULL, method_labels = NULL, reference_line = 0, facet_scales = c("free_x", "fixed"), x_label = NULL, estimate_label = "Coefficient", title = NULL, annotate = TRUE, estimate_digits = 3L, p_digits = 3L ) ## S3 method for class 'twophase_sensitivity' plot(x, ...)plot_sensitivity( x, outcome = NULL, method = NULL, outcome_labels = NULL, method_labels = NULL, reference_line = 0, facet_scales = c("free_x", "fixed"), x_label = NULL, estimate_label = "Coefficient", title = NULL, annotate = TRUE, estimate_digits = 3L, p_digits = 3L ) ## S3 method for class 'twophase_sensitivity' plot(x, ...)
x |
A |
outcome |
Optional character vector selecting one or more outcomes. |
method |
Optional character vector selecting one or more methods. |
outcome_labels |
Optional character vector used to relabel outcomes. Supply either a named vector whose names are the outcome variable names or an unnamed vector in the same order as the selected outcomes. |
method_labels |
Optional named character vector used to relabel methods. |
reference_line |
Numeric scalar giving the vertical reference line.
Use |
facet_scales |
Facet x-axis scaling for multiple outcomes:
|
x_label |
Optional x-axis label. If |
estimate_label |
Label used for the numeric estimate column. The default
is |
title |
Optional overall plot title. Outcome labels are shown in facet strips, including when a single outcome is plotted. |
annotate |
Logical; if |
estimate_digits |
Number of digits used in the coefficient and confidence-interval annotation. The default is 3. |
p_digits |
Number of digits used in the p-value annotation. |
... |
Arguments passed to |
A ggplot object.
dat <- twophase_example_data(n = 200, seed = 2026) fit <- twophase_sensitivity( data = dat, outcome = "outcome1", exposure = "exposure", covariates = c("age", "sex"), phase2_covariates = c("marker1", "marker2", "marker3"), phase2 = "phase2", methods = c("naive", "cca", "ipw"), seed = 1001 ) plot_sensitivity(fit, outcome_labels = c(outcome1 = "Outcome 1"))dat <- twophase_example_data(n = 200, seed = 2026) fit <- twophase_sensitivity( data = dat, outcome = "outcome1", exposure = "exposure", covariates = c("age", "sex"), phase2_covariates = c("marker1", "marker2", "marker3"), phase2 = "phase2", methods = c("naive", "cca", "ipw"), seed = 1001 ) plot_sensitivity(fit, outcome_labels = c(outcome1 = "Outcome 1"))
Formats method-comparison results from twophase_sensitivity() with methods
in rows and one group of columns per outcome. By default, the function
returns a gtsummary object with outcome spanning headers. A plain data
frame can be requested for downstream custom formatting.
tbl_sensitivity( x, estimate_digits = 3L, p_digits = 3L, include_se = FALSE, method_labels = NULL, outcome_labels = NULL, caption = NULL, output = c("gtsummary", "data.frame") )tbl_sensitivity( x, estimate_digits = 3L, p_digits = 3L, include_se = FALSE, method_labels = NULL, outcome_labels = NULL, caption = NULL, output = c("gtsummary", "data.frame") )
x |
A |
estimate_digits |
Number of digits for estimates and confidence limits. The default is 3. |
p_digits |
Number of digits for p values. |
include_se |
Logical; include a separate standard-error column for each outcome. |
method_labels |
Optional named character vector used to relabel methods.
Names should be package method labels such as |
outcome_labels |
Optional character vector used to relabel outcomes.
Supply either a named vector whose names are the outcome variable names or
an unnamed vector in the same order as |
caption |
Optional table caption. Markdown is supported for
|
output |
Output type: |
A gtsummary object by default, or a formatted data frame when
output = "data.frame".
dat <- twophase_example_data(n = 200, seed = 2026) fit <- twophase_sensitivity( data = dat, outcome = "outcome1", exposure = "exposure", covariates = c("age", "sex"), phase2_covariates = c("marker1", "marker2", "marker3"), phase2 = "phase2", methods = c("naive", "cca", "ipw"), seed = 1001 ) tbl_sensitivity(fit, output = "data.frame")dat <- twophase_example_data(n = 200, seed = 2026) fit <- twophase_sensitivity( data = dat, outcome = "outcome1", exposure = "exposure", covariates = c("age", "sex"), phase2_covariates = c("marker1", "marker2", "marker3"), phase2 = "phase2", methods = c("naive", "cca", "ipw"), seed = 1001 ) tbl_sensitivity(fit, output = "data.frame")
Creates a small reproducible dataset for examples, teaching, and package
documentation. Phase-1 variables are fully observed, while the continuous
Phase-2 covariates are observed as a complete block only when phase2 = 1.
twophase_example_data(n = 300L, seed = 2026L)twophase_example_data(n = 300L, seed = 2026L)
n |
Number of observations. |
seed |
Non-negative integer seed used only while generating the example data. The caller's pre-existing global random-number state is restored. |
The generated data are synthetic and are not derived from MIDUS or any other participant-level study data.
A data frame containing two continuous outcomes, one continuous exposure, two Phase-1 covariates, three continuous Phase-2 covariates, and a binary Phase-2 indicator.
dat <- twophase_example_data(n = 200, seed = 2026) head(dat) table(dat$phase2)dat <- twophase_example_data(n = 200, seed = 2026) head(dat) table(dat$phase2)
Runs a prespecified set of analytic approaches for a linear-regression exposure coefficient when a block of continuous adjustment covariates is observed only in a Phase-2 subsample.
twophase_sensitivity( data, outcome, exposure, covariates = character(), phase2_covariates, phase2, methods = c("naive", "cca", "fcs_mi", "jm_mi", "ipw", "aipw"), n_imputations = .twophasesens_defaults$n_imputations, mice_maxit = .twophasesens_defaults$mice_maxit, jomo_nburn = .twophasesens_defaults$jomo_nburn, jomo_nbetween = .twophasesens_defaults$jomo_nbetween, seed = NULL, conf_level = .twophasesens_defaults$conf_level )twophase_sensitivity( data, outcome, exposure, covariates = character(), phase2_covariates, phase2, methods = c("naive", "cca", "fcs_mi", "jm_mi", "ipw", "aipw"), n_imputations = .twophasesens_defaults$n_imputations, mice_maxit = .twophasesens_defaults$mice_maxit, jomo_nburn = .twophasesens_defaults$jomo_nburn, jomo_nbetween = .twophasesens_defaults$jomo_nbetween, seed = NULL, conf_level = .twophasesens_defaults$conf_level )
data |
A data frame. |
outcome |
Character vector naming one or more continuous outcomes. A single outcome is fully supported. Multiple outcomes are analyzed separately using the same exposure, covariates, Phase-2 variables, and requested methods. |
exposure |
Character scalar naming the numeric primary exposure. |
covariates |
Character vector naming fully observed Phase-1 covariates. |
phase2_covariates |
Character vector naming continuous Phase-2 covariates. |
phase2 |
Character scalar naming the 0/1 Phase-2 indicator. |
methods |
Methods to run. Defaults to all six validated approaches. |
n_imputations |
Number of imputations for FCS-MI and JM-MI. |
mice_maxit |
Maximum FCS iterations. |
jomo_nburn |
JM-MI burn-in iterations. |
jomo_nbetween |
JM-MI iterations between saved imputations. |
seed |
Optional random-number seed. Supply either one non-negative integer, which is expanded sequentially across outcomes, or one integer per outcome. A named vector may be supplied using the outcome names. The previous global RNG state is restored after each outcome analysis. |
conf_level |
Confidence level for intervals. |
An object of class twophase_sensitivity.
dat <- twophase_example_data(n = 200, seed = 2026) fit <- twophase_sensitivity( data = dat, outcome = "outcome1", exposure = "exposure", covariates = c("age", "sex"), phase2_covariates = c("marker1", "marker2", "marker3"), phase2 = "phase2", methods = c("naive", "cca", "ipw"), seed = 1001 ) fitdat <- twophase_example_data(n = 200, seed = 2026) fit <- twophase_sensitivity( data = dat, outcome = "outcome1", exposure = "exposure", covariates = c("age", "sex"), phase2_covariates = c("marker1", "marker2", "marker3"), phase2 = "phase2", methods = c("naive", "cca", "ipw"), seed = 1001 ) fit