benjaminrich / table1

79 stars 26 forks source link

Adjusted p-values in extra column #129

Open myjulo opened 3 months ago

myjulo commented 3 months ago

Is there a way to apply a p-value adjustment on all p-values in the extra column? For by incorporating the p.adjust function somewhere? I am assuming that the pvalue function from the vignette is doing it's calculations per row, so it wouldn't make sense there. Is it possible anywhere in the arguments for the table1 function?

pvalue function from the vignette: pvalue <- function(x, ...) {

Construct vectors of data y, and groups (strata) g

y <- unlist(x)
g <- factor(rep(1:length(x), times=sapply(x, length)))
if (is.numeric(y)) {
    # 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
}
# 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.
c("", sub("<", "&lt;", format.pval(p, digits=3, eps=0.001)))

}

table1 example from the vignette: table1(~ age + race + married + nodegree + re74 + re75 + re78 | treat, data=lalonde, overall=F, extra.col=list(P-value=pvalue))

Link: https://cran.r-project.org/web/packages/table1/vignettes/table1-examples.html#example-a-column-of-p-values

myjulo commented 1 month ago

I posted a slightly adjusted version of the question above on Stackoverflow: https://stackoverflow.com/questions/78993102/r-table1-package-adjusted-p-values-in-extra-column