diff --git a/docs/articles/Family.html b/docs/articles/Family.html index 86dfb6a..917cbdf 100644 --- a/docs/articles/Family.html +++ b/docs/articles/Family.html @@ -33,7 +33,7 @@ @@ -100,26 +100,21 @@
##
-## Attaching package: 'RobinCar2'
-## The following object is masked from 'package:base':
-##
-## table
-
-##
-## 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
+library(RobinCar2)
+library(dplyr)
+library(SuperLearner)
+library(ranger)
+library(xgboost)
+library(glmnet)
+Data Manipulation
-Creates continuous and binary outcomes, and does simple data -manipulations.
-+We use data from the Juraska et al. (2022) R package, which comes +from a study of nucleoside treatment regimens for individuals with HIV-1 +(Hammer et al. 1996) called the AIDS Clinical Trials Group Study 175. +This trial had stratified permuted block randomization.
+# Data are from the speff2trial package data <- tibble(speff2trial::ACTG175) @@ -142,7 +137,7 @@2026-01-19
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), @@ -162,36 +157,10 @@2026-01-19
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1Generalized 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 ' ' 1Rather 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).
-+instead. Rather than a linear contrast, we could instead estimate a log +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), @@ -223,7 +192,7 @@2026-01-19
calculation.The MH function in RobinCar is only valid for simple randomization.
-diff --git a/vignettes/articles/Family.Rmd b/vignettes/articles/Family.Rmd index 1f5cb38..5354c9c 100644 --- a/vignettes/articles/Family.Rmd +++ b/vignettes/articles/Family.Rmd @@ -13,7 +13,7 @@ This vignette accompanies the Results section of the RobinCar Family paper. knitr::opts_chunk$set(echo = TRUE) ``` -```{r} +```{r, results='hide', message=FALSE, warning=FALSE} library(RobinCar) library(RobinCar2) library(dplyr)+diff --git a/docs/articles/index.html b/docs/articles/index.html index e3d59bf..e11f0cc 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -17,7 +17,7 @@data <- data %>% mutate( X=interaction(oprior, hemo) ) @@ -246,7 +215,7 @@2026-01-19
For a survival outcome with right-censoring, we can use the RobinCar2 function
-robin_survto do a covariate-adjusted, stratified log-rank test.++ +surv <- robin_surv( Surv(days, cens) ~ wtkg + oprior + hemo + strat, treatment = arms ~ pb(strat), @@ -272,17 +241,134 @@2026-01-19
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1You can use the
-tablefunction to see the number of events and number at-risk++table(surv)+## Number of patients and events per treatment arm: ## arms Patients Events ## 1 0 532 181 ## 2 1 522 103+Case Study 2: RCT of Indomethacin for Post-ERCP Pancreatitis +
+Data Manipulation
+This case study uses a different dataset, +
+ +medicaldata::indo_rct, which was a randomized trial of +rectal indomethacin to prevent post-ERCP pancreatitis (Elmunzer, +Higgins, et al. 2012). This study used simple randomization stratified +by study site (this is not the same as stratified permuted block +randomization in the first example).+## Loading required package: medicaldata++data2 <- medicaldata::indo_rct %>% + mutate( + outcome2=as.numeric(outcome)-1 + ) %>% + select( + -c(outcome, status, type, bleed) + )First fit a really simple logistic regression working model only +adjusting for site, and a risk difference as our contrast of +interest.
+++robin_glm( + outcome2 ~ rx * site, + treatment = rx ~ sr(1), + data=data2, + family=binomial(link="logit"), + contrast = "difference" +)+## Model : outcome2 ~ rx * site +## Randomization: rx ~ sr(1) ( Simple ) +## Variance Type: vcovG +## Marginal Mean: +## Estimate Std.Err 2.5 % 97.5 % +## 0_placebo 0.167499 0.021227 0.125894 0.2091 +## 1_indomethacin 0.092527 0.016766 0.059666 0.1254 +## +## Contrast : difference +## Estimate Std.Err Z Value Pr(>|z|) +## 1_indomethacin v.s. 0_placebo -0.074971 0.026910 -2.786 0.005337 ** +## --- +## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1There are 27 baseline covariates included in this dataset and 602 +patients. If we include all of the covariates in a logistic regression +working model, the model fails to converge and returns NA.
+++# Create formula with all baseline covariates included in dataset +covariates <- setdiff(colnames(data2), c("id", "outcome2", "rx")) +formula <- as.formula( + sprintf("outcome2 ~ rx * (%s)", paste0(covariates, collapse=" + ")) +)++robin_glm( + as.formula(formula), + treatment = rx ~ sr(1), + data=data2, + family=binomial(link="logit"), + contrast = "difference" +)+## Model : outcome2 ~ rx * (site + age + risk + gender + sod + pep + recpanc + psphinc + precut + difcan + pneudil + amp + paninj + acinar + brush + asa81 + asa325 + asa + prophystent + therastent + pdstent + sodsom + bsphinc + bstent + chole + pbmal + train) +## Randomization: rx ~ sr(1) ( Simple ) +## Variance Type: vcovG +## Marginal Mean: +## Estimate Std.Err 2.5 % 97.5 % +## 0_placebo NA NA NA NA +## 1_indomethacin NA NA NA NA +## +## Contrast : difference +## Estimate Std.Err Z Value Pr(>|z|) +## 1_indomethacin v.s. 0_placebo NA NA NA NAIf you do want to include all of the baseline covariates because you +aren’t sure which ones are the most prognostic, this is a use-case for +the SuperLearner approach. We’ll test an ensemble of random forest +(SL.ranger), elastic net regression (Sl.glmnet), and XGboost +(SL.xgboost). SuperLearner will figure out the optimal combination of +these approaches. See this +link for documentation on the SuperLearner.
+RobinCar includes SuperLearner working models with cross-fitting to +ensure we aren’t over-fitting to the data. We will use 5 folds for +cross-fitting. Since cross-fitting is a random process, we’ll also set a +seed for reproducibility.
+++set.seed(1989) + +sl <- robincar_SL( + df=data2, + response_col="outcome2", + treat_col="rx", + covariate_cols=covariates, + SL_libraries=c("SL.xgboost", "SL.glmnet", "SL.ranger"), + car_scheme="simple", + k_split=5 +)+## Done!+## Warning in func(): Prediction unbiasedness does not hold.++# Make a linear contrast +contrast <- robincar_contrast(sl, contrast_h="diff") +contrast+## Treatment group contrasts using linear contrast +## +## Contrasts: +## # A tibble: 1 × 4 +## contrast estimate se `pval (2-sided)` +## <chr> <dbl> <dbl> <dbl> +## 1 treat 1_indomethacin - 0_placebo -0.0812 0.0269 0.00256 +## +## Variance-Covariance Matrix for Contrasts: +## [,1] +## [1,] 0.0007245833