library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.6
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(flextable)
## 
## Dołączanie pakietu: 'flextable'
## Następujący obiekt został zakryty z 'package:purrr':
## 
##     compose
library(lubridate)
## 
## Dołączanie pakietu: 'lubridate'
## Następujące obiekty zostały zakryte z 'package:base':
## 
##     date, intersect, setdiff, union
options(digits = 3)
data <- read_csv("data/results-survey811918.csv")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_character(),
##   id = col_double(),
##   submitdate = col_datetime(format = ""),
##   lastpage = col_double(),
##   seed = col_double(),
##   Inst = col_logical()
## )
## ℹ Use `spec()` for the full column specifications.

Wyniki ankiety

data <- data %>% filter((`attCheck1[Satz]` == 0) & (`attCheck2[Satz]` == 'plus2'))
data_long <- pivot_longer(data, cols = ends_with("[Satz]"), names_to = "sentence", values_to = "score")
data_long$score <- recode(data_long$score,
                          `min2` = -2,
                          `min1` = -1,
                          `0` = 0,
                          `plus1` = 1,
                          `plus2` = 2,
                          )
data_long <- data_long %>% rowwise() %>% mutate(popr = str_split(sentence, "X", simplify = T)[3])
summ <- data_long %>%
          filter(! sentence %in% c('attCheck1[Satz]', 'attCheck2[Satz]') ) %>%
          group_by(popr, sentence) %>% summarise(M = mean(score), SD = sd(score)) %>% arrange(M) 
## `summarise()` has grouped output by 'popr'. You can override using the `.groups` argument.
pvals <- data_long %>% filter(! sentence %in% c('attCheck1[Satz]', 'attCheck2[Satz]') ) %>%
          group_by(popr, sentence) %>% rstatix::t_test(data = ., score ~ 1, mu = 0) %>%
          rowwise() %>%
          mutate(p = scales::pvalue(p))
left_join(summ, pvals, by = c('sentence', 'popr')) %>% select(popr, sentence, M, SD, p) %>% flextable()