I am using R markdown and simulating the scenario with table1 package on the melanoma data set.
is there a way to get for the continuous variables 95% confidence interval written in this way [lower CI, upper CI] below the mean and SD values, in the my render
library(boot)
melanoma2 <- melanoma
Factor the basic variables that
we’re interested in
melanoma2$status <-
factor(melanoma2$status,
levels=c(2,1,3),
labels=c("Alive", # Reference
"Melanoma death",
"Non-melanoma death"))
labels <- list(
variables=list(sex="Sex",
age="Age (years)",
ulcer="Ulceration",
thickness="Thicknessᵃ (mm)"),
groups=list("", "", "Death"))
Remove the word “death” from the labels, since it now appears above
levels(melanoma2$status) <- c("Alive", "Melanoma", "Non-melanoma")
strata <- c(list(Total=melanoma2), split(melanoma2, melanoma2$status))
my.render.cont <- function(x) {
with(stats.apply.rounding(stats.default(x), digits=2), c("",
"Mean (SD)"=sprintf("%s (± %s)", MEAN, SD)))
}
my.render.cat <- function(x) {
c("", sapply(stats.default(x), function(y) with(y,
sprintf("%d (%0.0f %%)", FREQ, PCT))))
}