rm(list=ls())
library(RobinCar)

Linear and Joint Calibration for Guaranteed Efficiency Gain and Universality

The dataset that we will use for this is included in the package.

data <- RobinCar:::data_sim
data$A <- as.factor(data$A)
 # add some noise as an extra covariate as toy example
data$extra_cov <- rnorm(nrow(data))

Adjustment with Binary Outcomes

Dichotomize the continuous outcome.

data$y_bin <- ifelse(data$y > 2, 1, 0)

Fit a heterogeneous working model with biased coin randomization, then perform linear and joint calibration.

result <- robincar_glm(
  df=data,
  response_col="y_bin",
  treat_col="A",
  car_strata_cols=c("z1"),
  car_scheme="biased-coin",
  g_family=binomial(link="logit"),
  g_accuracy=7,
  formula="y_bin ~ A + x3 + z1"
)
print(result)
#> Treatment group mean estimates from a GLM working model of family binomial and link logit using formula: 
#> response ~ treat + x3 + z1
#> 
#> 
#> Used HC0-type of heteroskedasticity-consistent variance estimates 
#> and adjusted variance-covariance matrix for randomization car_strata z1 
#> consistent with the biased-coin design.
#> 
#> Estimates:
#> # A tibble: 3 × 4
#>   treat estimate     se `pval (2-sided)`
#>   <chr>    <dbl>  <dbl>            <dbl>
#> 1 0        0.558 0.0369        1.12e- 51
#> 2 1        0.763 0.0271        7.01e-175
#> 3 2        0.718 0.0303        3.42e-124
#> 
#> Variance-Covariance Matrix:
#>           [,1]         [,2]         [,3]
#> 0 1.359508e-03 1.002508e-04 3.171744e-05
#> 1 1.002508e-04 7.332810e-04 9.390325e-05
#> 2 3.171744e-05 9.390325e-05 9.166562e-04

Calibration

Use joint = FALSE to indicate linear calibration. This fits a model with the predicted potential outcomes as covariates.

robincar_calibrate(
  result=result,
  joint=FALSE
)
#> Linear calibration on the following model result:
#> --------------------------------------------
#> Treatment group mean estimates from a GLM working model of family binomial and link logit using formula: 
#> response ~ treat + x3 + z1
#> 
#> 
#> Used HC0-type of heteroskedasticity-consistent variance estimates 
#> and adjusted variance-covariance matrix for randomization car_strata z1 
#> consistent with the biased-coin design.
#> 
#> Estimates:
#> # A tibble: 3 × 4
#>   treat estimate     se `pval (2-sided)`
#>   <chr>    <dbl>  <dbl>            <dbl>
#> 1 0        0.607 0.0374        2.32e- 59
#> 2 1        0.765 0.0270        2.45e-177
#> 3 2        0.717 0.0304        1.14e-122
#> 
#> Variance-Covariance Matrix:
#>           [,1]         [,2]         [,3]
#> 0 1.397997e-03 7.442724e-05 5.110205e-05
#> 1 7.442724e-05 7.265707e-04 9.210614e-05
#> 2 5.110205e-05 9.210614e-05 9.269001e-04

Use joint = TRUE to indicate joint calibration. This fits a model with the predicted potential outcomes and the joint strata variables.

robincar_calibrate(
  result=result,
  joint=TRUE
)
#> Joint calibration on the following model result:
#> --------------------------------------------
#> Treatment group mean estimates from a GLM working model of family binomial and link logit using formula: 
#> response ~ treat + x3 + z1
#> 
#> 
#> Used HC0-type of heteroskedasticity-consistent variance estimates 
#> and adjusted variance-covariance matrix for randomization car_strata z1 
#> consistent with the biased-coin design.
#> 
#> Estimates:
#> # A tibble: 3 × 4
#>   treat estimate     se `pval (2-sided)`
#>   <chr>    <dbl>  <dbl>            <dbl>
#> 1 0        0.581 0.0287        3.10e- 91
#> 2 1        0.762 0.0268        2.17e-177
#> 3 2        0.722 0.0300        1.32e-127
#> 
#> Variance-Covariance Matrix:
#>           [,1]         [,2]         [,3]
#> 0 8.227905e-04 5.447923e-05 2.322831e-06
#> 1 5.447923e-05 7.200310e-04 1.013007e-04
#> 2 2.322831e-06 1.013007e-04 9.017343e-04

Use add_x to include additional covariates in the calibration. This fits a model with the predicted potential outcomes and specified additional covariates (and the joint strata if joint = TRUE).

robincar_calibrate(
  result=result,
  joint=TRUE,
  add_x=c("extra_cov")
)
#> Joint calibration, additionally adjusting for covariatesextra_cov, , on the following model result:
#> --------------------------------------------
#> Treatment group mean estimates from a GLM working model of family binomial and link logit using formula: 
#> response ~ treat + x3 + z1
#> 
#> 
#> Used HC0-type of heteroskedasticity-consistent variance estimates 
#> and adjusted variance-covariance matrix for randomization car_strata z1 
#> consistent with the biased-coin design.
#> 
#> Estimates:
#> # A tibble: 3 × 4
#>   treat estimate     se `pval (2-sided)`
#>   <chr>    <dbl>  <dbl>            <dbl>
#> 1 0        0.578 0.0282        1.28e- 93
#> 2 1        0.760 0.0266        6.17e-179
#> 3 2        0.722 0.0300        1.17e-127
#> 
#> Variance-Covariance Matrix:
#>           [,1]         [,2]         [,3]
#> 0 7.933915e-04 4.645474e-05 9.106364e-07
#> 1 4.645474e-05 7.100323e-04 1.021362e-04
#> 2 9.106364e-07 1.021362e-04 9.016799e-04