I have an object called resultados ,a list, which is a result from a cch function. applied to set a model that was run in a loop to iterate for a list of biomarkers (111 elements). I would like to obtain the table that is displayed in the summary of each element. This table is different if you go by resultados$hsalet7a5p$coefficients
resultados <- list()
# Iterate in variables where i are the 111 biomarkers
for (i in columnas) {
# age, sex, HDL-C levels, diabetes, hypercholesterolaemia, triglyceride levels, hypertension, smoking habit, body mass index, and leisure-time physical activity.
# Construir dinámicamente la fórmula
formula <- as.formula(paste("Surv(tocoro, iam) ~ edat + sexe + hdldir + diabetis + fuma + box + pes + trigli + col + ", i))
# Analysis
resultado <- cch(formula, data = dat, subcoh = ~ casecohort2, id = ~parti, cohort.size = 5404, method = "LinYing", robust = TRUE)
# Almacenar el resultado en la lista
resultados[[i]] <- resultado
}
> class(resultados$hsalet7a5p)
[1] "cch"
> summary(resultados$hsalet7a5p)
Case-cohort analysis,x$method, LinYing
with subcohort of 195 from cohort of 5404
Call: cch(formula = formula, data = dat, subcoh = ~casecohort2, id = ~parti,
cohort.size = 5404, method = "LinYing", robust = TRUE)
Coefficients:
Coef HR (95% CI) p
edat 0.050 1.052 1.010 1.095 0.015
sexe2 -1.753 0.173 0.060 0.502 0.001
hdldir -0.019 0.981 0.941 1.024 0.381
diabetis 0.357 1.429 0.495 4.124 0.510
fuma -0.310 0.733 0.556 0.967 0.028
box5 4.314 74.727 30.717 181.790 0.000
pes -0.021 0.979 0.947 1.012 0.218
trigli 0.001 1.001 0.994 1.009 0.740
col 0.011 1.011 1.001 1.022 0.034
hsalet7a5p 0.198 1.219 1.003 1.482 0.047
Thanks in advance
Loop over the list and use broom::tidy
:
# data from cch help page
res <- list(fit1 = cch(Surv(edrel, rel) ~ stage + histol + age, data =ccoh.data,
subcoh = ~subcohort, id=~seqno, cohort.size=4028),
fit2 = cch(Surv(edrel, rel) ~ stage, data =ccoh.data,
subcoh = ~subcohort, id=~seqno, cohort.size=4028))
library(broom)
lapply(res, function(i) {
x <- broom::tidy(i)
x[, c("HR", "HR_ci_lo", "HR_ci_hi")] <-
lapply(c("estimate", "conf.low", "conf.high"), function(i) exp(x[[ i ]]))
x
})
#$fit1
## A tibble: 5 × 10
# term estimate std.error statistic p.value conf.low conf.high HR HR_ci_lo HR_ci_hi
# <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#1 stageII 0.735 0.168 4.36 1.30e- 5 0.404 1.06 2.08 1.50 2.90
#2 stageIII 0.597 0.173 3.44 5.77e- 4 0.257 0.937 1.82 1.29 2.55
#3 stageIV 1.38 0.205 6.76 1.40e-11 0.983 1.79 3.99 2.67 5.96
#4 histolUH 1.50 0.160 9.38 0 1.19 1.81 4.47 3.27 6.12
#5 age 0.0433 0.0237 1.82 6.83e- 2 -0.00324 0.0898 1.04 0.997 1.09
#
#$fit2
## A tibble: 3 × 10
# term estimate std.error statistic p.value conf.low conf.high HR HR_ci_lo HR_ci_hi
# <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#1 stageII 0.851 0.152 5.59 2.28e- 8 0.553 1.15 2.34 1.74 3.16
#2 stageIII 0.938 0.152 6.19 6.20e-10 0.641 1.24 2.56 1.90 3.44
#3 stageIV 1.42 0.185 7.69 1.49e-14 1.06 1.79 4.16 2.89 5.98