1

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 answers into numerical scores.

I want to test for each course for each question type whether there is a difference in scores between pre and post-term surveys. I also want to add Bonferroni corrections 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.

Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
yuliaUU
  • 1,581
  • 2
  • 12
  • 33

1 Answers1

1

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          
akrun
  • 874,273
  • 37
  • 540
  • 662
  • 1
    yo @akrun ! always the real mvp for all my questions. nice to see here. hope you see this before its deleted :) . cheers – Pauliinaa Jul 28 '22 at 10:46