Reputation: 415
Please see my sample data below:
dad <- data.frame(type = c("new", "new", "old", "new", "old", "new", "old", "old", "new", "new"),
outcome = c(68,76,57,67,89,98,99,120,99,67),
loan1=c(98000 ,56668,67000,87999,87945, 89768, 65738, 87547, 78937, 20000),
loan2 =c(56768,45679, 23453, 87673, 56749, 45783, 67836, 54673, 45379, 78483),
house=c("semi", "detached", "town", "semi", "town", "town", "semi", "detached", "semi", "town"))
I am trying to run separate multivariate linear regression models for each house and would like to correct for multiple testing by adjusting the p-values with Bonferroni correction. In my actual dataset I am running 7 backward stepwise selection models (initially starting with the same independent variables) to come to the final multivariate regression models. Every model has the same outcome as well. I am wondering if there is a way to get the adjusted p-value with the below code at all? Any help would be appreciated, thank you!
#Example
full <- lm(outcome ~loan1+loan2,data = subset(dad, house=="semi"))
summary(full)
tab_model(full)
Upvotes: 0
Views: 1549
Reputation: 9878
Try p.adjust()
. Call it with the argument method = 'bonferroni'
library(purrr)
Unnadjusted p.values:
full |>
summary() |>
pluck(coefficients) |>
(\(x) x[-1, 4])()
loan1 loan2
0.0814972 0.1389506
adjusted p.values:
full |>
summary() |>
pluck(coefficients) |>
(\(x) x[-1, 4])() |>
p.adjust(method = 'bonferroni')
loan1 loan2
0.1629944 0.2779012
Upvotes: 0
Reputation: 22034
The tab_model()
function has an argument for adjusted p-values.
library(sjPlot)
dad <- data.frame(type = c("new", "new", "old", "new", "old", "new", "old", "old", "new", "new"),
outcome = c(68,76,57,67,89,98,99,120,99,67),
loan1=c(98000 ,56668,67000,87999,87945, 89768, 65738, 87547, 78937, 20000),
loan2 =c(56768,45679, 23453, 87673, 56749, 45783, 67836, 54673, 45379, 78483),
house=c("semi", "detached", "town", "semi", "town", "town", "semi", "detached", "semi", "town"))
full <- lapply(unique(dad$house), \(h){
args <- list(
formula = outcome ~ loan1 + loan2,
data= subset(dad, house == h))
do.call(lm, args)
})
tab_model(full[[1]], p.adjust="bonferroni")
tab_model(full[[2]], p.adjust="bonferroni")
tab_model(full[[3]], p.adjust="bonferroni")
})
Upvotes: 1