-
Notifications
You must be signed in to change notification settings - Fork 26
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
P-values for each individual row #120
Comments
It is possible. Can you explain exactly how you are computing the p-value, like how did you get 0.011 for the third p-value (Hispanic)? |
Thanks for the detailed explanation. I just wanted to be sure because I wasn't getting 0.011, which turned out to be incorrect. So, here's how you can do it (basically, I just modified one line from the example in 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 individual chi-squared tests for each category
p <- sapply(levels(y), function(z) chisq.test(table(y==z, g), correct=F)$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(~ age + race | treat, data=lalonde, overall=F, extra.col=list(`P-value`=pvalue)) Just a note of caution though, that the p-values for the different categories won't be independent of each other. EDIT: Note that I used |
What do you mean when you say that the p-values for the different categories will not be independent of each other? Thank you so much for your help! |
Hello Benjamin!
Thank you so much for this wonderful package and your incredible work. I have read your guide titled "Using the table1 Package to Create HTML Tables of Descriptive Statistics" and have run into a question in regards to the section titled "Example: a column of p-values".
I have used this to add a column of p-values in the past, but I run into an issue with it using the entire column for each p-value. Here is a screenshot from your guide:
It generates a p-value that is performing a chi-square of the entire "Race" column (ie. "White", "Black", AND "Hispanic") of "<0.001". If I want to look at each specific race and how it varies for the Control and Treatment groups, I would not be able to do that.
In that case, I would need a separate p-value for "White", a separate p-value for "Black, and a separate p-value for "Hispanic" (three separate chi-square analyses). I have tried different solutions to separate the chi-square analyses but none of them have worked, and I am quite unfamiliar with how to do this properly in table1. This is how the output would ideally look (chi-square analysis for each race category separately) if I could get it to work:
Is it possible for table1 to do this? Or is it a lost cause?
Thank you so much in advance.
Warmest regards,
Vaish
The text was updated successfully, but these errors were encountered: