-
Notifications
You must be signed in to change notification settings - Fork 27
Incorporating both p-values and the overall column #52
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
Comments
Yes. You can do it like this: pvalue <- function(x, ...) {
x <- x[-length(x)] # Remove "overall" group
# 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 an ANOVA
p <- summary(aov(y ~ g))[[1]][["Pr(>F)"]][1]
} 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("<", "<", format.pval(p, digits=3, eps=0.001)))
}
table1(~ Q1 + Q2 | ano, data=data, overall="Total",
render.missing=NULL, render.categorical="FREQ (PCTnoNA%)",
extra.col=list(`Valor-p`=pvalue), extra.col.pos=4) |
Works like a charm, thank you so much for the quick reply. Would be a great addition to this statement "These are the only 2 elements the list will have, because we will use overall=F in table1 (otherwise, there would be a third element in the list corresponding to the overall column). " here https://cran.r-project.org/web/packages/table1/vignettes/table1-examples.html Just to let you/anyone else who stumbles on this issue, I had trouble adding p-values at all using the table1 package I'd downloaded from CRAN, and had to uninstall that and install directly from here on Github using remotes::install_github("benjaminrich/table1"). I don't know if it's just me or anyone else had the same issue, but putting this out here in case it helps anyone. |
It's a great function. I just wondering how do we pass aov(y ~ g + a + b + c)? I tried exact function but the table1 function is showing me an error message: |
Thank you all for posting this! It helps me understand the function better. pvalue <- function(x, ...) { |
Thank you for posting this. I modified it for my needs right now and wanted to share. I added a check before doing the anova to make sure there are 2 or more strata. I also added for the categorical variables if any cell values are <10 to do fishers.test() and if not then do chisq.test(). I made two functions one for my tables that don't have the overall col and one for the ones that do have it. Idk if anyone else will find this helpful but just incase. I definitely found what yall posted helpful :) Also I'm new to stats so if I got anything wrong please tell me without being rude, I'm just a worm!
|
Hi, thanks for a great tool. I thought this wasn't possible to do, and have been trying to do it manually, until I saw this: #21
Does anyone know how to generate a table1 that incorporates both p-values and the overall column as that particular user does in the example shown? Thanks!
The text was updated successfully, but these errors were encountered: