Compute stanadardization (i.e. G-Computation) estimator
Source:R/standardization.R
standardization.Rd
Computes the estimate of a contrast of means for continuous and binary outcomes on the additive scale, relative scale. Computing a marginal odds ratio is also possible for binary outcomes.
Usage
standardization(
data,
estimand = "difference",
y0_formula,
y1_formula,
family,
treatment_column = NULL,
outcome_indicator_column = NULL
)
standardization_correction(
data,
y0_formula,
y1_formula,
treatment_column,
outcome_indicator_column
)
Arguments
- data
A
data.frame
containing baseline covariates (e.g.x1
,x2
, ...), a binary treatment indicator (e.g.tx
where 1 = Treatment; 0 = Control), outcome variables (e.g.y1
,y2
, ...), and outcome indicators (e.g..r_1
,.r_2
, ...). The outcome indicators indicate whether an outcome has been observed (1
), is missing (0
), or not yet obtained (NA
).- estimand
A
character
scalar: "difference" (for a difference in means or risk difference), "ratio" (for a ratio of means or relative risk), or "oddsratio" (for an odds ratio for a binary outcome).- y0_formula
A stats::formula specifying the relationship between the outcome and covariates in the control arm.
- y1_formula
A stats::formula specifying the relationship between the outcome and covariates in the treatment arm.
- family
The stats::family for the outcome regression model
- treatment_column
A
character
scalar indicating the column containing the treatment indicator.- outcome_indicator_column
A
character
scalar indicating the column containing the outcome indicator corresponding totreatment_column
.
Details
Generalized linear models, stratified by treatment arm, are fitted using the specified formulas. Predictions are generated for each individual from each treatment model, representing the predicted outcome under each treatment assignment. These predictions are marginalized over the covariates by averaging to produce marginal estimates of the means. Finally, the contrast is computed and returned.
Variance estimates can be obtained using the nonparametric bootstrap. Unadjusted estimates can be obtained by using intercept only models.
Examples
ex_1 <- example_1
ex_1$.r_4 <- 1*(!is.na(ex_1$y_4))
standardization(
data = ex_1,
estimand = "difference",
y0_formula = y_4 ~ x_1 + x_2 + x_3 + x_4,
y1_formula = y_4 ~ x_1 + x_2 + x_3 + x_4,
family = gaussian,
treatment_column = "tx",
outcome_indicator_column = ".r_4"
)
#> $estimate
#> [1] 3.399756
#>
#> $y1_pred
#> 1 2 3 4 5 6
#> -0.297051858 5.073109474 11.436194287 -2.513249148 8.465807942 2.964424727
#> 7 8 9 10 11 12
#> 1.329629699 3.702978369 0.583497314 8.278725911 2.066010821 7.574220209
#> 13 14 15 16 17 18
#> 8.059079706 -0.237060205 4.512008648 7.886628113 6.819003744 12.488891547
#> 19 20 21 22 23 24
#> -4.396487588 7.980101994 7.835935773 9.386694433 9.600527704 11.345502540
#> 25 26 27 28 29 30
#> 7.526925700 6.570070999 1.195479206 14.197233167 -3.740726868 -1.054410797
#> 31 32 33 34 35 36
#> 0.377046558 -1.359020248 8.341046638 -0.760193888 12.095957376 0.827557407
#> 37 38 39 40 41 42
#> 1.142987383 11.365537427 4.394520750 4.846709061 0.671176472 4.866668537
#> 43 44 45 46 47 48
#> 16.669510919 -0.535484097 4.724423653 10.453155535 2.182827822 3.646232219
#> 49 50 51 52 53 54
#> 2.554949396 8.415424213 -1.629085444 6.212956673 9.707494802 3.402470267
#> 55 56 57 58 59 60
#> 3.298780017 -0.023389418 6.282669269 15.002882674 9.016259072 -2.120883320
#> 61 62 63 64 65 66
#> 13.584155206 7.972138009 -0.327298990 -5.859776104 7.799248530 7.930315974
#> 67 68 69 70 71 72
#> 2.081842180 4.647729974 10.603181547 4.322683208 2.980861237 -0.293104870
#> 73 74 75 76 77 78
#> 4.345600417 5.353470291 9.491364566 -2.483042959 8.060922454 -2.848809088
#> 79 80 81 82 83 84
#> 1.267695476 13.892626118 6.873781113 1.565514694 4.927546594 12.779692123
#> 85 86 87 88 89 90
#> 7.406749570 6.259928006 5.821015519 -0.024263548 2.405295153 1.954568986
#> 91 92 93 94 95 96
#> 4.966503078 10.680288450 -5.617376258 1.819708761 16.075819981 -0.621160094
#> 97 98 99 100 101 102
#> 1.647365497 6.232268535 1.534085623 10.492200443 1.941639089 0.009062318
#> 103 104 105 106 107 108
#> 6.203182538 5.917814244 4.512744743 1.960211105 5.438448585 -4.644893491
#> 109 110 111 112 113 114
#> -1.874170408 4.169962197 11.774180178 0.183018732 4.555624627 4.798871160
#> 115 116 117 118 119 120
#> 3.293412932 11.219324718 3.828292949 5.184923919 -0.312499263 9.921262066
#> 121 122 123 124 125 126
#> 0.066305387 6.464671612 4.189741786 6.429775707 4.473312531 2.494016113
#> 127 128 129 130 131 132
#> 8.227636162 -7.004591693 0.540755008 8.772332355 12.036693094 3.892001708
#> 133 134 135 136 137 138
#> 1.050136975 -3.447485624 9.631010062 1.792401265 3.927341604 2.658138653
#> 139 140 141 142 143 144
#> 6.690208421 3.510519788 -2.060464142 10.545740886 2.188605527 6.912954393
#> 145 146 147 148 149 150
#> 3.190863622 15.563077802 -8.111077566 4.980135539 6.654453568 3.383329118
#> 151 152 153 154 155 156
#> 6.479447591 -0.140368080 5.345597596 14.352718616 4.372367694 -3.415367654
#> 157 158 159 160 161 162
#> 4.834836311 -1.210974845 -6.904389433 2.476945936 10.691536736 9.180756844
#> 163 164 165 166 167 168
#> 3.190953103 5.192707152 7.222875013 12.109275000 8.629434159 5.653633237
#> 169 170 171 172 173 174
#> 13.294147211 13.248027476 -0.351326842 1.489021483 8.699858133 8.620943622
#> 175 176 177 178 179 180
#> 3.331467295 14.777410595 0.277646771 9.478067915 4.690259698 9.861443414
#> 181 182 183 184 185 186
#> 13.982665208 10.763437242 7.408329690 2.823376601 7.324778154 1.050275620
#> 187 188 189 190 191 192
#> 9.031491318 -0.431978558 5.097501235 -3.373953668 7.876481276 7.259143858
#> 193 194 195 196 197 198
#> 5.032283175 5.279436795 6.506435284 2.346482216 9.915531027 -2.351233753
#> 199 200 201 202 203 204
#> 6.528750998 1.765941582 11.989494540 13.762651635 4.943060599 -1.133975437
#> 205 206 207 208 209 210
#> 7.191147083 -0.301078619 5.603496348 10.481670093 10.371049987 4.612870111
#> 211 212 213 214 215 216
#> 3.643203539 4.367922314 5.660704335 4.484621594 12.710301520 3.100211616
#> 217 218 219 220 221 222
#> 12.647356672 -4.828054373 8.092643731 0.955353160 1.649256417 16.892977209
#> 223 224 225 226 227 228
#> 7.802017587 10.343180665 7.086627365 14.547013540 -4.053265589 0.696517564
#> 229 230 231 232 233 234
#> 12.426849180 -6.093232309 10.341036368 3.505514343 7.683300971 11.814084974
#> 235 236 237 238 239 240
#> 0.207818521 12.584715101 4.300786546 -2.736527721 7.859595526 11.123626763
#> 241 242 243 244 245 246
#> 10.223281729 19.108704235 9.357019868 -4.541704580 7.076749565 6.782784202
#> 247 248 249 250 251 252
#> 5.381955674 11.149902643 -2.802809197 1.342226120 4.909787615 -2.122455165
#> 253 254 255 256 257 258
#> 8.348697027 8.613037844 0.366674423 5.013208899 10.198756563 3.169252497
#> 259 260 261 262 263 264
#> 4.266800291 5.777463823 5.338778691 3.656025911 3.555998749 8.706774792
#> 265 266 267 268 269 270
#> 12.538376494 10.982582713 11.788257900 4.233066916 10.531578258 5.021019152
#> 271 272 273 274 275 276
#> -2.911129593 11.189336499 2.821315525 4.408168484 6.583162083 1.511252190
#> 277 278 279 280 281 282
#> 7.405094967 2.472301493 6.704306689 1.121372912 2.332754030 6.475399590
#> 283 284 285 286 287 288
#> 7.007579616 11.135455013 4.892699046 9.041922065 13.987596523 7.579622103
#> 289 290 291 292 293 294
#> 11.148506324 1.621183777 -1.974476193 -0.531407174 3.615686540 6.449567856
#> 295 296 297 298 299 300
#> 5.547206755 5.655709394 9.554970645 10.811082968 4.888080095 4.345795222
#>
#> $y0_pred
#> 1 2 3 4 5 6
#> 0.29513801 1.45051208 6.57681738 -4.93329026 4.15647654 -0.56341465
#> 7 8 9 10 11 12
#> 1.60851871 -0.26771424 -4.75730987 4.19768331 0.97506743 7.54440913
#> 13 14 15 16 17 18
#> 5.06705080 1.18663014 0.94411379 5.75660204 2.49123485 7.13545396
#> 19 20 21 22 23 24
#> -5.78415572 4.78129418 3.47565019 7.03572879 1.51399934 4.67492510
#> 25 26 27 28 29 30
#> 0.83985663 -1.42007878 -4.50526832 9.18472878 -6.69306748 -5.31330550
#> 31 32 33 34 35 36
#> -2.78640260 -2.10695699 2.44961903 -5.05738667 5.12879051 -2.70333559
#> 37 38 39 40 41 42
#> -0.66327583 4.64486556 2.87718646 3.70495234 -0.61526473 5.65676039
#> 43 44 45 46 47 48
#> 11.00417427 -6.00953265 2.77973457 6.88433822 -1.85433187 -0.27945891
#> 49 50 51 52 53 54
#> -3.05379510 4.25352252 -3.20499786 5.09565144 5.90733778 1.01392810
#> 55 56 57 58 59 60
#> 1.36936532 -4.34068705 3.29352698 11.70782895 4.13649440 -5.35507918
#> 61 62 63 64 65 66
#> 8.72578102 3.70370295 -1.85300954 -8.45537717 5.34758574 1.91878595
#> 67 68 69 70 71 72
#> -1.70826561 0.07570689 7.48480813 1.85693824 -0.38483276 0.13627150
#> 73 74 75 76 77 78
#> 1.16053478 3.47115272 1.03550429 -3.12468960 4.84205590 -6.18832432
#> 79 80 81 82 83 84
#> -1.72550637 7.63395837 4.04394423 0.45469142 -0.35145691 6.38846000
#> 85 86 87 88 89 90
#> 7.27242203 1.09759623 0.05137633 1.09083878 -4.75181375 0.81946330
#> 91 92 93 94 95 96
#> 1.01321302 6.90157980 -8.55652105 -1.86535376 9.85114151 -4.08795173
#> 97 98 99 100 101 102
#> -2.10031500 1.24401020 1.33165360 5.59539780 -1.05439557 -1.96659194
#> 103 104 105 106 107 108
#> 0.41480786 2.74166317 0.73071674 0.30436064 2.27367607 -6.61314037
#> 109 110 111 112 113 114
#> -0.89599499 -0.20330360 5.81101171 -3.05021205 -0.67521906 0.80078768
#> 115 116 117 118 119 120
#> -1.32762460 10.07252300 2.46584354 1.47034863 -5.96461749 4.33255630
#> 121 122 123 124 125 126
#> -4.09948579 0.92958960 0.05852662 3.28598045 -1.53979917 -2.44531235
#> 127 128 129 130 131 132
#> 3.50344872 -12.49873363 -2.14322463 6.81314831 11.13074286 3.69212011
#> 133 134 135 136 137 138
#> -5.12119742 -8.58705562 4.77696161 -1.71478672 2.77732028 2.22848469
#> 139 140 141 142 143 144
#> 1.99015797 -1.07740918 -6.38001586 5.52079333 -0.52429451 3.69931867
#> 145 146 147 148 149 150
#> -0.35692891 11.30888544 -10.52703528 -1.80784264 -2.28888244 -0.95978005
#> 151 152 153 154 155 156
#> 5.15496126 -2.52551468 6.61972938 7.88454578 4.77774187 -7.58697832
#> 157 158 159 160 161 162
#> 0.74645659 -3.02234522 -9.57140842 1.62330545 10.83617353 8.04593929
#> 163 164 165 166 167 168
#> 0.00540188 1.47499597 2.05039690 4.69580168 6.75383173 0.39454606
#> 169 170 171 172 173 174
#> 10.97392026 10.96747338 -5.57558637 -2.58984960 5.78308649 4.69317793
#> 175 176 177 178 179 180
#> 1.74953285 11.63069271 -2.47866937 6.32125310 1.18294243 5.03115514
#> 181 182 183 184 185 186
#> 9.63406596 4.76170308 4.72386736 0.76376851 5.10532146 -1.87160296
#> 187 188 189 190 191 192
#> 5.87004065 0.88018560 0.22305278 -3.23233355 2.52219555 2.03135409
#> 193 194 195 196 197 198
#> 1.85823043 0.11754956 5.95018371 0.57749290 4.08253360 -8.77234401
#> 199 200 201 202 203 204
#> 5.01288235 -1.47972041 6.66502776 10.82874977 -0.02579330 -1.57341093
#> 205 206 207 208 209 210
#> 7.41480659 -3.54379525 1.04831493 8.59029347 5.54286099 -2.76193619
#> 211 212 213 214 215 216
#> -0.19284239 3.66866794 6.05184017 4.67161686 7.65418030 -1.53331001
#> 217 218 219 220 221 222
#> 5.58780770 -6.90396483 3.21730215 -2.07078451 1.44759837 11.11253031
#> 223 224 225 226 227 228
#> 10.73952458 8.91710642 6.34378213 8.46527232 -0.69989084 0.50470181
#> 229 230 231 232 233 234
#> 11.25943897 -9.01745879 9.98069698 -1.67386944 2.24913944 9.01335133
#> 235 236 237 238 239 240
#> -1.62299312 4.41368280 0.96572540 -6.93429093 3.29534392 4.22569843
#> 241 242 243 244 245 246
#> 10.00835908 13.63335087 3.69194364 -5.67939763 4.48772560 0.20868586
#> 247 248 249 250 251 252
#> 3.19513255 4.42626429 -2.40670417 0.59439782 -0.56444748 -3.57192431
#> 253 254 255 256 257 258
#> 6.26010046 3.40296339 1.45202589 1.86749164 6.22368611 0.81010813
#> 259 260 261 262 263 264
#> 1.53427166 4.53642209 1.86092392 -0.96780156 -0.20685046 3.65736988
#> 265 266 267 268 269 270
#> 3.84428540 5.05587961 10.11964544 3.30958026 6.51819972 1.74112267
#> 271 272 273 274 275 276
#> -7.28027170 7.97135050 -1.35208037 -1.35594062 4.90411480 -1.58385498
#> 277 278 279 280 281 282
#> 4.32767736 -1.24098224 2.44845522 -2.48756366 -0.72164870 -0.67771463
#> 283 284 285 286 287 288
#> 4.81845962 6.68136224 1.13089909 3.94423628 8.13967283 1.54679639
#> 289 290 291 292 293 294
#> 6.92826722 0.54854995 -1.12398015 -4.45525658 -4.93959840 3.99151710
#> 295 296 297 298 299 300
#> 2.09538416 4.07907836 5.89236185 10.11967178 0.11747174 3.84806477
#>
#> attr(,"class")
#> [1] "standardization"