1
votes

I have a survey that was conducted in 3 different classes ( math, phys, bio) at the beginning and at the end of the semester ( pre and post). In the survey, there were 3 groups of questions (A, B, C) and a Likert-type scale. I converted all the answer into the numerical score

I want to test for each course for each question type whether the is a difference in score between pre and post-term survey. I also want to add Bonferroni correction here to account for multiple comparisons:

library(rstatix) 
library(tidyr) 
df= data.frame(
survey = rep(c("pre","post"),60),
subject = rep(c("bio", "math", "phys"),40),
q = rep(c("A", "B", "C"),40),
score =  sample(x=1:7, size = 120, replace = TRUE))
df

df %>%  group_by(subject, q) %>% 
  t_test(score ~ survey, paired = TRUE, p.adjust.method = "bonferroni") %>%
  add_significance()

However, p.adjust.method = "bonferroni", does not produce any output. I am not sure why.

1
What do you mean by "does not produce any output"? Is there a way to add that "no output" to your question? - jay.sf
it just gives p-values and no column for adjusted p values is created - yuliaUU

1 Answers

0
votes

We could use adjust_pvalue

library(dplyr)
library(rstatix)
df %>% 
   group_by(subject, q) %>% 
   t_test(score ~ survey, paired = TRUE) %>%
   adjust_pvalue(method = 'bonferroni') %>%
   add_significance()

-output

# A tibble: 3 x 12
#  subject q     .y.   group1 group2    n1    n2 statistic    df     p p.adj p.adj.signif
#* <chr>   <chr> <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl> <dbl> <dbl> <chr>       
#1 bio     A     score post   pre       20    20     1.52     19 0.145 0.435 ns          
#2 math    B     score post   pre       20    20    -0.543    19 0.594 1     ns          
#3 phys    C     score post   pre       20    20     1.24     19 0.232 0.696 ns