PStrata: Principal Stratification Analysis for Data with...

View source: R/PStrata.R

PStrataR Documentation

Principal Stratification Analysis for Data with Post-Randomization Intervention

Description

Perform pincipal stratification analysis when there are confounding variables after randomization

Usage

PStrata(
  PSobject = NULL,
  S.formula,
  Y.formula,
  Y.family,
  data = NULL,
  strata = NULL,
  ER = NULL,
  prior_intercept = prior_flat(),
  prior_coefficient = prior_normal(),
  prior_sigma = prior_inv_gamma(),
  prior_alpha = prior_inv_gamma(),
  prior_lambda = prior_inv_gamma(),
  prior_theta = prior_normal(),
  survival.time.points = 50,
  filename = NULL,
  ...
)

Arguments

PSobject

an object of class PSObject. If left blank, the object is constructed using the following arguments. See PSObject for details.

S.formula, Y.formula

an object of class "PSFormula" (or an object of class "formula" that can be coerced to that class with data provided) specifying the model for principal stratum and outcome respectively. See PSFormula for details.

Y.family

an object of class "family": specifying the parametric family of the model for the response and the link function. See the documentation for glm for details on how such model fitting takes place. Supported families and corresponding link functions are presented in 'Details' below.

data

(optional) a data frame object. This is required when either S.formula or Y.formula is a formula object, to coerce it into a PSFormula object. When this happens, the data frame should contain all of the variables with names given in S.formula or Y.formula.

strata, ER

arguments to define the principal strata. See PStrataInfo for details.

Alternatively, one can pass an object of class PStrataInfo to strata, and ER will be ignored.

prior_intercept, prior_coefficient, prior_sigma, prior_alpha, prior_lambda, prior_theta

prior distribution for corresponding parameters in the model.

survival.time.points

a vector of time points at which the estimated survival probability is evaluated (only used when the type of outcome is survival), or an integer specifying the number of time points to be chosen. By default, the time points are chosen with equal distance from 0 to the 90% quantile of the observed outcome.

filename

(optional) string. If not NULL, the stan file will be saved via cat in a text file named after the string supplied.

...

additional parameters to be passed into PSSample.

Value

An object of class PStrata or PStrata_survival, which is a list containing

PSobject

An object of PSObject.

post_samples

An object of class rstan::stanfit returned by Stan.

Examples

require(abind)
PSobj <- PSObject(
  S.formula = Z + D ~ 1,
  Y.formula = Y ~ 1,
  Y.family = gaussian("identity"),
  data = sim_data_normal,
  strata = c(n = "00*", c = "01", a = "11*")
)

PStrata(PSobj, cores = 2, chains = 2, iter = 200)

# Another example for survival data
PSobj <- PSObject(
  S.formula = Z + D ~ 1,
  Y.formula = Y + delta ~ 1,
  Y.family = survival("Cox"),
  data = sim_data_Cox,
  strata = c(`never-taker` = "00*", complier = "01", `always-taker` = "11*")
)

PStrata(PSobj, cores = 2, chains = 2, iter = 200)


PStrata documentation built on May 29, 2024, 8:17 a.m.