tableone
tableone copied to clipboard
odds ratio instead of p-value for categorical variables
Dream package! Kudos to its author Kazuki.
Now, for summarizing binary variables stratified by another binary variable, is there a way to output odds ratios (see attached picture taken from Agresti's CDA book) instead of p-values?
I guess there's an easy tweak to achieve this. Can you point me to the right place to get started? Thank you.
You can capture the output as a string matrix, and from there everything is under your control.
## Create a vector of OR as you like
orObject
## Capture output as a string matrix
tabAsStringMatrix <- print(TableOneObject, printToggle = FALSE, noSpaces = TRUE, test = FALSE)
## Add OR column
tab1 <- cbind(tabAsStringMatrix, orObject)
## print or write.csv()
tab1
Thanks for your response, Kazuki.
I apologize for not making my points clear; here is what I meant to ask: I assume CreateTableOne()
performs hypothesis testing in the background and extract p-value by fisher.test(data)$p.value
; my question is whether it's possible to add the option of outputting fisher.test(data)$estimate
, the conditional odds ratio, with some simple tweak to the CreateTableOne()
function.
The solution you suggested is indeed elegant and doesn't require much work. But with CreateTableOne()
, I can probably do some customization and streamline the process.
Thank you.
Testing occurs with this helper function, which runs a given test function and extracts the $p.value
part of the results.
https://github.com/kaz-yos/tableone/blob/42382213fd27416c6bfe7a534d30fca25fd83cd2/R/modules-constructors.R#L239-L263
It's very hacky, but you can create a custom fisher.test
function that returns the OR as the "p-value", and use this function instead of fisher.test
when using CreateTableOne
. I haven't tested it, so let me know how it goes.
my_or_fisher <- function(...) {
out <- fisher.test(...)
out$p.value <- out$estimate
out
}