Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handing multiple checkboxes variable #124

Open
pbilodeau94 opened this issue Mar 19, 2024 · 0 comments
Open

Handing multiple checkboxes variable #124

pbilodeau94 opened this issue Mar 19, 2024 · 0 comments

Comments

@pbilodeau94
Copy link

Hi! Very nice package. I'm working with survey data that has multiple checkboxes variable, where dummy variables are created for each factor e.g comorbidities___1, 2, 3, etc. I tried using the solution from #98 and it correctly creates the header and subcategories, but I have not been able to pull the data.
image

label (demographics_table$Age_at_nmo_diagnosis) <- "Age at NMO diagnosis"
label (demographics_table$Follow_up_time) <- "Follow-up (in years)"
demographics_table$comorbidities <- 1:nrow (demographics_table)
label(demographics_table$comorbidities) <- "Comorbidities, n (%)"

rndr <- function(x, name, ...) {
if (name == "comorbidities") {
vars <- c("Autoimmune disease",
"Psychiatric disorders (anxiety or depression, mania, psychosis)",
"Neurologic disorders (including migraines)",
"Vascular risk factors (hypertension, diabetes, hyperlipidemia)",
"Coronary artery disease or ischemic heart disease",
"Chronic obstructive pulmonary disease or asthma",
"Chronic kidney disease",
"Cancer",
"None")
y <- sapply(vars, function(var) {
render.default(dat[[var]][x])[2]
})
names(y) <- sapply(vars, function(var) {
l <- label(dat$var)
if (is.null(l)) var else l
})
c("", y)
} else {
# For numeric variables, perform Shapiro-Wilk test and render based on its result
if (is.numeric(x)) {
shapiro_test_result <- shapiro.test(x)
what <- ifelse(shapiro_test_result$p.value > 0.05,
"Mean (SD)", # If p-value > 0.05, data is considered normally distributed
"Median [IQR]") # If p-value <= 0.05, data is considered not normally distributed
parse.abbrev.render.code(c("", what))(x)
} else {
# For non-numeric variables, use default rendering
render.default(x, name, ...)
}
}
}
table1(~ Age + sex + ethnicity + race + bmi + Age_at_nmo_diagnosis + Follow_up_time + living_deceased + mrs_lastfu + comorbidities| aqp4, data = demographics_table, render = rndr)

Do you know of an easy way to show those variables in the table?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant