Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions vignettes/table1-examples.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,13 @@ pvalue <- function(x, ...) {
# For numeric variables, perform a standard 2-sample t-test
p <- t.test(y ~ g)$p.value
} else {
# For categorical variables, perform a chi-squared test of independence
p <- chisq.test(table(y, g))$p.value
p <- tryCatch({
# For categorical variables, perform a chi-squared test of independence
chisq.test(table(y, g))$p.value
}, warning = function(w) {
# If a warning appears (due to expected cell counts <5 or too few observations), use Fisher's Exact test
return(fisher.test(table(y, g))$p.value)
})
}
# Format the p-value, using an HTML entity for the less-than sign.
# The initial empty string places the output on the line below the variable label.
Expand Down