Calculates effect estimates from models with all possible combinations of variables. Effect estimates here can be regression coefficients, odds ratios and hazard ratios depending on modeling methods. This approach can be used for assessing the treatment effects in clinical trials or the effects of risk factors in observational biomedical and epidemiological studies.
You can install the released version of allestimates
from CRAN with:
install.packages("allestimates")
library(allestimates)
all_cox
Run Cox Proportional Hazards Regression Models with all possible combinations of variables specified in the argument of xlist
using coxph
from survival
package.
<- c("Age", "Sex", "Smoke", "Married", "BMI", "Income")
vlist <- all_cox(crude = "Surv(t0, t1, Endpoint) ~ Diabetes", xlist = vlist, data = diab_df)
results #> estimate: Hazard ratio
#> Crude model: Surv(t0, t1, Endpoint) ~ Diabetes
results#> $estimate
#> variables estimate conf_low conf_high p aic n
#> 1 Crude 1.602936 1.447701 1.774817 1.096400e-19 19811.20 2050
#> 2 Age 1.604603 1.448449 1.777593 1.397829e-19 19813.16 2050
#> 3 Sex 1.608607 1.452824 1.781094 5.853751e-20 19770.94 2050
#> 4 Smoke 1.644631 1.485056 1.821353 1.248088e-21 19759.22 2050
#> 5 Married 1.603902 1.448565 1.775898 9.905273e-20 19806.36 2050
#> 6 BMI 1.570416 1.416793 1.740696 8.465830e-18 19805.82 2050
#> 7 Income 1.548745 1.397960 1.715793 5.748060e-17 19777.69 2050
#> 8 Age, Sex 1.608208 1.451736 1.781544 9.245663e-20 19772.94 2050
#> 9 Age, Smoke 1.645750 1.485241 1.823605 1.812683e-21 19761.20 2050
#> 10 Age, Married 1.608235 1.451707 1.781640 9.500244e-20 19808.10 2050
#> 11 Age, BMI 1.570428 1.415933 1.741779 1.316518e-17 19807.82 2050
#> 12 Age, Income 1.558416 1.406244 1.727055 2.600521e-17 19777.39 2050
#> 13 Sex, Smoke 1.637362 1.478517 1.813272 2.785608e-21 19742.94 2050
#> 14 Sex, Married 1.618358 1.461535 1.792007 2.095449e-20 19748.50 2050
#> 15 Sex, BMI 1.571950 1.418344 1.742191 6.605897e-18 19762.21 2050
#> 16 Sex, Income 1.543966 1.393714 1.710416 9.166515e-17 19719.18 2050
#> 17 Smoke, Married 1.650623 1.490375 1.828101 6.710436e-22 19749.77 2050
#> 18 Smoke, BMI 1.610709 1.452963 1.785580 1.252512e-19 19752.97 2050
#> 19 Smoke, Income 1.585644 1.431021 1.756973 1.295859e-18 19720.88 2050
#> 20 Married, BMI 1.572164 1.418387 1.742613 6.978273e-18 19801.26 2050
#> 21 Married, Income 1.552276 1.401057 1.719815 4.148424e-17 19778.25 2050
#> 22 BMI, Income 1.521289 1.371681 1.687214 1.965444e-15 19773.96 2050
#> 23 Age, Sex, Smoke 1.637401 1.477751 1.814300 4.473889e-21 19744.94 2050
#> 24 Age, Sex, Married 1.622202 1.464266 1.797172 2.101959e-20 19750.29 2050
#> 25 Age, Sex, BMI 1.569302 1.415133 1.740266 1.328561e-17 19764.12 2050
#> 26 Age, Sex, Income 1.554042 1.402388 1.722097 3.932443e-17 19718.55 2050
#> 27 Age, Smoke, Married 1.655242 1.493685 1.834273 6.750476e-22 19751.52 2050
#> 28 Age, Smoke, BMI 1.609797 1.451193 1.785734 2.326315e-19 19754.96 2050
#> 29 Age, Smoke, Income 1.596162 1.440008 1.769249 5.488279e-19 19720.52 2050
#> 30 Age, Married, BMI 1.574987 1.420034 1.746847 8.215646e-18 19803.16 2050
#> 31 Age, Married, Income 1.562798 1.410079 1.732056 1.742013e-17 19777.71 2050
#> 32 Age, BMI, Income 1.530640 1.379531 1.698300 1.000052e-15 19774.24 2050
#> 33 Sex, Smoke, Married 1.647630 1.487682 1.824775 9.355592e-22 19720.79 2050
#> 34 Sex, Smoke, BMI 1.600443 1.443803 1.774078 3.592314e-19 19734.46 2050
#> 35 Sex, Smoke, Income 1.568890 1.415926 1.738379 7.654131e-18 19692.48 2050
#> 36 Sex, Married, BMI 1.582055 1.427439 1.753419 2.284029e-18 19739.49 2050
#> 37 Sex, Married, Income 1.559178 1.407253 1.727505 2.041332e-17 19708.34 2050
#> 38 Sex, BMI, Income 1.511316 1.362903 1.675890 4.844829e-15 19711.83 2050
#> 39 Smoke, Married, BMI 1.617442 1.458970 1.793128 6.264461e-20 19743.89 2050
#> 40 Smoke, Married, Income 1.593862 1.438213 1.766356 6.039354e-19 19719.32 2050
#> 41 Smoke, BMI, Income 1.555344 1.402225 1.725183 6.637521e-17 19715.81 2050
#> 42 Married, BMI, Income 1.524832 1.374795 1.691244 1.428294e-15 19774.52 2050
#> 43 Age, Sex, Smoke, Married 1.652106 1.490910 1.830729 9.272965e-22 19722.54 2050
#> 44 Age, Sex, Smoke, BMI 1.598056 1.440739 1.772550 7.577121e-19 19736.39 2050
#> 45 Age, Sex, Smoke, Income 1.579718 1.425231 1.750950 3.086309e-18 19691.73 2050
#> 46 Age, Sex, Married, BMI 1.583848 1.428209 1.756447 2.942044e-18 19741.45 2050
#> 47 Age, Sex, Married, Income 1.570948 1.417426 1.741098 7.399515e-18 19707.03 2050
#> 48 Age, Sex, BMI, Income 1.520592 1.370732 1.686836 2.433956e-15 19711.98 2050
#> 49 Age, Smoke, Married, BMI 1.620219 1.460473 1.797438 8.109894e-20 19745.81 2050
#> 50 Age, Smoke, Married, Income 1.605552 1.448221 1.779975 2.298658e-19 19718.62 2050
#> 51 Age, Smoke, BMI, Income 1.565254 1.410518 1.736966 3.272296e-17 19716.11 2050
#> 52 Age, Married, BMI, Income 1.535060 1.383400 1.703346 6.759584e-16 19774.60 2050
#> 53 Sex, Smoke, Married, BMI 1.611052 1.453335 1.785884 1.165826e-19 19712.07 2050
#> 54 Sex, Smoke, Married, Income 1.584644 1.429924 1.756106 1.600942e-18 19681.94 2050
#> 55 Sex, Smoke, BMI, Income 1.535048 1.384039 1.702535 5.011866e-16 19684.80 2050
#> 56 Sex, Married, BMI, Income 1.526068 1.376062 1.692426 1.175969e-15 19700.47 2050
#> 57 Smoke, Married, BMI, Income 1.563486 1.409350 1.734479 3.183370e-17 19714.30 2050
#> 58 Age, Sex, Smoke, Married, BMI 1.613341 1.454467 1.789568 1.523950e-19 19714.01 2050
#> 59 Age, Sex, Smoke, Married, Income 1.597132 1.440704 1.770545 5.449028e-19 19680.52 2050
#> 60 Age, Sex, Smoke, BMI, Income 1.545005 1.392429 1.714300 2.399979e-16 19684.88 2050
#> 61 Age, Sex, Married, BMI, Income 1.537049 1.385401 1.705297 5.025127e-16 19700.05 2050
#> 62 Age, Smoke, Married, BMI, Income 1.574620 1.418704 1.747672 1.412887e-17 19714.29 2050
#> 63 Sex, Smoke, Married, BMI, Income 1.550384 1.397689 1.719760 1.139567e-16 19673.84 2050
#> 64 Age, Sex, Smoke, Married, BMI, Income 1.562040 1.407589 1.733439 4.625451e-17 19673.34 2050
#>
#> $xlist
#> [1] "Age" "Sex" "Smoke" "Married" "BMI" "Income"
#>
#> $fun
#> [1] "all_cox"
#>
#> $crude
#> [1] "Surv(t0, t1, Endpoint) ~ Diabetes"
#>
#> $family
#> [1] "coxph"
All hazard ratio estimates are stored in the object results
which can be used for further analysis and graphic presentation.
all_plot
all_plot
quickly presents all hazard ratio (effect) estimates in the graph divided into four parts (quarters).
all_plot(results)
In this example, all hazard ratio estimates are in the left-upper quarter of the graph, indicating a positive association between Diabetes
and Endpoint
.
all_plot2
all_plot2(results)
Plot hazard ratios (effect estimates) indicating whether each of those variables included and not included in the model.
all_glm
or all_speedglm
all_speedglm
calling speedglm
is a faster alternative of all_glm
which calls glm
. By default, those functions run logistic regressions to calculate odds ratios.
$Overweight = as.numeric(diab_df$BMI >= 25)
diab_df<- c("Age", "Sex", "Education","Married", "BMI", "Income")
vlist <- all_speedglm(crude = "Diabetes ~ Overweight", xlist = vlist, data = diab_df)
results #> estimate: Odds Ratio or Rate Ratio
#> Crude model: Diabetes ~ Overweight
all_plot(results)
all_plot2(results)
In this example, odds ratio estimates appeared in two upper quarters, a positive association with alpha levels less than 0.05 in some models (left-upper) and higher than 0.05 in others. Since different models produce conflicting results, inspecting all_plot2
can be helpful in combination with biological background knowledge. As we can see the above plot, estimates were in the right-hand side of the vertical line when BMI
was included in models. In this case, including BMI
when assessing the association between Overweight
and Diabetes
can be problematic because Overweight
was determined based on BMI
.
all_plot_aic2(results)
all_lm
all_lm
fits Linear Regression Models with all possible combinations of variables specified in the argument of xlist
using lm
from stats
package.
<- c("Age", "Sex", "Education", "Income", "Diabetes", "Smoke")
vlist <- all_lm(crude = "BMI ~ Married", xlist = vlist, data = diab_df)
results #> estimate: Coefficient
#> Crude model: BMI ~ Married
all_plot(results)
all_plot2(results)
All estimates are in the right-hand side of the vertical line. The results does not support an association between the marital status Married
and BMI
.
Note: If you want to add non-linear terms or interaction terms, generate those terms as variables first and add them to the argument of xlist
.