data %>% group_by(neg) %>% summarise(
  percentage_yes = mean(resp, na.rm = T),
  sd_yes = sd(resp, na.rm = T),
  n = n(),
) %>% flextable() %>%
  theme_vanilla() %>%
  fit_to_width(7.5)
ggbarplot(data = data,
          y = "resp",
          x = "neg",
          add = "mean_se",
          fill = "neg"
          )
## Warning: Removed 22 rows containing non-finite values (stat_summary).

contrasts(data$neg) <- MASS::contr.sdif(4)
fit <- glmer(resp ~ neg + (1|idx) + (1+neg|nr_uczestnika), data=data, family="binomial", nAGQ=0)
summary(fit)
## Generalized linear mixed model fit by maximum likelihood (Adaptive
##   Gauss-Hermite Quadrature, nAGQ = 0) [glmerMod]
##  Family: binomial  ( logit )
## Formula: resp ~ neg + (1 | idx) + (1 + neg | nr_uczestnika)
##    Data: data
## 
##      AIC      BIC   logLik deviance df.resid 
##      878      950     -424      848      827 
## 
## Scaled residuals: 
##    Min     1Q Median     3Q    Max 
## -2.817 -0.461  0.309  0.513  3.515 
## 
## Random effects:
##  Groups        Name        Variance Std.Dev. Corr             
##  idx           (Intercept) 0.1346   0.367                     
##  nr_uczestnika (Intercept) 0.7984   0.894                     
##                neg2-1      0.0409   0.202    -0.99            
##                neg3-2      1.5125   1.230     0.71 -0.79      
##                neg4-3      0.1605   0.401    -0.95  0.98 -0.89
## Number of obs: 842, groups:  idx, 144; nr_uczestnika, 24
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)   0.0255     0.2058    0.12     0.90    
## neg2-1        0.1330     0.2594    0.51     0.61    
## neg3-2       -2.4532     0.3673   -6.68  2.4e-11 ***
## neg4-3       -0.3963     0.2814   -1.41     0.16    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr) neg2-1 neg3-2
## neg2-1 -0.134              
## neg3-2  0.444 -0.433       
## neg4-3 -0.244  0.046 -0.527