diff --git a/R/robincar-tte.R b/R/robincar-tte.R index 8201104..f3ed78d 100644 --- a/R/robincar-tte.R +++ b/R/robincar-tte.R @@ -17,7 +17,7 @@ #' @param car_scheme Name of the type of covariate-adaptive randomization scheme. One of: "simple", "pocock-simon", "biased-coin", "permuted-block". #' @param ref_arm Reference arm of the treatment group, defaults to NULL, #' which results in using the first element of `unique(data[, treat_col])`. -#' @param p_trt Treatment allocation ratio for the reference arm. +#' @param p_trt Treatment allocation ratio for the treatment arm. #' @param adj_method Adjustment method (one of "CL", "CSL", or "coxscore") #' @param sparse_remove Remove sparse car_strata from calculation #' diff --git a/_pkgdown.yml b/_pkgdown.yml index 457d7ed..909c235 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -7,6 +7,7 @@ articles: - articles/Calibration-for-GLM-Models - articles/Robust-Testing-for-Time-to-Event-Data - articles/Mantel-Haenszel-Statistic + - articles/Family template: params: diff --git a/docs/articles/Family.html b/docs/articles/Family.html new file mode 100644 index 0000000..050fb1e --- /dev/null +++ b/docs/articles/Family.html @@ -0,0 +1,327 @@ + + + + + + + +RobinCar Family • RobinCar + + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +
+library(RobinCar)
+library(dplyr)
+
## 
+## Attaching package: 'dplyr'
+
## The following objects are masked from 'package:stats':
+## 
+##     filter, lag
+
## The following objects are masked from 'package:base':
+## 
+##     intersect, setdiff, setequal, union
+
+if (!require("remotes")) {
+  install.packages("remotes")
+}
+
## Loading required package: remotes
+
+remotes::install_github(
+  "openpharma/RobinCar2"
+)
+
## Using GitHub PAT from the git credential store.
+
## Skipping install of 'RobinCar2' from a github remote, the SHA1 (4f016471) has not changed since last install.
+##   Use `force = TRUE` to force installation
+ +
## 
+## Attaching package: 'RobinCar2'
+
## The following object is masked from 'package:base':
+## 
+##     table
+

This vignette is to accompany the Results section of the RobinCar +Family paper.

+

Data Manipulation

+

Creates continuous and binary outcomes, and does simple data +manipulations.

+
+# Data are from the speff2trial package
+data <- tibble(speff2trial::ACTG175)
+
+data <- data %>% mutate(
+  # Create continuous and binary outcomes
+  y_cont = cd420 - cd40,
+  y_bin = as.numeric((y_cont / cd40) > 0.5)
+) %>% filter(
+  # Focus on two treatment arms
+  arms %in% c("0", "1")
+) %>% mutate(
+  # Factor variables for treatment
+  # and stratification variable
+  arms = factor(arms),
+  strat = factor(strat)
+)
+

Linear Adjustment

+

The following shows a linear model with treatment-by-covariate +interactions, including strata as covariates, and using the four +covariates of weight, hemophilia status, and prior use of non-zidovudine +antiretroviral therapy. These specifications ensure that the covariate +adjustment has guaranteed efficiency gain (asymptotically).

+
+robin_lm(
+  y_cont ~ arms * (strat + wtkg + hemo + oprior), 
+  treatment = arms ~ pb(strat), 
+  data=data)
+
## Model        :  y_cont ~ arms * (strat + wtkg + hemo + oprior) 
+## Randomization:  arms ~ pb(strat)  ( Permuted-Block )
+## Variance Type:  vcovG 
+## Marginal Mean: 
+##   Estimate  Std.Err    2.5 %  97.5 %
+## 0 -16.9304   4.4915 -25.7336 -8.1273
+## 1  54.0531   6.2848  41.7352 66.3710
+## 
+## Contrast     :  h_diff
+##          Estimate Std.Err Z Value  Pr(>|z|)    
+## 1 v.s. 0   70.984   7.673  9.2511 < 2.2e-16 ***
+## ---
+## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+

Generalized Linear Models

+

For the binary outcome, we can use a logistic regression model +instead.

+
+robin_glm(
+  y_bin ~ arms * (wtkg + hemo + oprior),
+  treatment = arms ~ pb(strat),
+  family = binomial(link = "logit"),
+  contrast = "risk_ratio",
+  data = data
+)
+
## Warning in robin_glm(y_bin ~ arms * (wtkg + hemo + oprior), treatment = arms ~
+## : Consider using the log transformation `log_odds_ratio` and `log_risk_ratio`
+## to replace `odds_ratio` and `risk_ratio` to improve the performance of normal
+## approximation.
+
## Model        :  y_bin ~ arms * (wtkg + hemo + oprior) 
+## Randomization:  arms ~ pb(strat)  ( Permuted-Block )
+## Variance Type:  vcovG 
+## Marginal Mean: 
+##    Estimate   Std.Err     2.5 % 97.5 %
+## 0 0.0496651 0.0092998 0.0314378 0.0679
+## 1 0.1828118 0.0168988 0.1496908 0.2159
+## 
+## Contrast     :  risk_ratio
+##          Estimate Std.Err Z Value  Pr(>|z|)    
+## 1 v.s. 0  3.68089 0.76609  3.4994 0.0004662 ***
+## ---
+## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+

Rather than a linear contrast, we can instead estimate a risk ratio. +This does not change the marginal mean estimates, but it changes the +contrast estimates (and p-values).

+
+robin_glm(
+  y_bin ~ arms * (strat + wtkg + hemo + oprior),
+  treatment = arms ~ pb(strat),
+  family = binomial(link = "logit"),
+  contrast = "log_risk_ratio",
+  data=data
+)
+
## Model        :  y_bin ~ arms * (strat + wtkg + hemo + oprior) 
+## Randomization:  arms ~ pb(strat)  ( Permuted-Block )
+## Variance Type:  vcovG 
+## Marginal Mean: 
+##    Estimate   Std.Err     2.5 % 97.5 %
+## 0 0.0493622 0.0093041 0.0311264 0.0676
+## 1 0.1835664 0.0168944 0.1504539 0.2167
+## 
+## Contrast     :  log_risk_ratio
+##          Estimate Std.Err Z Value  Pr(>|z|)    
+## 1 v.s. 0  1.31339 0.20904  6.2831 3.318e-10 ***
+## ---
+## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+

Mantel-Haenszel

+

RobinCar includes functions for robust Mantel-Haenszel estimation. +Here we create a new variable that is the interaction of prior use of +non-zidovudine antiretroviral therapy and hemophilia status, and use +that as the stratification variable.

+

By default, the function uses the average treatment effect as the +estimand of interest. Specifying the estimand argument as “MH” does not +change the estimate, but it does change the standard error +calculation.

+

The MH function in RobinCar is only valid for simple +randomization.

+
+data <- data %>% mutate(
+  X=interaction(oprior, hemo)
+)
+
+robincar_mh(
+  data, "arms", "y_bin",
+  strata_cols=c("oprior", "hemo")
+)
+
## Treatment group contrasts based on ATE
+## Estimand: ATE
+## Stratified by oprior, hemo
+## SE calculated via modified Greenland's estimator
+## 
+## Contrasts:
+## # A tibble: 1 × 4
+##   contrast    estimate     se `pval (2-sided)`
+##   <chr[1d]>      <dbl>  <dbl>            <dbl>
+## 1 treat 1 - 0    0.134 0.0193         3.83e-12
+

Survival Analysis

+

For a survival outcome with right-censoring, we can use the RobinCar2 +function robin_surv to do a covariate-adjusted, stratified +log-rank test.

+
+surv <- robin_surv(
+  Surv(days, cens) ~ wtkg + oprior + hemo + strata(strat),
+  treatment = arms ~ pb(strat),
+  data = data
+)
+surv
+
## Model        : Surv(days, cens) ~ wtkg + oprior + hemo + strata(strat)
+## Randomization: arms ~ pb(strat) (Permuted-Block)
+## Stratification variables:  strat 
+## Covariates adjusted for: wtkg, oprior, hemo (including interactions with arms)
+## 
+## Contrast     : Covariate-adjusted Stratified Log Hazard Ratio
+## 
+##          Estimate  Std.Err Z Value  Pr(>|z|)    
+## 1 v.s. 0 -0.69673  0.12323 -5.6539 1.569e-08 ***
+## ---
+## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+## 
+## Test         : Covariate-adjusted Stratified Log-Rank
+## 
+##          Test Stat.  Pr(>|z|)    
+## 1 v.s. 0    -5.7736 7.757e-09 ***
+## ---
+## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+

You can use the table function to see the number of +events and number at-risk

+
+table(surv)
+
## Number of patients and events per stratum and treatment arm:
+##   strat arms Patients Events
+## 1     1    0      223     59
+## 2     1    1      213     34
+## 3     2    0       96     30
+## 4     2    1      106     20
+## 5     3    0      213     92
+## 6     3    1      203     49
+
+ + + +
+ + + + +
+ + + + + + + + diff --git a/docs/articles/index.html b/docs/articles/index.html index 6c2e5e0..5c0764e 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -43,6 +43,9 @@
  • Mantel-Haenszel-Statistic
  • +
  • + RobinCar Family +
  • Changelog @@ -71,6 +74,8 @@

    Articles

    Mantel-Haenszel-Statistic
    +
    RobinCar Family
    +
    diff --git a/docs/index.html b/docs/index.html index 5c70c42..4a7284e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -12,7 +12,7 @@ - +