Title: | Bayesian Evaluation, Analysis, and Simulation Software Tools for Trials |
---|---|
Description: | Bayesian dynamic borrowing with covariate adjustment via inverse probability weighting for simulations and data analyses in clinical trials. This makes it easy to use propensity score methods to balance covariate distributions between external and internal data. |
Authors: | Christina Fillmore [aut, cre] , Ben Arancibia [aut], Nate Bean [aut] , Abi Terry [aut], GlaxoSmithKline Research & Development Limited [cph, fnd], Trustees of Columbia University [cph] (R/stanmodels.R, configure, configure.win) |
Maintainer: | Christina Fillmore <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.2 |
Built: | 2025-01-30 15:24:53 UTC |
Source: | https://github.com/gsk-biostatistics/beastt |
Inverse Probability Weighted Bayesian Dynamic Borrowing
Stan Development Team (NA). RStan: the R interface to Stan. R package version 2.32.3. https://mc-stan.org
Calculate a posterior distribution that is beta (or a mixture of beta components). Only the relevant treatment arms from the internal dataset should be read in (e.g., only the control arm if constructing a posterior distribution for the control response rate).
calc_post_beta(internal_data, response, prior)
calc_post_beta(internal_data, response, prior)
internal_data |
A tibble of the internal data. |
response |
Name of response variable |
prior |
A distributional object corresponding to a beta distribution or a mixture distribution of beta components |
For a given arm of an internal trial (e.g., the control arm or an
active treatment arm) of size , suppose the response data are binary
such that
,
. The
posterior distribution for
is written as
where is the likelihood of the
response data from the internal arm and
is a prior
distribution on
(either a beta distribution or a mixture
distribution with an arbitrary number of beta components). The posterior
distribution for
is either a beta distribution or a mixture of
beta components depending on whether the prior is a single beta
distribution or a mixture distribution.
distributional object
library(dplyr) library(distributional) calc_post_beta(internal_data = filter(int_binary_df, trt == 1), response = y, prior = dist_beta(0.5, 0.5))
library(dplyr) library(distributional) calc_post_beta(internal_data = filter(int_binary_df, trt == 1), response = y, prior = dist_beta(0.5, 0.5))
Calculate a posterior distribution that is normal (or a mixture of normal components). Only the relevant treatment arms from the internal dataset should be read in (e.g., only the control arm if constructing a posterior distribution for the control mean).
calc_post_norm(internal_data, response, prior, internal_sd = NULL)
calc_post_norm(internal_data, response, prior, internal_sd = NULL)
internal_data |
A tibble of the internal data. |
response |
Name of response variable |
prior |
A distributional object corresponding to a normal distribution, a t distribution, or a mixture distribution of normal and/or t components |
internal_sd |
Standard deviation of internal response data if
assumed known. It can be left as |
For a given arm of an internal trial (e.g., the control arm or an
active treatment arm) of size , suppose the response data are normally
distributed such that
,
.
If
is assumed known, the posterior distribution for
is written as
where is the
likelihood of the response data from the internal arm and
is a prior distribution on
(either a normal distribution, a
distribution, or a mixture distribution with an arbitrary number of
normal and/or
components). Any
components of the prior for
are approximated with a mixture of two normal distributions.
If is unknown, the marginal posterior distribution for
is instead written as
In this case, the prior for is chosen to be
such that
becomes a non-standardized
distribution. This integrated likelihood
is then approximated with a mixture of two normal distributions.
If internal_sd
is supplied a positive value and prior
corresponds to a
single normal distribution, then the posterior distribution for
is a normal distribution. If
internal_sd = NULL
or if other types of prior
distributions are specified (e.g., mixture or t distribution), then the
posterior distribution is a mixture of normal distributions.
distributional object
library(distributional) library(dplyr) post_treated <- calc_post_norm(internal_data = filter(int_norm_df, trt == 1), response = y, prior = dist_normal(50, 10), internal_sd = 0.15)
library(distributional) library(dplyr) post_treated <- calc_post_norm(internal_data = filter(int_norm_df, trt == 1), response = y, prior = dist_normal(50, 10), internal_sd = 0.15)
Calculate a posterior distribution for the probability of surviving past a given analysis time(s) for time-to-event data with a Weibull likelihood. Only the relevant treatment arms from the internal dataset should be read in (e.g., only the control arm if constructing a posterior distribution for the control survival probability).
calc_post_weibull(internal_data, response, event, prior, analysis_time, ...)
calc_post_weibull(internal_data, response, event, prior, analysis_time, ...)
internal_data |
This can either be a propensity score object or a tibble of the internal data. |
response |
Name of response variable |
event |
Name of event indicator variable (1: event; 0: censored) |
prior |
A distributional object corresponding to a multivariate normal distribution or a mixture of 2 multivariate normals. The first element of the mean vector and the first row/column of covariance matrix correspond to the log-shape parameter, and the second element corresponds to the intercept (i.e., log-inverse-scale) parameter. |
analysis_time |
Vector of time(s) when survival probabilities will be calculated |
... |
rstan sampling option. This overrides any default options. For more
information, see |
For a given arm of an internal trial (e.g., the control arm or an
active treatment arm) of size , suppose the response data are time to event
such that
, where
. Define
where
is the intercept parameter of a Weibull
proportional hazards regression model. The posterior distribution for
is written as
where
is the likelihood of the response data from the internal arm with event indicator
and survival function
, and
is a prior
distribution on
(either a multivariate normal distribution or a
mixture of two multivariate normal distributions). Note that the posterior distribution
for
does not have a closed form, and thus MCMC samples
for
and
are drawn from the posterior. These MCMC
samples are used to construct samples from the posterior distribution
for the probability of surviving past the specified analysis time(s) for the
given arm.
To construct a posterior distribution for the treatment difference (i.e., the difference in survival probabilities at the specified analysis time), obtain MCMC samples from the posterior distributions for the survival probabilities under each arm and then subtract the control-arm samples from the treatment-arm samples.
stan posterior object
library(distributional) library(dplyr) library(rstan) mvn_prior <- dist_multivariate_normal( mu = list(c(0.3, -2.6)), sigma = list(matrix(c(1.5, 0.3, 0.3, 1.1), nrow = 2))) post_treated <- calc_post_weibull(filter(int_tte_df, trt == 1), response = y, event = event, prior = mvn_prior, analysis_time = 12, warmup = 5000, iter = 15000) # Extract MCMC samples of survival probabilities at time t=12 surv_prob_treated <- as.data.frame(extract(post_treated, pars = c("survProb")))[,1]
library(distributional) library(dplyr) library(rstan) mvn_prior <- dist_multivariate_normal( mu = list(c(0.3, -2.6)), sigma = list(matrix(c(1.5, 0.3, 0.3, 1.1), nrow = 2))) post_treated <- calc_post_weibull(filter(int_tte_df, trt == 1), response = y, event = event, prior = mvn_prior, analysis_time = 12, warmup = 5000, iter = 15000) # Extract MCMC samples of survival probabilities at time t=12 surv_prob_treated <- as.data.frame(extract(post_treated, pars = c("survProb")))[,1]
Calculate a (potentially inverse probability weighted) beta power prior for the control response rate using external control data.
calc_power_prior_beta(external_data, response, prior)
calc_power_prior_beta(external_data, response, prior)
external_data |
This can either be a |
response |
Name of response variable |
prior |
A beta distributional object that is the initial prior for the control response rate before the external control data are observed |
Weighted participant-level response data from the control arm of an
external study are incorporated into an inverse probability weighted (IPW)
power prior for the control response rate . When borrowing
information from an external control arm of size
, the components
of the IPW power prior for
are defined as follows:
with
weights
:
Defining the weights to equal 1 results in a
conventional beta power prior.
Beta power prior object
Other power prior:
calc_power_prior_norm()
,
calc_power_prior_weibull()
library(distributional) library(dplyr) # This function can be used directly on the data calc_power_prior_beta(external_data = ex_binary_df, response = y, prior = dist_beta(0.5, 0.5)) # Or this function can be used with a propensity score object ps_obj <- calc_prop_scr(internal_df = filter(int_binary_df, trt == 0), external_df = ex_binary_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) calc_power_prior_beta(ps_obj, response = y, prior = dist_beta(0.5, 0.5))
library(distributional) library(dplyr) # This function can be used directly on the data calc_power_prior_beta(external_data = ex_binary_df, response = y, prior = dist_beta(0.5, 0.5)) # Or this function can be used with a propensity score object ps_obj <- calc_prop_scr(internal_df = filter(int_binary_df, trt == 0), external_df = ex_binary_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) calc_power_prior_beta(ps_obj, response = y, prior = dist_beta(0.5, 0.5))
Calculate a (potentially inverse probability weighted) normal power prior using external data.
calc_power_prior_norm( external_data, response, prior = NULL, external_sd = NULL )
calc_power_prior_norm( external_data, response, prior = NULL, external_sd = NULL )
external_data |
This can either be a |
response |
Name of response variable |
prior |
Either |
external_sd |
Standard deviation of external response data if assumed
known. It can be left as |
Weighted participant-level response data from an external study are
incorporated into an inverse probability weighted (IPW) power prior for the
parameter of interest (e.g., the control mean if borrowing
from an external control arm). When borrowing information from an external
dataset of size
, the IPW likelihood of the external response
data
with weights
is defined as
The prior
argument should be either a distributional object with a family
type of normal
or NULL
, corresponding to the use of a normal initial
prior or an improper uniform initial prior (i.e., ), respectively.
The external_sd
argument can be a positive value if the external standard
deviation is assumed known or left as NULL
otherwise. If external_sd = NULL
, then prior
must be NULL
to indicate the use of an improper
uniform initial prior for , and an improper prior is defined
for the unknown external standard deviation such that
. The details of the IPW power prior for each
case are as follows:
external_sd = positive value
(
known):With
either a proper normal or an improper uniform initial prior, the IPW
weighted power prior for is a normal distribution.
external_sd = NULL
(
unknown):With improper
priors for both and
, the marginal IPW weighted
power prior for
after integrating over
is
a non-standardized
distribution.
Defining the weights to equal 1 results in a
conventional normal (or
) power prior if the external standard
deviation is known (unknown).
Normal power prior object
Other power prior:
calc_power_prior_beta()
,
calc_power_prior_weibull()
library(distributional) library(dplyr) # This function can be used directly on the data calc_power_prior_norm(ex_norm_df, response = y, prior = dist_normal(50, 10), external_sd = 0.15) # Or this function can be used with a propensity score object ps_obj <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) calc_power_prior_norm(ps_obj, response = y, prior = dist_normal(50, 10), external_sd = 0.15)
library(distributional) library(dplyr) # This function can be used directly on the data calc_power_prior_norm(ex_norm_df, response = y, prior = dist_normal(50, 10), external_sd = 0.15) # Or this function can be used with a propensity score object ps_obj <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) calc_power_prior_norm(ps_obj, response = y, prior = dist_normal(50, 10), external_sd = 0.15)
Calculate an approximate (potentially inverse probability weighted) multivariate normal power prior for the log-shape and log-inverse-scale parameters of a Weibull likelihood for external time-to-event control data.
calc_power_prior_weibull( external_data, response, event, intercept, shape, approximation = c("Laplace", "MCMC"), ... )
calc_power_prior_weibull( external_data, response, event, intercept, shape, approximation = c("Laplace", "MCMC"), ... )
external_data |
This can either be a |
response |
Name of response variable |
event |
Name of event indicator variable (1: event; 0: censored) |
intercept |
Normal distributional object that is the initial prior for the intercept (i.e., log-inverse-scale) parameter |
shape |
Integer value that is the scale of the half-normal prior for the shape parameter |
approximation |
Type of approximation to be used. Either |
... |
Arguments passed to |
Weighted participant-level response data from the control arm of an
external study are incorporated into an approximated inverse probability
weighted (IPW) power prior for the parameter vector
, where
is the intercept parameter of a Weibull proportional hazards regression model
and
and
are the Weibull shape and scale parameters,
respectively. When borrowing information from an external dataset of size
,
the IPW likelihood of the external response data
with
event indicators
and weights
is defined as
The initial priors for the intercept parameter and the shape parameter
are assumed to be normal and half-normal, respectively, which can
be defined using the
intercept
and shape
arguments.
The power prior for does not have a closed form, and
thus we approximate it via a bivariate normal distribution; i.e.,
.
If approximation = Laplace
, then is the mode vector
of the IPW power prior and
is the negative
inverse of the Hessian of the log IPW power prior evaluated at the mode. If
approximation = MCMC
, then MCMC samples are obtained from the IPW power prior,
and and
are the estimated mean vector and covariance matrix of these MCMC samples.
Note that the Laplace approximation method is faster due to its use of
optimization instead of MCMC sampling.
The first element of the mean vector and the first row/column of covariance
matrix correspond to the log-shape parameter (), and the
second element corresponds to the intercept (
, the log-inverse-scale)
parameter.
Multivariate Normal Distributional Object
Other power prior:
calc_power_prior_beta()
,
calc_power_prior_norm()
library(distributional) library(dplyr) # This function can be used directly on the data calc_power_prior_weibull(ex_tte_df, response = y, event = event, intercept = dist_normal(0, 10), shape = 50, approximation = "Laplace") # Or this function can be used with a propensity score object ps_obj <- calc_prop_scr(internal_df = filter(int_tte_df, trt == 0), external_df = ex_tte_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) calc_power_prior_weibull(ps_obj, response = y, event = event, intercept = dist_normal(0, 10), shape = 50, approximation = "Laplace")
library(distributional) library(dplyr) # This function can be used directly on the data calc_power_prior_weibull(ex_tte_df, response = y, event = event, intercept = dist_normal(0, 10), shape = 50, approximation = "Laplace") # Or this function can be used with a propensity score object ps_obj <- calc_prop_scr(internal_df = filter(int_tte_df, trt == 0), external_df = ex_tte_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) calc_power_prior_weibull(ps_obj, response = y, event = event, intercept = dist_normal(0, 10), shape = 50, approximation = "Laplace")
Calculate the propensity scores and ATT inverse probability weights for participants from internal and external datasets. Only the relevant treatment arms from each dataset should be read in (e.g., only the control arm from each dataset if creating a hybrid control arm).
calc_prop_scr(internal_df, external_df, id_col, model, ...)
calc_prop_scr(internal_df, external_df, id_col, model, ...)
internal_df |
Internal dataset with one row per subject and all the variables needed to run the model |
external_df |
External dataset with one row per subject and all the variables needed to run the model |
id_col |
Name of the column in both datasets used to identify each subject. It must be the same across datasets |
model |
Model used to calculate propensity scores |
... |
Optional arguments |
For the subset of participants in both the external and internal studies for which we want to balance the covariate distributions (e.g., external control and internal control participants if constructing a hybrid control arm), we define a study-inclusion propensity score for each participant as
where denotes a vector of baseline covariates for the
th
participant and
denotes the indicator that the participant is
enrolled in the internal trial (
if internal,
if external). The estimated propensity score
is obtained
using logistic regression.
An ATT inverse probability weight is calculated for each individual as
In a weighted estimator, data from participants in the external study
are given a weight of whereas data
from participants in the internal trial are given a weight of 1.
prop_scr_obj
object, with the internal and the external data and
the propensity score and inverse probability weight calculated for each
subject.
# This can be used for both continuous and binary data library(dplyr) # Continuous calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) # Binary calc_prop_scr(internal_df = filter(int_binary_df, trt == 0), external_df = ex_binary_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4)
# This can be used for both continuous and binary data library(dplyr) # Continuous calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) # Binary calc_prop_scr(internal_df = filter(int_binary_df, trt == 0), external_df = ex_binary_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4)
This is a simulated dataset used to illustrate Bayesian dynamic borrowing in the case when borrowing from an external control arm with a binary endpoint, where the baseline covariate distributions of the internal and external data are balanced via inverse probability weighting.
ex_binary_df
ex_binary_df
ex_binary_df
A data frame with 150 rows and 6 columns:
Unique subject ID
Covariate 1, which is normally distributed around 65 with a SD of 10
Covariate 2, which is binary (0 vs. 1) with about 30% of participants having level 1
Covariate 3, which is binary (0 vs. 1) with about 40% of participants having level 1
Covariate 4, which is binary (0 vs. 1) with about 50% of participants having level 1
Response, which is binary (0 vs. 1)
This is a simulated dataset used to illustrate Bayesian dynamic borrowing in the case when borrowing from an external control arm with a normal endpoint, where the baseline covariate distributions of the internal and external data are balanced via inverse probability weighting.
ex_norm_df
ex_norm_df
ex_norm_df
A data frame with 150 rows and 6 columns:
Unique subject ID
Covariate 1, which is normally distributed around 50 with a SD of 10
Covariate 2, which is binary (0 vs. 1) with about 20% of participants having level 1
Covariate 3, which is binary (0 vs. 1) with about 60% of participants having level 1
Covariate 4, which is binary (0 vs. 1) with about 30% of participants having level 1
Response, which is normally distributed with a SD of 0.15
This is a simulated dataset used to illustrate Bayesian dynamic borrowing in the case when borrowing from an external control arm with a time-to-event endpoint, where the baseline covariate distributions of the internal and external data are balanced via inverse probability weighting.
ex_tte_df
ex_tte_df
ex_tte_df
A data frame with 150 rows and 9 columns:
Unique subject ID
Response (observed time at which the participant either had an event or was censored)
Enrollment time
Time from study start
Event indicator (1: event; 0: censored)
Covariate 1, which is normally distributed around 65 with a SD of 10
Covariate 2, which is binary (0 vs. 1) with about 30% of participants having level 1
Covariate 3, which is binary (0 vs. 1) with about 40% of participants having level 1
Covariate 4, which is binary (0 vs. 1) with about 50% of participants having level 1
This is a simulated dataset used to illustrate Bayesian dynamic borrowing in the case when borrowing from an external control arm with a binary endpoint, where the baseline covariate distributions of the internal and external data are balanced via inverse probability weighting.
int_binary_df
int_binary_df
int_binary_df
A data frame with 160 rows and 7 columns:
Unique subject ID
Covariate 1, which is normally distributed around 62 with an sd of 8
Covariate 2, which is binary (0 vs. 1) with about 40% of participants having level 1
Covariate 3, which is binary (0 vs. 1) with about 40% of participants having level 1
Covariate 4, which is binary (0 vs. 1) with about 60% of participants having level 1
Treatment indicator, where 0 = control and 1 = active treatment
Response, which is binary (0 vs. 1)
This is a simulated dataset used to illustrate Bayesian dynamic borrowing in the case when borrowing from an external control arm with a normal endpoint, where the baseline covariate distributions of the internal and external data are balanced via inverse probability weighting.
int_norm_df
int_norm_df
int_norm_df
A data frame with 120 rows and 7 columns:
Unique subject ID
Covariate 1, which is normally distributed around 55 with a SD of 8
Covariate 2, which is binary (0 vs. 1) with about 30% of participants having level 1
Covariate 3, which is binary (0 vs. 1) with about 50% of participants having level 1
Covariate 4, which is binary (0 vs. 1) with about 30% of participants having level 1
Treatment indicator, where 0 = control and 1 = active treatment
Response, which is normally distributed with a SD of 0.15
This is a simulated dataset used to illustrate Bayesian dynamic borrowing in the case when borrowing from an external control arm with a time-to-event endpoint, where the baseline covariate distributions of the internal and external data are balanced via inverse probability weighting.
int_tte_df
int_tte_df
int_tte_df
A data frame with 160 rows and 10 columns:
Unique subject ID
Response (observed time at which the participant either had an event or was censored)
Enrollment time
Time from study start
Event indicator (1: event; 0: censored)
Treatment indicator, where 0 = control and 1 = active treatment
Covariate 1, which is normally distributed around 62 with a SD of 8
Covariate 2, which is binary (0 vs. 1) with about 40% of participants having level 1
Covariate 3, which is binary (0 vs. 1) with about 40% of participants having level 1
Covariate 4, which is binary (0 vs. 1) with about 60% of participants having level 1
Test If Propensity Score Object
is_prop_scr(x)
is_prop_scr(x)
x |
Object to test |
Boolean
library(dplyr) x <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) is_prop_scr(x)
library(dplyr) x <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) is_prop_scr(x)
Extract Means of Mixture Components
mix_means(x)
mix_means(x)
x |
A mixture distributional object |
If a distributional object that is a mixture of two or more normal distributions is read in, the function will return a numeric object with the means of each normal component. If the distributional object is a mixture of two or more multivariate normal distributions, the function will return a list with the mean vectors of each multivariate normal component.
numeric or list object
library(distributional) mix_norm <- dist_mixture(comp1 = dist_normal(1, 10), comp2 = dist_normal(1.5, 12), weights = c(.5, .5)) mix_means(mix_norm)
library(distributional) mix_norm <- dist_mixture(comp1 = dist_normal(1, 10), comp2 = dist_normal(1.5, 12), weights = c(.5, .5)) mix_means(mix_norm)
Extract Standard Deviations of Mixture Components
mix_sigmas(x)
mix_sigmas(x)
x |
A mixture distributional object |
If a distributional object that is a mixture of two or more normal distributions is read in, the function will return a numeric object with the standard deviations of each normal component. If the distributional object is a mixture of two or more multivariate normal distributions, the function will return a list with the covariance matrices of each multivariate normal component.
numeric or list object
library(distributional) mix_norm <- dist_mixture(comp1 = dist_normal(1, 10), comp2 = dist_normal(1.5, 12), weights = c(.5, .5)) mix_sigmas(mix_norm)
library(distributional) mix_norm <- dist_mixture(comp1 = dist_normal(1, 10), comp2 = dist_normal(1.5, 12), weights = c(.5, .5)) mix_sigmas(mix_norm)
Plot Distribution
plot_dist(...)
plot_dist(...)
... |
Distributional object(s) to plot. When passing multiple objects naming them will change the labels in the plot, else they will use the distributional format |
ggplot object that is the density of the provided distribution
library(distributional) plot_dist(dist_normal(0, 1)) #Plotting Multiple plot_dist(dist_normal(0, 1), dist_normal(10, 5)) plot_dist('Prior' = dist_normal(0, 1), 'Posterior' = dist_normal(10, 5))
library(distributional) plot_dist(dist_normal(0, 1)) #Plotting Multiple plot_dist(dist_normal(0, 1), dist_normal(10, 5)) plot_dist('Prior' = dist_normal(0, 1), 'Posterior' = dist_normal(10, 5))
Plot overlapping density curves of the propensity scores for both the internal and external participants, or plot external IPWs.
prop_scr_dens( x, variable = c("propensity score", "ps", "inverse probability weight", "ipw"), ... )
prop_scr_dens( x, variable = c("propensity score", "ps", "inverse probability weight", "ipw"), ... )
x |
Propensity score object |
variable |
Variable to plot. It must be either a propensity score ("ps" or "propensity score") or inverse probability weight ("ipw" or "inverse probability weight") |
... |
Optional arguments for |
ggplot object
library(dplyr) ps_obj <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) # Plotting the Propensity Scores prop_scr_dens(ps_obj) # Or plotting the inverse probability weights prop_scr_dens(ps_obj, variable = "ipw")
library(dplyr) ps_obj <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) # Plotting the Propensity Scores prop_scr_dens(ps_obj) # Or plotting the inverse probability weights prop_scr_dens(ps_obj, variable = "ipw")
Plot overlapping histograms of the propensity scores for both the internal and external participants, or plot external IPWs.
prop_scr_hist( x, variable = c("propensity score", "ps", "inverse probability weight", "ipw"), ... )
prop_scr_hist( x, variable = c("propensity score", "ps", "inverse probability weight", "ipw"), ... )
x |
Propensity score object |
variable |
Variable to plot. It must be either a propensity score ("ps" or "propensity score") or inverse probability weight ("ipw" or "inverse probability weight") |
... |
Optional arguments for |
ggplot object
library(dplyr) ps_obj <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) # Plotting the Propensity Scores prop_scr_hist(ps_obj) # Or plotting the inverse probability weights prop_scr_hist(ps_obj, variable = "ipw")
library(dplyr) ps_obj <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) # Plotting the Propensity Scores prop_scr_hist(ps_obj) # Or plotting the inverse probability weights prop_scr_hist(ps_obj, variable = "ipw")
Plot the unadjusted and IPW-adjusted absolute standardized mean differences for each covariate.
prop_scr_love(x, reference_line = NULL, ...)
prop_scr_love(x, reference_line = NULL, ...)
x |
Propensity score object |
reference_line |
Numeric value of where along the x-axis the vertical reference line should be placed |
... |
Optional options for |
ggplot object
library(dplyr) ps_obj <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) # Plotting the Propensity Scores prop_scr_love(ps_obj, reference_line = 0.1)
library(dplyr) ps_obj <- calc_prop_scr(internal_df = filter(int_norm_df, trt == 0), external_df = ex_norm_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) # Plotting the Propensity Scores prop_scr_love(ps_obj, reference_line = 0.1)
Adds vague normal component, where the level of vagueness is controlled by
the n
parameter
robustify_mvnorm(prior, n, weights = c(0.5, 0.5))
robustify_mvnorm(prior, n, weights = c(0.5, 0.5))
prior |
Multivariate Normal distributional object |
n |
Number of theoretical participants (or events, for time-to-event data) |
weights |
Vector of weights, where the first number corresponds to the informative component and the second is the vague |
In cases with a time-to-event endpoint, a robust mixture prior can be
created by adding a vague multivariate normal component to any multivariate
normal prior with mean vector and covariance matrix
. The vague component is calculated to have the
same mean vector
and covariance matrix equal to
, where
n
is the specified number of
theoretical events.
mixture distribution
library(distributional) robustify_mvnorm( dist_multivariate_normal(mu = list(c(1, 0)), sigma = list(c(10, 5))), n = 15)
library(distributional) robustify_mvnorm( dist_multivariate_normal(mu = list(c(1, 0)), sigma = list(c(10, 5))), n = 15)
Adds vague normal component, where the level of vagueness is controlled by
the n
parameter
robustify_norm(prior, n, weights = c(0.5, 0.5))
robustify_norm(prior, n, weights = c(0.5, 0.5))
prior |
Normal or Multivariate Normal distributional object |
n |
Number of theoretical participants (or events, for time-to-event data) |
weights |
Vector of weights, where the first number corresponds to the informative component and the second is the vague |
In cases with a normal endpoint, a robust mixture prior can be created by
adding a vague normal component to any normal prior with mean
and variance
.The vague component is calculated to have the
same mean
and variance equal to
, where
n
is the specified number of theoretical participants. If robustifying a normal
power prior that was calculated from external control data and n
is defined as
the number of external control participants, and the vague component would
then correspond to one external control participant's worth of data.
mixture distribution
library(distributional) robustify_norm(dist_normal(0,1), n = 15)
library(distributional) robustify_norm(dist_normal(0,1), n = 15)
Tidy a(n) prop_scr object
## S3 method for class 'prop_scr' tidy(x, ...)
## S3 method for class 'prop_scr' tidy(x, ...)
x |
a |
... |
Unused, included for generic consistency only. |
A tidy tibble::tibble()
summarizing the results of the propensity
score weighting. The tibble will have the id column of the external data,
an internal
column to indicate all the data is external, a ps
column
with the propensity scores and a weight
column with the inverse
probability weights
library(dplyr) ps_obj <- calc_prop_scr(internal_df = filter(int_binary_df, trt == 0), external_df = ex_binary_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) tidy(ps_obj)
library(dplyr) ps_obj <- calc_prop_scr(internal_df = filter(int_binary_df, trt == 0), external_df = ex_binary_df, id_col = subjid, model = ~ cov1 + cov2 + cov3 + cov4) tidy(ps_obj)