I have demographic data and for some of the variables I want to show Mean (95% CI) So far:
> label (demog$Site) = "Site"
> label (demog$Sex) = "Sex"
> label (demog$Age) = "Age (years)"
> label (demog$Temperature) = "Temperature (Celcius)"
> label (demog$MOI) = "MOI"
>
> table1(~Sex + Age + Temperature + MOI | Site, data = demog)
This gives me all of my varaibles stratified by the sampling site, which is what I want. But it reports the Mean (SD), Median [Min, Max], and Missing for each continuous variable (everything but "Sex"), which I don't want.
To change what was shown, I tried mimicking this: https://benjaminrich.github.io/table1/vignettes/table1-examples.html
I made:
> my.render.cont = function(x) {with(stats.apply.rounding(stats.default(x), digits=2), c("", "Mean (95% CI)"=sprintf("%s (± %s)", MEAN, (MEAN + SD*1.96), (MEAN - SD*1.96))))}
> my.render.cat = function(x) {c("", sapply(stats.default(x), function(y) with(y, sprintf("%d (%0.0f %%)", FREQ, PCT))))}
> strata = c(list(Total=demog), split(demog, demog$Site))
But when I tried to actually show the table
> table1(strata, labels, render.continuous=my.render.cont, render.categorical=my.render.cat)
Error: object of type 'closure' is not subsettable
I don't necessarily care about showing the 95% CIs this specific way, I just want to show them. If anyone has a fix to this error, great. If anyone has an entirely different way to show Mean (95% CI) in this table, also great