Type: Package
Title: ROBust INference for Covariate Adjustment in Randomized Clinical Trials
Version: 0.1.1
Date: 2025-03-30
Description: Performs robust estimation and inference when using covariate adjustment and/or covariate-adaptive randomization in randomized controlled trials. This package is trimmed to reduce the dependencies and validated to be used across industry. See "FDA's final guidance on covariate adjustment"https://www.regulations.gov/docket/FDA-2019-D-0934, Tsiatis (2008) <doi:10.1002/sim.3113>, Bugni et al. (2018) <doi:10.1080/01621459.2017.1375934>, Ye, Shao, Yi, and Zhao (2023)<doi:10.1080/01621459.2022.2049278>, Ye, Shao, and Yi (2022)<doi:10.1093/biomet/asab015>, Rosenblum and van der Laan (2010)<doi:10.2202/1557-4679.1138>, Wang et al. (2021)<doi:10.1080/01621459.2021.1981338>, Ye, Bannick, Yi, and Shao (2023)<doi:10.1080/24754269.2023.2205802>, and Bannick, Shao, Liu, Du, Yi, and Ye (2024)<doi:10.48550/arXiv.2306.10213>.
License: Apache License 2.0
URL: https://github.com/openpharma/RobinCar2/
BugReports: https://github.com/openpharma/RobinCar2/issues
Depends: R (≥ 3.6)
Imports: checkmate, numDeriv, MASS, sandwich, stats, utils
Suggests: knitr, rmarkdown, testthat (≥ 3.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
LazyData: true
RoxygenNote: 7.3.2
NeedsCompilation: no
Packaged: 2025-04-03 09:08:19 UTC; root
Author: Liming Li ORCID iD [aut, cre], Marlena Bannick ORCID iD [aut], Dong Xi [aut], Ting Ye [aut], Yanyao Yi [aut], Gregory Chen [ctb], Gilead Sciences, Inc. [cph, fnd], F. Hoffmann-La Roche AG [cph, fnd], Merck Sharp & Dohme, Inc. [cph, fnd], AstraZeneca plc [cph, fnd], Eli Lilly and Company [cph, fnd], The University of Washington [cph, fnd]
Maintainer: Liming Li <liming.li1@astrazeneca.com>
Repository: CRAN
Date/Publication: 2025-04-03 16:10:02 UTC

RobinCar2 Package

Description

RobinCar2 implements unbiased prediction and robust inference of variance of a fit in R.

Author(s)

Maintainer: Liming Li liming.li1@astrazeneca.com (ORCID)

Authors:

Other contributors:

See Also

Useful links:


Prediction Bias

Description

Obtain prediction bias within each stratum.

Usage

bias(residual, treatment, group_idx)

Arguments

residual

(numeric) residuals.

treatment

(factor) treatment.

group_idx

(character) stratum index.

Value

Numeric matrix of bias in each stratum.


Block Sum of a matrix

Description

Block Sum of a matrix

Usage

block_sum(x, n)

Dummy Trial Data with Permute-Block Randomization

Description

This dataset contains the dummy trial data with permute block randomization.

Usage

dummy_data

Format

A data frame with 600 rows and 7 columns:

id

The ID of the patients.

treatment

The treatment assignment, "pbo", "trt1" and "trt2"

s1

The first stratification variable, "a" and "b".

s2

The second stratification variable, "c" and "d".

covar

The covariate following normal distribution.

y

The continuous response.

y_b

The binary response.

Source

The data is generated by the create_dummy.R script.


Find Data in a Fit

Description

Find Data in a Fit

Usage

find_data(fit, ...)

Arguments

fit

A fit object.

...

Additional arguments.

Value

A data frame used in the fit.


Obtain Adjustment for Proportion of Treatment Assignment

Description

Obtain Adjustment for Proportion of Treatment Assignment

Usage

h_adjust_pi(pi)

Arguments

pi

(numeric) vector of proportions.

Value

Numeric matrix.


Contrast Functions and Jacobians

Description

Contrast Functions and Jacobians

Create Contrast of Pairs

Usage

h_diff(x, y)

h_jac_diff(x, y)

h_ratio(x, y)

h_jac_ratio(x, y)

h_odds_ratio(x, y)

h_jac_odds_ratio(x, y)

eff_jacob(f)

pairwise(levels, x = levels)

against_ref(levels, ref = levels[1], x = tail(levels, -1))

custom_contrast(levels, x, y)

Arguments

x

(vector) A vector of treatment levels.

y

(vector) A vector of treatment levels.

f

(function) Function with argument x and y to compute treatment effect.

levels

(character) Levels of the treatment.

ref

(string or int) Reference level.

Value

Vector of contrasts, or matrix of jacobians.

A list of contrast object with following elements:

Examples

h_diff(1:3, 4:6)
h_jac_ratio(1:3, 4:6)

Obtain Adjustment for Covariance Matrix

Description

Obtain Adjustment for Covariance Matrix

Usage

h_get_erb(resi, group_idx, trt, pi, randomization)

Arguments

resi

(numeric) vector of residuals.

group_idx

(list of integer) index for each groups.

trt

(factor) of treatment assignment.

pi

(numeric) proportion of treatment assignment.

randomization

(string) name of the randomization schema.


Extract Variable Names

Description

Extract Variable Names

Usage

h_get_vars(treatment)

Arguments

treatment

(string or formula) string name of the treatment, or a formula.

Details

Extract the formula elements, including treatment, schema and strata.

Value

A list of three elements, treatment, schema and strata.


Obtain the Jacobian matrix

Description

Obtain the Jacobian matrix

Usage

jac_mat(jac, pair)

Counterfactual Prediction

Description

Obtain counterfactual prediction of a fit.

Usage

predict_counterfactual(fit, treatment, data, vcov, vcov_args, ...)

Arguments

fit

fitted object.

treatment

(formula) formula of form treatment ~ strata(s).

data

(data.frame) raw dataset.

vcov

(function or character) variance function or name.

vcov_args

(list) additional arguments for variance function.

...

Additional arguments for methods.

Value

List of class prediction_cf containing following elements:


S3 Methods for prediction_cf

Description

S3 Methods for prediction_cf

Usage

## S3 method for class 'prediction_cf'
print(x, level = 0.95, ...)

Arguments

x

(prediction_cf)
the obtained counter-factual prediction object.

level

(number)
the significance level.

Value

No return value.

Functions


Randomization schema

Description

Randomization schema

Usage

randomization_schema

Format

An object of class data.frame with 3 rows and 2 columns.


Covariate adjusted glm model

Description

Covariate adjusted glm model

Usage

robin_glm(
  formula,
  data,
  treatment,
  contrast = "difference",
  contrast_jac = NULL,
  vcov = "vcovG",
  family = gaussian(),
  vcov_args = list(),
  pair,
  ...
)

Arguments

formula

(formula) A formula of analysis.

data

(data.frame) Input data frame.

treatment

(formula or character(1)) A formula of treatment assignment or assignment by stratification, or a string name of treatment assignment.

contrast

(function or character(1)) A function to calculate the treatment effect, or character of "difference", "risk_ratio", "odds_ratio" for default contrasts.

contrast_jac

(function) A function to calculate the Jacobian of the contrast function. Ignored if using default contrasts.

vcov

(function) A function to calculate the variance-covariance matrix of the treatment effect, including vcovHC and vcovG.

family

(family) A family object of the glm model.

vcov_args

(list) Additional arguments passed to vcov.

pair

Pairwise treatment comparison.

...

Additional arguments passed to glm or glm.nb.

Details

If family is MASS::negative.binomial(NA), the function will use MASS::glm.nb instead of glm.

Value

A treatment_effect object.

Examples

robin_glm(
  y ~ treatment * s1,
  data = dummy_data,
  treatment = treatment ~ s1, contrast = "difference"
)

Covariate adjusted lm model

Description

Covariate adjusted lm model

Usage

robin_lm(
  formula,
  data,
  treatment,
  vcov = "vcovG",
  vcov_args = list(),
  pair,
  ...
)

Arguments

formula

(formula) A formula of analysis.

data

(data.frame) Input data frame.

treatment

(formula or character(1)) A formula of treatment assignment or assignment by stratification, or a string name of treatment assignment.

vcov

(function) A function to calculate the variance-covariance matrix of the treatment effect, including vcovHC and vcovG. The default is 'vcovG'.

vcov_args

(list) Additional arguments passed to vcov.

pair

Pairwise treatment comparison.

...

Additional arguments passed to lm.

Value

A treatment_effect object.

Examples

robin_lm(
  y ~ treatment * s1,
  data = dummy_data,
  treatment = treatment ~ s1
)

Treatment Effect

Description

Obtain treatment effect and variance from counter-factual prediction

Usage

treatment_effect(
  object,
  pair = pairwise(names(object$estimate)),
  eff_measure,
  eff_jacobian = eff_jacob(eff_measure),
  ...
)

difference(object, ...)

risk_ratio(object, ...)

odds_ratio(object, ...)

Arguments

object

Object from which to obtain treatment effect.

pair

(contrast) Contrast choices.

eff_measure

(function) Treatment effect measurement function.

eff_jacobian

(function) Treatment effect jacobian function.

...

Additional arguments for variance.

Value

A list of treatment_effect object with following elements:


Update levels in a contrast pair

Description

Update levels in a contrast pair

Usage

update_levels(pair, levels)

ANHECOVA Covariance

Description

ANHECOVA Covariance

Usage

vcovG(x, decompose = TRUE, ...)

Arguments

x

(prediction_cf) Counter-factual prediction.

decompose

(flag) whether to use decompose method to calculate the variance.

...

Not used.

Value

Named covariance matrix.


Heteroskedasticity-consistent covariance matrix for predictions

Description

The heteroskedasticity-consistent covariance matrix for predictions is obtained with sandwich::vocvHC using sandwich method.

Usage

vcovHC(x, type = "HC3", ...)

Arguments

x

(prediction_cf) Counter-factual prediction.

type

(character) Type of HC covariance matrix.

...

Additional arguments for sandwich::vcovHC.

Value

Matrix of the heteroskedasticity-consistent covariance for the predictions.