title: "Package Introduction" package: RobinCar2 output: rmarkdown::html_vignette: toc: true vignette: | %\VignetteIndexEntry{Package Introduction} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} editor_options: chunk_output_type: console
knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
RobinCar2 provides robust covariate adjustment methods for estimating and inferring treatment effects through generalized linear models (glm) under different randomization schema.
A minimal call of robin_lm() and robin_glm(), consisting of only formula,
data arguments and the randomization scheme, will produce an object of class
treatment_effect.
library(RobinCar2) head(glm_data)
In the glm_data, we have the following columns:
id is the patient identifier.treatment is the treatment assignment.s1 is the first stratification factor.s2 is the second stratification factor.covar is the continuous covariate.y is the continuous outcome.y_b is the binary outcome.For the continuous outcome y, the linear model includes covar as a covariate,
s1 as a stratification factor. The randomization scheme is a permuted-block
randomization stratified by s1. The model formula also includes the treatment
by stratification interaction as y ~ treatment * s1 + covar.
robin_lm(y ~ treatment * s1 + covar, data = glm_data, treatment = treatment ~ pb(s1) )
We can also use the Huber-White variance estimator by setting vcov = "vcovHC".
Please note that in this case, the model formula should not contain the
treatment by stratification (covariate) interaction.
robin_lm(y ~ treatment + s1 + covar, data = glm_data, treatment = treatment ~ pb(s1), vcov = "vcovHC" )
Note that robin_glm can also handle continuous outcomes using the default
family and the default link function family = gaussian().
For binary outcomes, the logistic model includes covar as a covariate,
s1 as a stratification factor. The randomization scheme is a permuted-block
randomization stratified by s1. The model formula also includes the treatment
by stratification interaction as y_b ~ treatment * s1 + covar. Note here we need
to specify family to be binomial(link = "logit").
robin_glm(y_b ~ treatment * s1 + covar, data = glm_data, treatment = treatment ~ pb(s1), family = binomial(link = "logit") )
For counts, the log link model includes covar as a covariate,
s1 as a stratification factor. The randomization scheme is a permuted-block
randomization stratified by s1. The model formula also includes the treatment
by stratification interaction as y_count ~ treatment * s1 + covar. Note here
we need to specify family to be poisson(link = "log") to use the Poisson
model or to be MASS::negative.binomial(theta = NA) to use the negative
binomial model. A fixed theta could be provided if it is known.
glm_data$y_count <- rpois(nrow(glm_data), lambda = 20) robin_glm( y_count ~ treatment * s1 + covar, data = glm_data, treatment = treatment ~ pb(s1), family = MASS::negative.binomial(theta = 1) )
If the randomization schema is not permuted-block randomization, we can use
other randomization schema. Currently RobinCar2 supports sp for the simple
randomization, pb for the permuted-block randomization, and ps for the
Pocock-Simon randomization.
robin_glm(y_b ~ treatment * s1 + covar, data = glm_data, treatment = treatment ~ ps(s1), family = binomial(link = "logit") )
To obtain the confidence interval, we can use confint function.
Given the following model
robin_res <- robin_glm(y_b ~ treatment * s1 + covar, data = glm_data, treatment = treatment ~ ps(s1), family = binomial(link = "logit"), contrast = "log_risk_ratio" ) robin_res
It is easy to obtain the confidence interval matrix for the marginal mean, at specified level.
If parm is not provided, the complete matrix (all treatment groups) will be provided.
confint(robin_res$marginal_mean, parm = 1:2, level = 0.7) confint(robin_res$marginal_mean, level = 0.7)
Similarly for the contrast, however it has an additional argument transform to provide the confidence interval at transformed level.
Thus, standard error is removed because it does not make sense anymore.
By default, if the log_risk_ratio or log_odds_ratio is used as contrast, the confint will transform it back using exponential function.
You can also specify the transform to be identity to avoid the transformation.
confint(robin_res$contrast) confint(robin_res$contrast, transform = identity)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.