---
title: "Supplementary online material (SOM5): Quality of the two experimental questions"
subtitle: "Comparing Control, Choice, PushDictation and PushRecording groups"
output:
  html_document: default
  word_document: default
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(
  echo = FALSE,
  cache = TRUE,
  cache.extra = rnorm(1)
)
```


```{r libraries, include = FALSE, cache = FALSE}
library(haven) # for dealing with dataframe
library(tidyverse) # for data handling
library(rstatix) # Para t-test and pr tests within all pairs of groups
library(lubridate) #for dates
library(knitr) #for creating tables
library(kableExtra) #to make changes in style of the tables
library(psych)#for cohen's kappa
library(irr)#alternative cohen's kappa
library(stargazer)#to create table with several regressions
library(readr)#to read data
```


```{r load_data, include = FALSE, cache = TRUE}
#Define path
#path <- "yourpath" #Replace "yourpath" with the place where the data is saved
data= read_rds(file.path(path,"datafinalALLCODESregnoID.rds"))
```
<br>
<br>

## Table of Contents

- [InterRater Reliability (IRR)](#interrater-reliability-(irr))
<br>
  - [IRR WHYTRANSP](#irr-whytransp)
<br>
  - [IRR WHYTRUST](#irr-whytrust)
<br>

- [Valid answers](#valid-answers)
<br>
  - [Valid WHYTRANSP](#valid-whytransp)
<br>
  - [Valid WHYTRUST](#valid-whytrust)
<br>
  - [Main results Valid by subgroups (text versus voice)](#main-results-valid-by-subgroups-text-versus-voice)
<br>

- [Aspects answered](#aspects-answered)
<br>
  - [Aspects WHYTRANSP](#aspects-whytransp)
<br>
  - [Aspects WHYTRUST](#aspects-whytrust)
<br>
  - [Main results Aspects answered by subgroups (text versus voice)](#main-results-aspects-answered-by-subgroups-text-versus-voice)
<br>
- [Abbreviations](#abbreviations)
<br>
  - [Abbreviations WHYTRANSP](#abbreviations-whytransp)
<br>
  - [Abbreviations WHYTRUST](#abbreviations-whytrust)
<br>
- [Problems detected](#problems-detected)
<br>
  - [Problems WHYTRANSP](#problems-whytransp)
<br>
  - [Problems WHYTRUST](#problems-whytrust)
<br>
  - [Main results Problems detected by subgroups (text versus voice)](#main-results-problems-detected-by-subgroups-text-versus-voice)
<br>
- [Number of themes](#number-of-themes)
<br>
  - [No. themes WHYTRANSP](#no.-themes-whytransp)
<br>
  - [No. themes WHYTRUST](#no.-themes-whytrust)
  <br>
  - [Main results No. themes by subgroups (text versus voice)](#main-results-no.-themes-by-subgroups-text-versus-voice)
<br>
- [Number of characters](#number-of-characters)
<br>
  - [No. characters WHYTRANSP](#no.-characters-whytransp)
<br>
  - [No. characters WHYTRUST](#no.-characters-whytrust)
  <br>
  - [Main results No. characters by subgroups (text versus voice)](#main-results-no.-characters-by-subgroups-text-versus-voice)
<br>
- [Completion time](#completion-time)
<br>
  - [Focus time WHYTRANSP](#focus-time-whytransp)
<br>
  - [Focus time WHYTRUST](#focus-time-whytrust)
<br>


```{r create_functions, include = FALSE, cache = TRUE}
#Function to get the n and proportions
prop=function(data, var){
  data %>% 
    drop_na({{var}}) %>%
    group_by({{var}}) %>%
    summarise(n=n()) %>% 
    mutate(n_cum=cumsum(n), f=n/
             sum(n), f_cum=cumsum(f)) %>%
    print(n = 80)
}

#Function for proportions but by group
propby=function(data, var1, var2){
  data %>% 
    drop_na({{var1}}, {{var2}}) %>%
    group_by({{var1}}, {{var2}}) %>%
    summarise(n=n()) %>% 
    mutate(n_cum=cumsum(n), f=n/
             sum(n), f_cum=cumsum(f))#%>%
    #print(n = 80)
}

#Function to test each pairs of groups for proportions
proptest = function(data,valuevar,grupvar) {
  data %>% 
    filter(!is.na({{valuevar}})) %>% #needed when there are NAs
    filter(!is.na({{grupvar}})) %>% #when also NA in group var
    group_by(rowname={{grupvar}},{{valuevar}}) %>%
    count() %>% 
    pivot_wider(names_from = {{valuevar}},values_from = "n") %>%
    mutate( across(.fns = ~ ifelse(is.na(.x),0,.x))) %>%       
    column_to_rownames() %>% 
    pairwise_prop_test() %>% 
    mutate(
    p.signif=case_when(
        p<0.001 ~ "***",
        p<0.01 ~ "**",
        p<0.05 ~ "*",
        TRUE ~ "ns"),
        .before=4
      )
}

#Function for means, st dev, etc.
meanandmore=function(data, var){
  data %>% 
    filter(!is.na({{var}})) %>% #needed when there are NAs
    summarise(mean=mean({{var}}), stdev=sd({{var}}), min=min({{var}}), max=max({{var}}), median=median({{var}}))
}

#Function for means, st dev, etc. but by group
meanandmoreby=function(data, var1, var2){
  data %>% 
    filter(!is.na({{var1}})) %>% #needed when there are NAs
    group_by({{var2}}) %>%
    summarise(mean=mean({{var1}}), stdev=sd({{var1}}), min=min({{var1}}), max=max({{var1}}), median=median({{var1}}))
}

```

<br>
<br>

# InterRater Reliability (IRR)

### <i>IRR WHYTRANSP</i>

```{r prep_IRR, message=FALSE, warning=FALSE, include = FALSE, cache = TRUE}
# Create a list of data frames for each variable of interest
metrics_list <- list(
  VALID_TRANSP = data %>% select(VALID_TRANSPC1, VALID_TRANSPC2),
  ASPECTS_TRANSP = data %>% select(ASPECTS_TRANSPC1, ASPECTS_TRANSPC2),
  ABBR_TRANSP = data %>% select(ABBR_TRANSPC1, ABBR_TRANSPC2),
  PB_TRANSP = data %>% select(PB1_TRANSPC1, PB1_TRANSPC2),
  NTHEMES_TRANSP = data %>% select(NTHEMES_TRANSP1b, NTHEMES_TRANSP2b)
)

# Custom function to calculate Cohen's kappa for a data frame
calculate_kappa <- function(data) {
  if (nrow(data) > 0) {
    cohen.kappa(data)$kappa
  } else {
    NA
  }
}

# Custom function to calculate percentage of agreement for a data frame
calculate_agreement_percentage <- function(data) {
  if (nrow(data) > 0) {
    agree(data)$value
  } else {
    NA
  }
}

# Calculate Cohen's kappa and agreement for each metric
kappa_values <- map_dbl(metrics_list, calculate_kappa)
agreement_values <- map_dbl(metrics_list, calculate_agreement_percentage)

# Create a tibble with the results
results_tibble <- tibble(
  Metric = names(metrics_list),
  Cohen_Kappa = round(kappa_values,2),
  Agreement_Percentage = round(agreement_values, 2)
)
```

<center><b>
Cohen's Kappa and percentage of agreement across Coders 1 and 2 for each variable studied
</center></b>
```{r results_IRR, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
kable(results_tibble, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(results_tibble), align = "c")
```

<br>
<br>

### <i>IRR WHYTRUST</i>


```{r prep_IRR2, message=FALSE, warning=FALSE, include = FALSE, cache = TRUE}
# Create a list of data frames for each variable of interest
metrics_list2 <- list(
  VALID_TRUST = data %>% select(VALID_TRUSTC1, VALID_TRUSTC2),
  ASPECTS_TRUST  = data %>% select(ASPECTS_TRUSTC1, ASPECTS_TRUSTC2),
  ABBR_TRUST  = data %>% select(ABBR_TRUSTC1, ABBR_TRUSTC2),
  PB_TRUST  = data %>% select(PB1_TRUSTC1, PB1_TRUSTC2),
  NTHEMES_TRUST = data %>% select(NTHEMES_TRUST1b, NTHEMES_TRUST2b)
)

# Calculate Cohen's kappa and agreement for each metric
kappa_values2 <- map_dbl(metrics_list2, calculate_kappa)
agreement_values2 <- map_dbl(metrics_list2, calculate_agreement_percentage)

# Create a tibble with the results
results_tibble2 <- tibble(
  Metric = names(metrics_list2),
  Cohen_Kappa = round(kappa_values2,2),
  Agreement_Percentage = round(agreement_values2, 2)
)
```

<center><b>
Cohen's Kappa and percentage of agreement across Coders 1 and 2 for each variable studied
</center></b>
```{r results_IRR2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
kable(results_tibble2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(results_tibble2), align = "c")
```

<br>
<br>




# Valid answers

<i>

### Valid WHYTRANSP

</i>

### Proportions per group WHYTRANSP


<center><b>
Proportions of non sense, not in line, DK and valid answers using the codes of Coder 1
</center></b>

```{r prep_valid1, message=FALSE, include = FALSE, cache = TRUE}
tibbleValidC1 = propby(data, GRUPO, VALID_TRANSPC1)
# Select relevant columns and reshape the data using spread
table_dataValidC1 <-  tibbleValidC1 %>%
    select(VALID_TRANSPC1, GRUPO, f) %>%
     spread(key = GRUPO, value = f) %>%
     arrange(VALID_TRANSPC1)

#Extract n_cum
max_n_cum_values_ValidC1 <- tibbleValidC1 %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_ValidC1 <- max_n_cum_values_ValidC1$max_n_cum[max_n_cum_values_ValidC1$GRUPO == "Control"]
pushdictation_max_n_cum_ValidC1 <- max_n_cum_values_ValidC1$max_n_cum[max_n_cum_values_ValidC1$GRUPO == "PushDictation"]
pushrecording_max_n_cum_ValidC1 <- max_n_cum_values_ValidC1$max_n_cum[max_n_cum_values_ValidC1$GRUPO == "PushRecording"]
choice_max_n_cum_ValidC1 <- max_n_cum_values_ValidC1$max_n_cum[max_n_cum_values_ValidC1$GRUPO == "Choice"]

#Put together last row
total_obs_row_ValidC1 <- tibble(
  VALID_TRANSPC1 = "Number of observations",
  Control = control_max_n_cum_ValidC1,
  PushDictation = pushdictation_max_n_cum_ValidC1,
  PushRecording = pushrecording_max_n_cum_ValidC1,
  Choice = choice_max_n_cum_ValidC1
)

#Put together with the rest
table_with_total_ValidC1 = bind_rows(
  table_dataValidC1 %>% 
  mutate(across(-VALID_TRANSPC1, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
  mutate_all(as.character),
  total_obs_row_ValidC1 %>% 
  mutate_all(as.character)
  )%>%
select(1, 2, 5, 3, 4)
```

```{r result_valid1, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_ValidC1, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```



<center><b>
Proportions of non sense, not in line, DK and valid answers using the codes of Coder 2
</center></b>

```{r prep_valid2, message=FALSE, include = FALSE, cache = TRUE}
tibbleValidC2 = propby(data, GRUPO, VALID_TRANSPC2)
# Select relevant columns and reshape the data using spread
table_dataValidC2 <-  tibbleValidC2 %>%
  select(VALID_TRANSPC2, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(VALID_TRANSPC2)

#Extract n_cum
max_n_cum_values_ValidC2 <- tibbleValidC2 %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_ValidC2 <- max_n_cum_values_ValidC2$max_n_cum[max_n_cum_values_ValidC2$GRUPO == "Control"]
pushdictation_max_n_cum_ValidC2 <- max_n_cum_values_ValidC2$max_n_cum[max_n_cum_values_ValidC2$GRUPO == "PushDictation"]
pushrecording_max_n_cum_ValidC2 <- max_n_cum_values_ValidC2$max_n_cum[max_n_cum_values_ValidC2$GRUPO == "PushRecording"]
choice_max_n_cum_ValidC2 <- max_n_cum_values_ValidC2$max_n_cum[max_n_cum_values_ValidC2$GRUPO == "Choice"]

#Put together last row
total_obs_row_ValidC2 <- tibble(
  VALID_TRANSPC2 = "Number of observations",
  Control = control_max_n_cum_ValidC2,
  PushDictation = pushdictation_max_n_cum_ValidC2,
  PushRecording = pushrecording_max_n_cum_ValidC2,
  Choice = choice_max_n_cum_ValidC2
)

#Put together with the rest
table_with_total_ValidC2 = bind_rows(
  table_dataValidC2 %>% 
    mutate(across(-VALID_TRANSPC2, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_ValidC2 %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_valid2, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_ValidC2, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

<center><b>
Proportions of non sense, not in line, DK and valid answers using the codes of Coder 3
</center></b>

```{r prep_valid3, message=FALSE, include = FALSE, cache = TRUE}
tibbleValidC3 = propby(data, GRUPO, VALID_TRANSPC3)
# Select relevant columns and reshape the data using spread
table_dataValidC3 <-  tibbleValidC3 %>%
  select(VALID_TRANSPC3, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(VALID_TRANSPC3)

#Extract n_cum
max_n_cum_values_ValidC3 <- tibbleValidC3 %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_ValidC3 <- max_n_cum_values_ValidC3$max_n_cum[max_n_cum_values_ValidC3$GRUPO == "Control"]
pushdictation_max_n_cum_ValidC3 <- max_n_cum_values_ValidC3$max_n_cum[max_n_cum_values_ValidC3$GRUPO == "PushDictation"]
pushrecording_max_n_cum_ValidC3 <- max_n_cum_values_ValidC3$max_n_cum[max_n_cum_values_ValidC3$GRUPO == "PushRecording"]
choice_max_n_cum_ValidC3 <- max_n_cum_values_ValidC3$max_n_cum[max_n_cum_values_ValidC3$GRUPO == "Choice"]

#Put together last row
total_obs_row_ValidC3 <- tibble(
  VALID_TRANSPC3 = "Number of observations",
  Control = control_max_n_cum_ValidC3,
  PushDictation = pushdictation_max_n_cum_ValidC3,
  PushRecording = pushrecording_max_n_cum_ValidC3,
  Choice = choice_max_n_cum_ValidC3
)

#Put together with the rest
table_with_total_ValidC3 = bind_rows(
  table_dataValidC3 %>% 
    mutate(across(-VALID_TRANSPC3, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_ValidC3 %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_valid3, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_ValidC3, format = "html", col.names = c("Coder 3", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

### Tests of significance across groups WHYTRANSP

```{r dummies_valid, message=FALSE, include = FALSE, cache = TRUE}

#use the proptest function but need first to create dummies for each of the 4 situations (nonsense, not in line...) and coder

data <- data %>%
     mutate(nonsense_WHYTRANSPC1 = ifelse(VALID_TRANSPC1 == "1 Non sense", 1, 0),
           notinline_WHYTRANSPC1 = ifelse(VALID_TRANSPC1 == "2 Not in line", 1, 0),
           DK_WHYTRANSPC1 = ifelse(VALID_TRANSPC1 == "3 DK", 1, 0),
            valid_WHYTRANSPC1 = ifelse(VALID_TRANSPC1 == "4 Valid", 1, 0),
            )

data <- data %>%
     mutate(nonsense_WHYTRANSPC2 = ifelse(VALID_TRANSPC2 == "1 Non sense", 1, 0),
            notinline_WHYTRANSPC2 = ifelse(VALID_TRANSPC2 == "2 Not in line", 1, 0),
            DK_WHYTRANSPC2 = ifelse(VALID_TRANSPC2 == "3 DK", 1, 0),
            valid_WHYTRANSPC2 = ifelse(VALID_TRANSPC2 == "4 Valid", 1, 0),
            )

data <- data %>%
     mutate(nonsense_WHYTRANSPC3 = ifelse(VALID_TRANSPC3 == "1 Non sense", 1, 0),
            notinline_WHYTRANSPC3 = ifelse(VALID_TRANSPC3 == "2 Not in line", 1, 0),
            DK_WHYTRANSPC3 = ifelse(VALID_TRANSPC3 == "3 DK", 1, 0),
            valid_WHYTRANSPC3 = ifelse(VALID_TRANSPC3 == "4 Valid", 1, 0),
            )
```

<center><b>
Tests non sense Coder 1
</center></b>
```{r nonsense_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nonsenseC1=proptest(data, nonsense_WHYTRANSPC1, GRUPO)
kable(nonsenseC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nonsenseC1), align = "c")
```

<center><b>
Tests non sense Coder 2
</center></b>
```{r nonsense_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nonsenseC2=proptest(data, nonsense_WHYTRANSPC2, GRUPO)
kable(nonsenseC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nonsenseC2), align = "c")
```

<center><b>
Tests non sense Coder 3
</center></b>
```{r nonsense_c3, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nonsenseC3=proptest(data, nonsense_WHYTRANSPC3, GRUPO)
kable(nonsenseC3, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nonsenseC3), align = "c")
```

<center><b>
Tests not in line Coder 1
</center></b>
```{r notinline_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
notinlineC1=proptest(data, notinline_WHYTRANSPC1, GRUPO)
kable(notinlineC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(notinlineC1), align = "c")
```

<center><b>
Tests not in line Coder 2
</center></b>
```{r notinline_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
notinlineC2=proptest(data, notinline_WHYTRANSPC2, GRUPO)
kable(notinlineC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(notinlineC2), align = "c")
```

<center><b>
Tests not in line Coder 3
</center></b>
```{r notinline_c3, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
notinlineC3=proptest(data, notinline_WHYTRANSPC3, GRUPO)
kable(notinlineC3, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(notinlineC3), align = "c")
```

<center><b>
Tests DK Coder 1
</center></b>
```{r DK_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
dkC1=proptest(data, DK_WHYTRANSPC1, GRUPO)
kable(dkC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(dkC1), align = "c")
```

<center><b>
Tests DK Coder 2
</center></b>
```{r DK_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
dkC2=proptest(data, DK_WHYTRANSPC2, GRUPO)
kable(dkC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(dkC2), align = "c")
```

<center><b>
Tests DK Coder 3
</center></b>
```{r DK_c3, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
dkC3=proptest(data, DK_WHYTRANSPC3, GRUPO)
kable(dkC3, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(dkC3), align = "c")
```

<center><b>
Tests valid Coder 1
</center></b>
```{r valid_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
validC1=proptest(data, valid_WHYTRANSPC1, GRUPO)
kable(validC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(validC1), align = "c")
```

<center><b>
Tests valid Coder 2
</center></b>
```{r valid_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
validC2=proptest(data, valid_WHYTRANSPC2, GRUPO)
kable(validC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(validC2), align = "c")
```

<center><b>
Tests valid Coder 3
</center></b>
```{r valid_c31, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
validC3=proptest(data, valid_WHYTRANSPC3, GRUPO)
kable(validC3, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(validC3), align = "c")
```

<br>

<i>

### Valid WHYTRUST

</i>

### Proportions per group WHYTRUST

<center><b>
Proportions of non sense, not in line, DK and valid answers using the codes of Coder 1
</center></b>

```{r prep_valid1tr, message=FALSE, include = FALSE, cache = TRUE}
tibbleValidC1tr = propby(data, GRUPO, VALID_TRUSTC1)
# Select relevant columns and reshape the data using spread
table_dataValidC1tr <-  tibbleValidC1tr %>%
    select(VALID_TRUSTC1, GRUPO, f) %>%
     spread(key = GRUPO, value = f) %>%
     arrange(VALID_TRUSTC1)

#Extract n_cum
max_n_cum_values_ValidC1tr <- tibbleValidC1tr %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_ValidC1tr <- max_n_cum_values_ValidC1tr$max_n_cum[max_n_cum_values_ValidC1tr$GRUPO == "Control"]
pushdictation_max_n_cum_ValidC1tr <- max_n_cum_values_ValidC1tr$max_n_cum[max_n_cum_values_ValidC1tr$GRUPO == "PushDictation"]
pushrecording_max_n_cum_ValidC1tr <- max_n_cum_values_ValidC1tr$max_n_cum[max_n_cum_values_ValidC1tr$GRUPO == "PushRecording"]
choice_max_n_cum_ValidC1tr <- max_n_cum_values_ValidC1tr$max_n_cum[max_n_cum_values_ValidC1tr$GRUPO == "Choice"]

#Put together last row
total_obs_row_ValidC1tr <- tibble(
  VALID_TRUSTC1 = "Number of observations",
  Control = control_max_n_cum_ValidC1tr,
  PushDictation = pushdictation_max_n_cum_ValidC1tr,
  PushRecording = pushrecording_max_n_cum_ValidC1tr,
  Choice = choice_max_n_cum_ValidC1tr
)

#Put together with the rest
table_with_total_ValidC1tr = bind_rows(
  table_dataValidC1tr %>% 
  mutate(across(-VALID_TRUSTC1, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
  mutate_all(as.character),
  total_obs_row_ValidC1tr %>% 
  mutate_all(as.character)
  )%>%
select(1, 2, 5, 3, 4)
```

```{r result_valid1tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_ValidC1tr, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

<center><b>
Proportions of non sense, not in line, DK and valid answers using the codes of Coder 2
</center></b>

```{r prep_valid2tr, message=FALSE, include = FALSE, cache = TRUE}
tibbleValidC2tr = propby(data, GRUPO, VALID_TRUSTC2)
# Select relevant columns and reshape the data using spread
table_dataValidC2tr <-  tibbleValidC2tr %>%
  select(VALID_TRUSTC2, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(VALID_TRUSTC2)

#Extract n_cum
max_n_cum_values_ValidC2tr <- tibbleValidC2tr %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_ValidC2tr <- max_n_cum_values_ValidC2tr$max_n_cum[max_n_cum_values_ValidC2tr$GRUPO == "Control"]
pushdictation_max_n_cum_ValidC2tr <- max_n_cum_values_ValidC2tr$max_n_cum[max_n_cum_values_ValidC2tr$GRUPO == "PushDictation"]
pushrecording_max_n_cum_ValidC2tr <- max_n_cum_values_ValidC2tr$max_n_cum[max_n_cum_values_ValidC2tr$GRUPO == "PushRecording"]
choice_max_n_cum_ValidC2tr <- max_n_cum_values_ValidC2tr$max_n_cum[max_n_cum_values_ValidC2tr$GRUPO == "Choice"]

#Put together last row
total_obs_row_ValidC2tr <- tibble(
  VALID_TRUSTC2 = "Number of observations",
  Control = control_max_n_cum_ValidC2tr,
  PushDictation = pushdictation_max_n_cum_ValidC2tr,
  PushRecording = pushrecording_max_n_cum_ValidC2tr,
  Choice = choice_max_n_cum_ValidC2tr
)

#Put together with the rest
table_with_total_ValidC2tr = bind_rows(
  table_dataValidC2tr %>% 
    mutate(across(-VALID_TRUSTC2, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_ValidC2tr %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_valid2tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_ValidC2tr, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

<center><b>
Proportions of non sense, not in line, DK and valid answers using the codes of Coder 3
</center></b>

```{r prep_valid3tr, message=FALSE, include = FALSE, cache = TRUE}
tibbleValidC3tr = propby(data, GRUPO, VALID_TRUSTC3)
# Select relevant columns and reshape the data using spread
table_dataValidC3tr <-  tibbleValidC3tr %>%
  select(VALID_TRUSTC3, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(VALID_TRUSTC3)

#Extract n_cum
max_n_cum_values_ValidC3tr <- tibbleValidC3tr %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_ValidC3tr <- max_n_cum_values_ValidC3tr$max_n_cum[max_n_cum_values_ValidC3tr$GRUPO == "Control"]
pushdictation_max_n_cum_ValidC3tr <- max_n_cum_values_ValidC3tr$max_n_cum[max_n_cum_values_ValidC3tr$GRUPO == "PushDictation"]
pushrecording_max_n_cum_ValidC3tr <- max_n_cum_values_ValidC3tr$max_n_cum[max_n_cum_values_ValidC3tr$GRUPO == "PushRecording"]
choice_max_n_cum_ValidC3tr <- max_n_cum_values_ValidC3tr$max_n_cum[max_n_cum_values_ValidC3tr$GRUPO == "Choice"]

#Put together last row
total_obs_row_ValidC3tr <- tibble(
  VALID_TRUSTC3 = "Number of observations",
  Control = control_max_n_cum_ValidC3tr,
  PushDictation = pushdictation_max_n_cum_ValidC3tr,
  PushRecording = pushrecording_max_n_cum_ValidC3tr,
  Choice = choice_max_n_cum_ValidC3tr
)

#Put together with the rest
table_with_total_ValidC3tr = bind_rows(
  table_dataValidC3tr %>% 
    mutate(across(-VALID_TRUSTC3, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_ValidC3tr %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_valid3tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_ValidC3tr, format = "html", col.names = c("Coder 3", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

### Tests of significance across groups WHYTRUST

```{r dummies_validtr, message=FALSE, include = FALSE, cache = TRUE}

#use the proptest function but need first to create dummies for each of the 4 situations (nonsense, not in line...) and coder

data <- data %>%
     mutate(nonsense_WHYTRUSTC1 = ifelse(VALID_TRUSTC1 == "1 Non sense", 1, 0),
           notinline_WHYTRUSTC1 = ifelse(VALID_TRUSTC1 == "2 Not in line", 1, 0),
           DK_WHYTRUSTC1 = ifelse(VALID_TRUSTC1 == "3 DK", 1, 0),
            valid_WHYTRUSTC1 = ifelse(VALID_TRUSTC1 == "4 Valid", 1, 0),
           previous_WHYTRUSTC1 = ifelse(VALID_TRUSTC1 == "5 Refer previous answer", 1, 0),
           depends_WHYTRUSTC1 = ifelse(VALID_TRUSTC1 == "10 Depends", 1, 0)
            )

data <- data %>%
     mutate(nonsense_WHYTRUSTC2 = ifelse(VALID_TRUSTC2 == "1 Non sense", 1, 0),
            notinline_WHYTRUSTC2 = ifelse(VALID_TRUSTC2 == "2 Not in line", 1, 0),
            DK_WHYTRUSTC2 = ifelse(VALID_TRUSTC2 == "3 DK", 1, 0),
            valid_WHYTRUSTC2 = ifelse(VALID_TRUSTC2 == "4 Valid", 1, 0),
           previous_WHYTRUSTC2 = ifelse(VALID_TRUSTC2 == "5 Refer previous answer", 1, 0),
           depends_WHYTRUSTC2 = ifelse(VALID_TRUSTC2 == "10 Depends", 1, 0)
            )

data <- data %>%
     mutate(nonsense_WHYTRUSTC3 = ifelse(VALID_TRUSTC3 == "1 Non sense", 1, 0),
            notinline_WHYTRUSTC3 = ifelse(VALID_TRUSTC3 == "2 Not in line", 1, 0),
            DK_WHYTRUSTC3 = ifelse(VALID_TRUSTC3 == "3 DK", 1, 0),
            valid_WHYTRUSTC3 = ifelse(VALID_TRUSTC3 == "4 Valid", 1, 0),
           previous_WHYTRUSTC3 = ifelse(VALID_TRUSTC3 == "5 Refer previous answer", 1, 0),
           depends_WHYTRUSTC3 = ifelse(VALID_TRUSTC3 == "10 Depends", 1, 0)
            )
```

<center><b>
Tests non sense Coder 1
</center></b>
```{r nonsense_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nonsenseC1tr=proptest(data, nonsense_WHYTRUSTC1, GRUPO)
kable(nonsenseC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nonsenseC1tr), align = "c")
```

<center><b>
Tests non sense Coder 2
</center></b>
```{r nonsense_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nonsenseC2tr=proptest(data, nonsense_WHYTRUSTC2, GRUPO)
kable(nonsenseC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nonsenseC2tr), align = "c")
```

<center><b>
Tests non sense Coder 3
</center></b>
```{r nonsense_c3tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nonsenseC3tr=proptest(data, nonsense_WHYTRUSTC3, GRUPO)
kable(nonsenseC3tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nonsenseC3tr), align = "c")
```

<center><b>
Tests not in line Coder 1
</center></b>
```{r notinline_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
notinlineC1tr=proptest(data, notinline_WHYTRUSTC1, GRUPO)
kable(notinlineC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(notinlineC1tr), align = "c")
```

<center><b>
Tests not in line Coder 2
</center></b>
```{r notinline_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
notinlineC2tr=proptest(data, notinline_WHYTRUSTC2, GRUPO)
kable(notinlineC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(notinlineC2tr), align = "c")
```

<center><b>
Tests not in line Coder 3
</center></b>
```{r notinline_c3tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
notinlineC3tr=proptest(data, notinline_WHYTRUSTC3, GRUPO)
kable(notinlineC3tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(notinlineC3tr), align = "c")
```

<center><b>
Tests DK Coder 1
</center></b>
```{r DK_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
dkC1tr=proptest(data, DK_WHYTRUSTC1, GRUPO)
kable(dkC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(dkC1tr), align = "c")
```

<center><b>
Tests DK Coder 2
</center></b>
```{r DK_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
dkC2tr=proptest(data, DK_WHYTRUSTC2, GRUPO)
kable(dkC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(dkC2tr), align = "c")
```

<center><b>
Tests DK Coder 3
</center></b>
```{r DK_c3tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
dkC3tr=proptest(data, DK_WHYTRUSTC3, GRUPO)
kable(dkC3tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(dkC3tr), align = "c")
```

<center><b>
Tests depends Coder 1
</center></b>
```{r depends_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
dependsC1tr=proptest(data, depends_WHYTRUSTC1, GRUPO)
kable(dependsC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(dependsC1tr), align = "c")
```

<center><b>
Tests depends Coder 2
</center></b>
```{r depends_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
dependsC2tr=proptest(data, depends_WHYTRUSTC2, GRUPO)
kable(dependsC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(dependsC2tr), align = "c")
```

<center><b>
Tests depends Coder 3
</center></b>
```{r depends_c3tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
dependsC3tr=proptest(data, depends_WHYTRUSTC3, GRUPO)
kable(dependsC3tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(dependsC3tr), align = "c")
```

<center><b>
Tests refer previous answers Coder 1
</center></b>
```{r previous_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
previousC1tr=proptest(data, previous_WHYTRUSTC1, GRUPO)
kable(previousC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(previousC1tr), align = "c")
```

<center><b>
Tests refer previous answers Coder 2:</b> NA (no "previous answer" codes). 
<br>
Note that this code was added when Coder 3 revised the coding of Coders 1 and 2.
</center>
<br>

<center><b>
Tests refer previous answers Coder 3
</center></b>
```{r previous_c3tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
previousC3tr=proptest(data, previous_WHYTRUSTC3, GRUPO)
kable(previousC3tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(previousC3tr), align = "c")
```

<center><b>
Tests valid Coder 1
</center></b>
```{r valid_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
validC1tr=proptest(data, valid_WHYTRUSTC1, GRUPO)
kable(validC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(validC1tr), align = "c")
```

<center><b>
Tests valid Coder 2
</center></b>
```{r valid_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
validC2tr=proptest(data, valid_WHYTRUSTC2, GRUPO)
kable(validC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(validC2tr), align = "c")
```

<center><b>
Tests valid Coder 3
</center></b>
```{r valid_c3tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
validC3tr=proptest(data, valid_WHYTRUSTC3, GRUPO)
kable(validC3tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(validC3tr), align = "c")
```

<br>

<i>

### Main results Valid by subgroups (text versus voice)

</i>

For the Choice, PushDictation, and PushRecording groups, we also examine the proportion of valid responses (in %) by input method: text versus voice. Participants who used both input methods are classified as voice respondents. In the Choice group, the voice subgroup includes both dictation and voice recordings.


<center><b>
Valid WHYTRANSP C3
</center></b>

```{r createsubgroup, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
data <- data %>% 
  mutate(SUBGROUP_TRANSP= case_when(
    GRUPO2TRANSP=="Choice_dictatedonly"|GRUPO2TRANSP=="Choice_recordedonly"|GRUPO2TRANSP=="Choice_several" ~ "Choice_voice",
    GRUPO2TRANSP=="Choice_textonly" ~ "Choice_text",
    GRUPO2TRANSP=="PushDictation_dictated1"|GRUPO2TRANSP=="PushDictation_dictated2"~ "PushDictation_dictated",
    GRUPO2TRANSP=="PushDictation_text2"~ "PushDictation_text",
    GRUPO2TRANSP=="PushRecording_recorded1"|GRUPO2TRANSP=="PushRecording_recordedonly2"|GRUPO2TRANSP=="PushRecording_several2"~ "Pushrecording_recorded",
    GRUPO2TRANSP=="PushRecording_textonly2"~ "PushRecording_text",
  ))
```

```{r valid_subgroup, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
validC3_subgroup <- propby(data, SUBGROUP_TRANSP, valid_WHYTRANSPC3)

validC3_subgroup <- validC3_subgroup %>%
  mutate(
    f = round(f * 100, 1),
    f_cum = round(f_cum * 100, 1)
  )

kable(validC3_subgroup, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(validC3_subgroup), align = "c")
```

<br>

<center><b>
Valid WHYTRUST C3
</center></b>

```{r createsubgrouptr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
 data <- data %>% 
   mutate(SUBGROUP_TRUST= case_when(
     GRUPO2TRUSTNH=="Choice_dictatedonly"|GRUPO2TRUSTNH=="Choice_recordedonly"|GRUPO2TRUSTNH=="Choice_several" ~ "Choice_voice",
     GRUPO2TRUSTNH=="Choice_textonly" ~ "Choice_text",
     GRUPO2TRUSTNH=="PushDictation_dictated1"|GRUPO2TRUSTNH=="PushDictation_dictated2"~ "PushDictation_dictated",
     GRUPO2TRUSTNH=="PushDictation_text2"~ "PushDictation_text",
     GRUPO2TRUSTNH=="PushRecording_recorded1"|GRUPO2TRUSTNH=="PushRecording_recordedonly2"~ "Pushrecording_recorded",
     GRUPO2TRUSTNH=="PushRecording_textonly2"~ "PushRecording_text",
   ))
```

```{r valid_subgrouptr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
validC3_subgrouptr <- propby(data, SUBGROUP_TRUST, valid_WHYTRUSTC3)

validC3_subgrouptr <- validC3_subgrouptr %>%
  mutate(
    f = round(f * 100, 1),
    f_cum = round(f_cum * 100, 1)
  )

kable(validC3_subgrouptr, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(validC3_subgrouptr), align = "c")
```



<br>

<br>


# For valid answers only from now on

<br>

## Aspects answered

<i>

### Aspects WHYTRANSP

</i>

### Proportions per group WHYTRANSP

<center><b>
Answered to both parts of the question, or only part 1 or only part 2, using the codes of Coder 1
</center></b>

```{r prep_Aspects1, message=FALSE, include = FALSE, cache = TRUE}
tibbleAspectsC1 = propby(data, GRUPO, ASPECTS_TRANSPC1)
# Select relevant columns and reshape the data using spread
table_dataAspectsC1 <-  tibbleAspectsC1 %>%
  select(ASPECTS_TRANSPC1, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(ASPECTS_TRANSPC1)

#Extract n_cum
max_n_cum_values_AspectsC1 <- tibbleAspectsC1 %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_AspectsC1 <- max_n_cum_values_AspectsC1$max_n_cum[max_n_cum_values_AspectsC1$GRUPO == "Control"]
pushdictation_max_n_cum_AspectsC1 <- max_n_cum_values_AspectsC1$max_n_cum[max_n_cum_values_AspectsC1$GRUPO == "PushDictation"]
pushrecording_max_n_cum_AspectsC1 <- max_n_cum_values_AspectsC1$max_n_cum[max_n_cum_values_AspectsC1$GRUPO == "PushRecording"]
choice_max_n_cum_AspectsC1 <- max_n_cum_values_AspectsC1$max_n_cum[max_n_cum_values_AspectsC1$GRUPO == "Choice"]

#Put together last row
total_obs_row_AspectsC1 <- tibble(
  ASPECTS_TRANSPC1 = "Number of observations",
  Control = control_max_n_cum_AspectsC1,
  PushDictation = pushdictation_max_n_cum_AspectsC1,
  PushRecording = pushrecording_max_n_cum_AspectsC1,
  Choice = choice_max_n_cum_AspectsC1
)

#Put together with the rest
table_with_total_AspectsC1 = bind_rows(
  table_dataAspectsC1 %>% 
    mutate(across(-ASPECTS_TRANSPC1, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_AspectsC1 %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Aspects1, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_AspectsC1, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

<center><b>
Answered to both parts of the question, or only part 1 or only part 2, using the codes of Coder 2
</center></b>

```{r prep_Aspects2, message=FALSE, include = FALSE, cache = TRUE}
tibbleAspectsC2 = propby(data, GRUPO, ASPECTS_TRANSPC2)
# Select relevant columns and reshape the data using spread
table_dataAspectsC2 <-  tibbleAspectsC2 %>%
  select(ASPECTS_TRANSPC2, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(ASPECTS_TRANSPC2)

#Extract n_cum
max_n_cum_values_AspectsC2 <- tibbleAspectsC2 %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_AspectsC2 <- max_n_cum_values_AspectsC2$max_n_cum[max_n_cum_values_AspectsC2$GRUPO == "Control"]
pushdictation_max_n_cum_AspectsC2 <- max_n_cum_values_AspectsC2$max_n_cum[max_n_cum_values_AspectsC2$GRUPO == "PushDictation"]
pushrecording_max_n_cum_AspectsC2 <- max_n_cum_values_AspectsC2$max_n_cum[max_n_cum_values_AspectsC2$GRUPO == "PushRecording"]
choice_max_n_cum_AspectsC2 <- max_n_cum_values_AspectsC2$max_n_cum[max_n_cum_values_AspectsC2$GRUPO == "Choice"]

#Put together last row
total_obs_row_AspectsC2 <- tibble(
  ASPECTS_TRANSPC2 = "Number of observations",
  Control = control_max_n_cum_AspectsC2,
  PushDictation = pushdictation_max_n_cum_AspectsC2,
  PushRecording = pushrecording_max_n_cum_AspectsC2,
  Choice = choice_max_n_cum_AspectsC2
)

#Put together with the rest
table_with_total_AspectsC2 = bind_rows(
  table_dataAspectsC2 %>% 
    mutate(across(-ASPECTS_TRANSPC2, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_AspectsC2 %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Aspects2, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_AspectsC2, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```


### Tests of significance across groups WHYTRANSP

```{r dummies_aspects, message=FALSE, include = FALSE, cache = TRUE}

#create dummies for each situation and coder

data <- data %>%
     mutate(bothparts_TRANSPC1 = ifelse(ASPECTS_TRANSPC1 == "Both parts", 1, 0),
           firstpart_TRANSPC1 = ifelse(ASPECTS_TRANSPC1 == "First part", 1, 0),
           secondpart_TRANSPC1 = ifelse(ASPECTS_TRANSPC1 == "Second part", 1, 0)
            )

data <- data %>%
     mutate(bothparts_TRANSPC2 = ifelse(ASPECTS_TRANSPC2 == "Both parts", 1, 0),
           firstpart_TRANSPC2 = ifelse(ASPECTS_TRANSPC2 == "First part", 1, 0),
           secondpart_TRANSPC2 = ifelse(ASPECTS_TRANSPC2 == "Second part", 1, 0)
            )
```

<center><b>
Tests both parts Coder 1
</center></b>
```{r bothparts_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testbothpartsC1=proptest(data, bothparts_TRANSPC1, GRUPO)
kable(testbothpartsC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testbothpartsC1), align = "c")
```

<center><b>
Tests both parts Coder 2
</center></b>
```{r bothparts_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testbothpartsC2=proptest(data, bothparts_TRANSPC2, GRUPO)
kable(testbothpartsC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testbothpartsC2), align = "c")
```

<center><b>
Tests first part Coder 1
</center></b>
```{r firstpart_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testfirstpartC1=proptest(data, firstpart_TRANSPC1, GRUPO)
kable(testfirstpartC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testfirstpartC1), align = "c")
```


<center><b>
Tests first part Coder 2
</center></b>
```{r firstpart_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testfirstpartC2=proptest(data, firstpart_TRANSPC2, GRUPO)
kable(testfirstpartC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testfirstpartC2), align = "c")
```


<center><b>
Tests second part Coder 1
</center></b>
```{r secpart_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testsecpartC1=proptest(data, secondpart_TRANSPC1, GRUPO)
kable(testsecpartC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testsecpartC1), align = "c")
```


<center><b>
Tests second part Coder 2
</center></b>
```{r secpart_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testsecpartC2=proptest(data, secondpart_TRANSPC2, GRUPO)
kable(testsecpartC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testsecpartC2), align = "c")
```

<br>
<br>

<i>

### Aspects WHYTRUST

</i>


### Proportions per group WHYTRUST

<center><b>
Answered to both parts of the question, or only part 1 or only part 2, using the codes of Coder 1
</center></b>

```{r prep_Aspects1tr, message=FALSE, include = FALSE, cache = TRUE}
tibbleAspectsC1tr = propby(data, GRUPO, ASPECTS_TRUSTC1)
# Select relevant columns and reshape the data using spread
table_dataAspectsC1tr <-  tibbleAspectsC1tr %>%
  select(ASPECTS_TRUSTC1, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(ASPECTS_TRUSTC1)

#Extract n_cum
max_n_cum_values_AspectsC1tr <- tibbleAspectsC1tr %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_AspectsC1tr <- max_n_cum_values_AspectsC1tr$max_n_cum[max_n_cum_values_AspectsC1tr$GRUPO == "Control"]
pushdictation_max_n_cum_AspectsC1tr <- max_n_cum_values_AspectsC1tr$max_n_cum[max_n_cum_values_AspectsC1tr$GRUPO == "PushDictation"]
pushrecording_max_n_cum_AspectsC1tr <- max_n_cum_values_AspectsC1tr$max_n_cum[max_n_cum_values_AspectsC1tr$GRUPO == "PushRecording"]
choice_max_n_cum_AspectsC1tr <- max_n_cum_values_AspectsC1tr$max_n_cum[max_n_cum_values_AspectsC1tr$GRUPO == "Choice"]

#Put together last row
total_obs_row_AspectsC1tr <- tibble(
  ASPECTS_TRUSTC1 = "Number of observations",
  Control = control_max_n_cum_AspectsC1tr,
  PushDictation = pushdictation_max_n_cum_AspectsC1tr,
  PushRecording = pushrecording_max_n_cum_AspectsC1tr,
  Choice = choice_max_n_cum_AspectsC1tr
)

#Put together with the rest
table_with_total_AspectsC1tr = bind_rows(
  table_dataAspectsC1tr %>% 
    mutate(across(-ASPECTS_TRUSTC1, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_AspectsC1tr %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Aspects1tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_AspectsC1tr, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

<center><b>
Answered to both parts of the question, or only part 1 or only part 2, using the codes of Coder 2
</center></b>

```{r prep_Aspects2tr, message=FALSE, include = FALSE, cache = TRUE}
tibbleAspectsC2tr = propby(data, GRUPO, ASPECTS_TRUSTC2)
# Select relevant columns and reshape the data using spread
table_dataAspectsC2tr <-  tibbleAspectsC2tr %>%
  select(ASPECTS_TRUSTC2, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(ASPECTS_TRUSTC2)

#Extract n_cum
max_n_cum_values_AspectsC2tr <- tibbleAspectsC2tr %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_AspectsC2tr <- max_n_cum_values_AspectsC2tr$max_n_cum[max_n_cum_values_AspectsC2tr$GRUPO == "Control"]
pushdictation_max_n_cum_AspectsC2tr <- max_n_cum_values_AspectsC2tr$max_n_cum[max_n_cum_values_AspectsC2tr$GRUPO == "PushDictation"]
pushrecording_max_n_cum_AspectsC2tr <- max_n_cum_values_AspectsC2tr$max_n_cum[max_n_cum_values_AspectsC2tr$GRUPO == "PushRecording"]
choice_max_n_cum_AspectsC2tr <- max_n_cum_values_AspectsC2tr$max_n_cum[max_n_cum_values_AspectsC2tr$GRUPO == "Choice"]

#Put together last row
total_obs_row_AspectsC2tr <- tibble(
  ASPECTS_TRUSTC2 = "Number of observations",
  Control = control_max_n_cum_AspectsC2tr,
  PushDictation = pushdictation_max_n_cum_AspectsC2tr,
  PushRecording = pushrecording_max_n_cum_AspectsC2tr,
  Choice = choice_max_n_cum_AspectsC2tr
)

#Put together with the rest
table_with_total_AspectsC2tr = bind_rows(
  table_dataAspectsC2tr %>% 
    mutate(across(-ASPECTS_TRUSTC2, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_AspectsC2tr %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Aspects2tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_AspectsC2tr, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

### Tests of significance across groups WHYTRUST

```{r dummies_aspectstr, message=FALSE, include = FALSE, cache = TRUE}

#create dummies for each situation and coder

data <- data %>%
     mutate(bothparts_TRUSTC1 = ifelse(ASPECTS_TRUSTC1 == "Both parts", 1, 0),
           firstpart_TRUSTC1 = ifelse(ASPECTS_TRUSTC1 == "First part", 1, 0),
           secondpart_TRUSTC1 = ifelse(ASPECTS_TRUSTC1 == "Second part", 1, 0)
            )

data <- data %>%
     mutate(bothparts_TRUSTC2 = ifelse(ASPECTS_TRUSTC2 == "Both parts", 1, 0),
           firstpart_TRUSTC2 = ifelse(ASPECTS_TRUSTC2 == "First part", 1, 0),
           secondpart_TRUSTC2 = ifelse(ASPECTS_TRUSTC2 == "Second part", 1, 0)
            )
```

<center><b>
Tests both parts Coder 1
</center></b>
```{r bothparts_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testbothpartsC1tr=proptest(data, bothparts_TRUSTC1, GRUPO)
kable(testbothpartsC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testbothpartsC1tr), align = "c")
```

<center><b>
Tests both parts Coder 2
</center></b>
```{r bothparts_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testbothpartsC2tr=proptest(data, bothparts_TRUSTC2, GRUPO)
kable(testbothpartsC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testbothpartsC2tr), align = "c")
```

<center><b>
Tests first part Coder 1
</center></b>
```{r firstpart_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testfirstpartC1tr=proptest(data, firstpart_TRUSTC1, GRUPO)
kable(testfirstpartC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testfirstpartC1tr), align = "c")
```


<center><b>
Tests first part Coder 2
</center></b>
```{r firstpart_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testfirstpartC2tr=proptest(data, firstpart_TRUSTC2, GRUPO)
kable(testfirstpartC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testfirstpartC2tr), align = "c")
```


<center><b>
Tests second part Coder 1
</center></b>
```{r secpart_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testsecpartC1tr=proptest(data, secondpart_TRUSTC1, GRUPO)
kable(testsecpartC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testsecpartC1tr), align = "c")
```


<center><b>
Tests second part Coder 2
</center></b>
```{r secpart_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testsecpartC2tr=proptest(data, secondpart_TRUSTC2, GRUPO)
kable(testsecpartC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testsecpartC2tr), align = "c")
```

<br>

<i>

### Main results Aspects answered by subgroups (text versus voice)

</i>

<br>

<center><b>
Both aspects answered WHYTRANSP C1
</center></b>

```{r aspects_subgroup, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
aspectsC1_subgroup <- propby(data, SUBGROUP_TRANSP, bothparts_TRANSPC1)

aspectsC1_subgroup <- aspectsC1_subgroup %>%
  mutate(
    f = round(f * 100, 1),
    f_cum = round(f_cum * 100, 1)
  )

kable(aspectsC1_subgroup, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(aspectsC1_subgroup), align = "c")
```

<br>

<center><b>
Both aspects answered WHYTRUST C1
</center></b>

```{r aspects_subgrouptr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
aspectsC1_subgrouptr <- propby(data, SUBGROUP_TRUST, bothparts_TRUSTC1)

aspectsC1_subgrouptr <- aspectsC1_subgrouptr %>%
  mutate(
    f = round(f * 100, 1),
    f_cum = round(f_cum * 100, 1)
  )

kable(aspectsC1_subgrouptr, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(aspectsC1_subgrouptr), align = "c")
```

<br>

## Abbreviations

<i>

### Abbreviations WHYTRANSP

</i>

### Proportions per group WHYTRANSP

<center><b>
Abbreviations, using the codes of Coder 1
</center></b>


```{r prep_Abbr1, message=FALSE, include = FALSE, cache = TRUE}
tibbleAbbrC1 = propby(data, GRUPO, ABBR_TRANSPC1)
# Select relevant columns and reshape the data using spread
table_dataAbbrC1 <-  tibbleAbbrC1 %>%
  select(ABBR_TRANSPC1, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(ABBR_TRANSPC1)

#Extract n_cum
max_n_cum_values_AbbrC1 <- tibbleAbbrC1 %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_AbbrC1 <- max_n_cum_values_AbbrC1$max_n_cum[max_n_cum_values_AbbrC1$GRUPO == "Control"]
pushdictation_max_n_cum_AbbrC1 <- max_n_cum_values_AbbrC1$max_n_cum[max_n_cum_values_AbbrC1$GRUPO == "PushDictation"]
pushrecording_max_n_cum_AbbrC1 <- max_n_cum_values_AbbrC1$max_n_cum[max_n_cum_values_AbbrC1$GRUPO == "PushRecording"]
choice_max_n_cum_AbbrC1 <- max_n_cum_values_AbbrC1$max_n_cum[max_n_cum_values_AbbrC1$GRUPO == "Choice"]

#Put together last row
total_obs_row_AbbrC1 <- tibble(
  ABBR_TRANSPC1 = "Number of observations",
  Control = control_max_n_cum_AbbrC1,
  PushDictation = pushdictation_max_n_cum_AbbrC1,
  PushRecording = pushrecording_max_n_cum_AbbrC1,
  Choice = choice_max_n_cum_AbbrC1
)

#Put together with the rest
table_with_total_AbbrC1 = bind_rows(
  table_dataAbbrC1 %>% 
    mutate(across(-ABBR_TRANSPC1, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_AbbrC1 %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Abbr1, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_AbbrC1, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

<center><b>
Abbreviations, using the codes of Coder 2
</center></b>

```{r prep_Abbr2, message=FALSE, include = FALSE, cache = TRUE}
tibbleAbbrC2 = propby(data, GRUPO, ABBR_TRANSPC2)
# Select relevant columns and reshape the data using spread
table_dataAbbrC2 <-  tibbleAbbrC2 %>%
  select(ABBR_TRANSPC2, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(ABBR_TRANSPC2)

#Extract n_cum
max_n_cum_values_AbbrC2 <- tibbleAbbrC2 %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_AbbrC2 <- max_n_cum_values_AbbrC2$max_n_cum[max_n_cum_values_AbbrC2$GRUPO == "Control"]
pushdictation_max_n_cum_AbbrC2 <- max_n_cum_values_AbbrC2$max_n_cum[max_n_cum_values_AbbrC2$GRUPO == "PushDictation"]
pushrecording_max_n_cum_AbbrC2 <- max_n_cum_values_AbbrC2$max_n_cum[max_n_cum_values_AbbrC2$GRUPO == "PushRecording"]
choice_max_n_cum_AbbrC2 <- max_n_cum_values_AbbrC2$max_n_cum[max_n_cum_values_AbbrC2$GRUPO == "Choice"]

#Put together last row
total_obs_row_AbbrC2 <- tibble(
  ABBR_TRANSPC2 = "Number of observations",
  Control = control_max_n_cum_AbbrC2,
  PushDictation = pushdictation_max_n_cum_AbbrC2,
  PushRecording = pushrecording_max_n_cum_AbbrC2,
  Choice = choice_max_n_cum_AbbrC2
)

#Put together with the rest
table_with_total_AbbrC2 = bind_rows(
  table_dataAbbrC2 %>% 
    mutate(across(-ABBR_TRANSPC2, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_AbbrC2 %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Abbr2, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_AbbrC2, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

### Tests of significance across groups WHYTRANSP

<center><b>
Tests abbreviations Coder 1
</center></b>
```{r testabbr_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testabbrC1=proptest(data, ABBR_TRANSPC1, GRUPO)
kable(testabbrC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testabbrC1), align = "c")
```

<center><b>
Tests abbreviations Coder 2
</center></b>
```{r testabbr_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testabbrC2=proptest(data, ABBR_TRANSPC2, GRUPO)
kable(testabbrC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testabbrC2), align = "c")
```

<br>

<br>

<i>

### Abbreviations WHYTRUST

</i>


### Proportions per group WHYTRUST

<center><b>
Abbreviations, using the codes of Coder 1
</center></b>

```{r prep_Abbr1tr, message=FALSE, include = FALSE, cache = TRUE}
tibbleAbbrC1tr = propby(data, GRUPO, ABBR_TRUSTC1)
# Select relevant columns and reshape the data using spread
table_dataAbbrC1tr <-  tibbleAbbrC1tr %>%
  select(ABBR_TRUSTC1, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(ABBR_TRUSTC1)

#Extract n_cum
max_n_cum_values_AbbrC1tr <- tibbleAbbrC1tr %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_AbbrC1tr <- max_n_cum_values_AbbrC1tr$max_n_cum[max_n_cum_values_AbbrC1tr$GRUPO == "Control"]
pushdictation_max_n_cum_AbbrC1tr <- max_n_cum_values_AbbrC1tr$max_n_cum[max_n_cum_values_AbbrC1tr$GRUPO == "PushDictation"]
pushrecording_max_n_cum_AbbrC1tr <- max_n_cum_values_AbbrC1tr$max_n_cum[max_n_cum_values_AbbrC1tr$GRUPO == "PushRecording"]
choice_max_n_cum_AbbrC1tr <- max_n_cum_values_AbbrC1tr$max_n_cum[max_n_cum_values_AbbrC1tr$GRUPO == "Choice"]

#Put together last row
total_obs_row_AbbrC1tr <- tibble(
  ABBR_TRUSTC1 = "Number of observations",
  Control = control_max_n_cum_AbbrC1tr,
  PushDictation = pushdictation_max_n_cum_AbbrC1tr,
  PushRecording = pushrecording_max_n_cum_AbbrC1tr,
  Choice = choice_max_n_cum_AbbrC1tr
)

#Put together with the rest
table_with_total_AbbrC1tr = bind_rows(
  table_dataAbbrC1tr %>% 
    mutate(across(-ABBR_TRUSTC1, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_AbbrC1tr %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Abbr1tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_AbbrC1tr, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

<center><b>
Abbreviations, using the codes of Coder 2
</center></b>

```{r prep_Abbr2tr, message=FALSE, include = FALSE, cache = TRUE}
tibbleAbbrC2tr = propby(data, GRUPO, ABBR_TRUSTC2)
# Select relevant columns and reshape the data using spread
table_dataAbbrC2tr <-  tibbleAbbrC2tr %>%
  select(ABBR_TRUSTC2, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(ABBR_TRUSTC2)

#Extract n_cum
max_n_cum_values_AbbrC2tr <- tibbleAbbrC2tr %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_AbbrC2tr <- max_n_cum_values_AbbrC2tr$max_n_cum[max_n_cum_values_AbbrC2tr$GRUPO == "Control"]
pushdictation_max_n_cum_AbbrC2tr <- max_n_cum_values_AbbrC2tr$max_n_cum[max_n_cum_values_AbbrC2tr$GRUPO == "PushDictation"]
pushrecording_max_n_cum_AbbrC2tr <- max_n_cum_values_AbbrC2tr$max_n_cum[max_n_cum_values_AbbrC2tr$GRUPO == "PushRecording"]
choice_max_n_cum_AbbrC2tr <- max_n_cum_values_AbbrC2tr$max_n_cum[max_n_cum_values_AbbrC2tr$GRUPO == "Choice"]

#Put together last row
total_obs_row_AbbrC2tr <- tibble(
  ABBR_TRUSTC2 = "Number of observations",
  Control = control_max_n_cum_AbbrC2tr,
  PushDictation = pushdictation_max_n_cum_AbbrC2tr,
  PushRecording = pushrecording_max_n_cum_AbbrC2tr,
  Choice = choice_max_n_cum_AbbrC2tr
)

#Put together with the rest
table_with_total_AbbrC2tr = bind_rows(
  table_dataAbbrC2tr %>% 
    mutate(across(-ABBR_TRUSTC2, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_AbbrC2tr %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Abbr2tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_AbbrC2tr, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

### Tests of significance across groups WHYTRUST

<center><b>
Tests abbreviations Coder 1
</center></b>
```{r testabbr_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testabbrC1tr=proptest(data, ABBR_TRUSTC1, GRUPO)
kable(testabbrC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testabbrC1tr), align = "c")
```

<center><b>
Tests abbreviations Coder 2
</center></b>
```{r testabbr_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testabbrC2tr=proptest(data, ABBR_TRUSTC2, GRUPO)
kable(testabbrC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testabbrC2tr), align = "c")
```

<br>

<br>


## Problems detected

<i>

### Problems WHYTRANSP

</i>

### Proportions per group WHYTRANSP

<center><b>
Problems, using the codes of Coder 1
</center></b>

```{r prep_Pb1, message=FALSE, include = FALSE, cache = TRUE}
tibblePbC1 = propby(data, GRUPO, PB1_TRANSPC1)
# Select relevant columns and reshape the data using spread
table_dataPbC1 <-  tibblePbC1 %>%
  select(PB1_TRANSPC1, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(PB1_TRANSPC1)

#Extract n_cum
max_n_cum_values_PbC1 <- tibblePbC1 %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_PbC1 <- max_n_cum_values_PbC1$max_n_cum[max_n_cum_values_PbC1$GRUPO == "Control"]
pushdictation_max_n_cum_PbC1 <- max_n_cum_values_PbC1$max_n_cum[max_n_cum_values_PbC1$GRUPO == "PushDictation"]
pushrecording_max_n_cum_PbC1 <- max_n_cum_values_PbC1$max_n_cum[max_n_cum_values_PbC1$GRUPO == "PushRecording"]
choice_max_n_cum_PbC1 <- max_n_cum_values_PbC1$max_n_cum[max_n_cum_values_PbC1$GRUPO == "Choice"]

#Put together last row
total_obs_row_PbC1 <- tibble(
  PB1_TRANSPC1 = "Number of observations",
  Control = control_max_n_cum_PbC1,
  PushDictation = pushdictation_max_n_cum_PbC1,
  PushRecording = pushrecording_max_n_cum_PbC1,
  Choice = choice_max_n_cum_PbC1
)

#Put together with the rest
table_with_total_PbC1 = bind_rows(
  table_dataPbC1 %>% 
    mutate(across(-PB1_TRANSPC1, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_PbC1 %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Pb1, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_PbC1, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```


<center><b>
Problems, using the codes of Coder 2
</center></b>

```{r prep_Pb2, message=FALSE, include = FALSE, cache = TRUE}
tibblePbC2 = propby(data, GRUPO, PB1_TRANSPC2)
# Select relevant columns and reshape the data using spread
table_dataPbC2 <-  tibblePbC2 %>%
  select(PB1_TRANSPC2, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(PB1_TRANSPC2)

#Extract n_cum
max_n_cum_values_PbC2 <- tibblePbC2 %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_PbC2 <- max_n_cum_values_PbC2$max_n_cum[max_n_cum_values_PbC2$GRUPO == "Control"]
pushdictation_max_n_cum_PbC2 <- max_n_cum_values_PbC2$max_n_cum[max_n_cum_values_PbC2$GRUPO == "PushDictation"]
pushrecording_max_n_cum_PbC2 <- max_n_cum_values_PbC2$max_n_cum[max_n_cum_values_PbC2$GRUPO == "PushRecording"]
choice_max_n_cum_PbC2 <- max_n_cum_values_PbC2$max_n_cum[max_n_cum_values_PbC2$GRUPO == "Choice"]

#Put together last row
total_obs_row_PbC2 <- tibble(
  PB1_TRANSPC2 = "Number of observations",
  Control = control_max_n_cum_PbC2,
  PushDictation = pushdictation_max_n_cum_PbC2,
  PushRecording = pushrecording_max_n_cum_PbC2,
  Choice = choice_max_n_cum_PbC2
)

#Put together with the rest
table_with_total_PbC2 = bind_rows(
  table_dataPbC2 %>% 
    mutate(across(-PB1_TRANSPC2, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_PbC2 %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Pb2, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_PbC2, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

### Tests of significance across groups WHYTRANSP


```{r dummies_pb, message=FALSE, include = FALSE, cache = TRUE}

#create dummies for each situation and coder

data <- data %>%
     mutate(noproblem_TRANSPC1 = ifelse(PB1_TRANSPC1 == "No problem detected", 1, 0),
           incomplete_TRANSPC1 = ifelse(PB1_TRANSPC1 == "Incomplete sentence(s)", 1, 0),
           repeat_TRANSPC1 = ifelse(PB1_TRANSPC1 == "Part of the answer repeated", 1, 0),
           otherpb_TRANSPC1 = ifelse(PB1_TRANSPC1 == "Other problem(s)", 1, 0)
            )

data <- data %>%
     mutate(noproblem_TRANSPC2 = ifelse(PB1_TRANSPC2 == "No problem detected", 1, 0),
           incomplete_TRANSPC2 = ifelse(PB1_TRANSPC2 == "Incomplete sentence(s)", 1, 0),
           repeat_TRANSPC2 = ifelse(PB1_TRANSPC2 == "Part of the answer repeated", 1, 0),
           otherpb_TRANSPC2 = ifelse(PB1_TRANSPC2 == "Other problem(s)", 1, 0)
            )
```

<center><b>
Tests problems Coder 1: no problem detected 
</center></b>
```{r testnopb_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testnopbC1=proptest(data, noproblem_TRANSPC1, GRUPO)
kable(testnopbC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testnopbC1), align = "c")
```

<center><b>
Tests problems Coder 2: no problem detected 
</center></b>
```{r testnopb_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testnopbC2=proptest(data, noproblem_TRANSPC2, GRUPO)
kable(testnopbC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testnopbC2), align = "c")
```


<center><b>
Tests problems Coder 1: Incomplete sentence(s) 
</center></b>
```{r testincomplete_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testincompleteC1=proptest(data, incomplete_TRANSPC1, GRUPO)
kable(testincompleteC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testincompleteC1), align = "c")
```

<center><b>
Tests problems Coder 2: Incomplete sentence(s) 
</center></b>
```{r testincomplete_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testincompleteC2=proptest(data, incomplete_TRANSPC2, GRUPO)
kable(testincompleteC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testincompleteC2), align = "c")
```

<center><b>
Tests problems Coder 1: Part of the answer repeated
</center></b>
```{r testrepeat_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testrepeatC1=proptest(data, repeat_TRANSPC1, GRUPO)
kable(testrepeatC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testrepeatC1), align = "c")
```


<center><b>
Tests problems Coder 2: Part of the answer repeated
</center></b>
```{r testrepeat_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testrepeatC2=proptest(data, repeat_TRANSPC2, GRUPO)
kable(testrepeatC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testrepeatC2), align = "c")
```


<center><b>
Tests problems Coder 1: Other problem(s)
</center></b>
```{r testotherpb_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testotherpbC1=proptest(data, otherpb_TRANSPC1, GRUPO)
kable(testotherpbC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testotherpbC1), align = "c")
```

<center><b>
Tests problems Coder 2: Other problem(s)
</center></b>
```{r testotherpb_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testotherpbC2=proptest(data, otherpb_TRANSPC2, GRUPO)
kable(testotherpbC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testotherpbC2), align = "c")
```

<br>

<br>

<i>

### Problems WHYTRUST



</i>

### Proportions per group WHYTRUST

<center><b>
Problems, using the codes of Coder 1
</center></b>

```{r prep_Pb1tr, message=FALSE, include = FALSE, cache = TRUE}
tibblePbC1tr = propby(data, GRUPO, PB1_TRUSTC1)
# Select relevant columns and reshape the data using spread
table_dataPbC1tr <-  tibblePbC1tr %>%
  select(PB1_TRUSTC1, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(PB1_TRUSTC1)

#Extract n_cum
max_n_cum_values_PbC1tr <- tibblePbC1tr %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_PbC1tr <- max_n_cum_values_PbC1tr$max_n_cum[max_n_cum_values_PbC1tr$GRUPO == "Control"]
pushdictation_max_n_cum_PbC1tr <- max_n_cum_values_PbC1tr$max_n_cum[max_n_cum_values_PbC1tr$GRUPO == "PushDictation"]
pushrecording_max_n_cum_PbC1tr <- max_n_cum_values_PbC1tr$max_n_cum[max_n_cum_values_PbC1tr$GRUPO == "PushRecording"]
choice_max_n_cum_PbC1tr <- max_n_cum_values_PbC1tr$max_n_cum[max_n_cum_values_PbC1tr$GRUPO == "Choice"]

#Put together last row
total_obs_row_PbC1tr <- tibble(
  PB1_TRUSTC1 = "Number of observations",
  Control = control_max_n_cum_PbC1tr,
  PushDictation = pushdictation_max_n_cum_PbC1tr,
  PushRecording = pushrecording_max_n_cum_PbC1tr,
  Choice = choice_max_n_cum_PbC1tr
)

#Put together with the rest
table_with_total_PbC1tr = bind_rows(
  table_dataPbC1tr %>% 
    mutate(across(-PB1_TRUSTC1, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_PbC1tr %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Pb1tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_PbC1tr, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

<center><b>
Problems, using the codes of Coder 2
</center></b>


```{r prep_Pb2tr, message=FALSE, include = FALSE, cache = TRUE}
tibblePbC2tr = propby(data, GRUPO, PB1_TRUSTC2)
# Select relevant columns and reshape the data using spread
table_dataPbC2tr <-  tibblePbC2tr %>%
  select(PB1_TRUSTC2, GRUPO, f) %>%
  spread(key = GRUPO, value = f) %>%
  arrange(PB1_TRUSTC2)

#Extract n_cum
max_n_cum_values_PbC2tr <- tibblePbC2tr %>%
  group_by(GRUPO) %>%
  summarize(max_n_cum = max(n_cum))

#Extract the values for specific groups
control_max_n_cum_PbC2tr <- max_n_cum_values_PbC2tr$max_n_cum[max_n_cum_values_PbC2tr$GRUPO == "Control"]
pushdictation_max_n_cum_PbC2tr <- max_n_cum_values_PbC2tr$max_n_cum[max_n_cum_values_PbC2tr$GRUPO == "PushDictation"]
pushrecording_max_n_cum_PbC2tr <- max_n_cum_values_PbC2tr$max_n_cum[max_n_cum_values_PbC2tr$GRUPO == "PushRecording"]
choice_max_n_cum_PbC2tr <- max_n_cum_values_PbC2tr$max_n_cum[max_n_cum_values_PbC2tr$GRUPO == "Choice"]

#Put together last row
total_obs_row_PbC2tr <- tibble(
  PB1_TRUSTC2 = "Number of observations",
  Control = control_max_n_cum_PbC2tr,
  PushDictation = pushdictation_max_n_cum_PbC2tr,
  PushRecording = pushrecording_max_n_cum_PbC2tr,
  Choice = choice_max_n_cum_PbC2tr
)

#Put together with the rest
table_with_total_PbC2tr = bind_rows(
  table_dataPbC2tr %>% 
    mutate(across(-PB1_TRUSTC2, ~ format(.x*100,nsmall=1,digits=1))) %>% #and change format decimals  
    mutate_all(as.character),
  total_obs_row_PbC2tr %>% 
    mutate_all(as.character)
)%>%
  select(1, 2, 5, 3, 4)
```

```{r result_Pb2tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_with_total_PbC2tr, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), align=c("l","c","c","c","c")) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, align = "c", bold = TRUE) 
```

### Tests of significance across groups WHYTRUST


```{r dummies_pbtr, message=FALSE, include = FALSE, cache = TRUE}

#create dummies for each situation and coder

data <- data %>%
     mutate(noproblem_TRUSTC1 = ifelse(PB1_TRUSTC1 == "No problem detected", 1, 0),
           incomplete_TRUSTC1 = ifelse(PB1_TRUSTC1 == "Incomplete sentence(s)", 1, 0),
           repeat_TRUSTC1 = ifelse(PB1_TRUSTC1 == "Part of the answer repeated", 1, 0),
           otherpb_TRUSTC1 = ifelse(PB1_TRUSTC1 == "Other problem(s)", 1, 0)
            )

data <- data %>%
     mutate(noproblem_TRUSTC2 = ifelse(PB1_TRUSTC2 == "No problem detected", 1, 0),
           incomplete_TRUSTC2 = ifelse(PB1_TRUSTC2 == "Incomplete sentence(s)", 1, 0),
           repeat_TRUSTC2 = ifelse(PB1_TRUSTC2 == "Part of the answer repeated", 1, 0),
           otherpb_TRUSTC2 = ifelse(PB1_TRUSTC2 == "Other problem(s)", 1, 0)
            )
```

<center><b>
Tests problems Coder 1: no problem detected 
</center></b>
```{r testnopb_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testnopbC1tr=proptest(data, noproblem_TRUSTC1, GRUPO)
kable(testnopbC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testnopbC1tr), align = "c")
```

<center><b>
Tests problems Coder 2: no problem detected 
</center></b>
```{r testnopb_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testnopbC2tr=proptest(data, noproblem_TRUSTC2, GRUPO)
kable(testnopbC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testnopbC2tr), align = "c")
```


<center><b>
Tests problems Coder 1: Incomplete sentence(s) 
</center></b>
```{r testincomplete_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testincompleteC1tr=proptest(data, incomplete_TRUSTC1, GRUPO)
kable(testincompleteC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testincompleteC1tr), align = "c")
```

<center><b>
Tests problems Coder 2: Incomplete sentence(s) 
</center></b>
```{r testincomplete_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testincompleteC2tr=proptest(data, incomplete_TRUSTC2, GRUPO)
kable(testincompleteC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testincompleteC2tr), align = "c")
```

<center><b>
Tests problems Coder 1: Part of the answer repeated
</center></b>
```{r testrepeat_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testrepeatC1tr=proptest(data, repeat_TRUSTC1, GRUPO)
kable(testrepeatC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testrepeatC1tr), align = "c")
```


<center><b>
Tests problems Coder 2: Part of the answer repeated
</center></b>
```{r testrepeat_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testrepeatC2tr=proptest(data, repeat_TRUSTC2, GRUPO)
kable(testrepeatC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testrepeatC2tr), align = "c")
```


<center><b>
Tests problems Coder 1: Other problem(s)
</center></b>
```{r testotherpb_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testotherpbC1tr=proptest(data, otherpb_TRUSTC1, GRUPO)
kable(testotherpbC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testotherpbC1tr), align = "c")
```

<center><b>
Tests problems Coder 2: Other problem(s)
</center></b>
```{r testotherpb_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testotherpbC2tr=proptest(data, otherpb_TRUSTC2, GRUPO)
kable(testotherpbC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testotherpbC2tr), align = "c")
```

<br>
<br>



<i>

### Main results Problems detected by subgroups (text versus voice)

</i>

<br>

<center><b>
No problem detected WHYTRANSP C1
</center></b>

```{r nopb_subgroup, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nopbC1_subgroup <- propby(data, SUBGROUP_TRANSP, noproblem_TRANSPC1)

nopbC1_subgroup <- nopbC1_subgroup %>%
  mutate(
    f = round(f * 100, 1),
    f_cum = round(f_cum * 100, 1)
  )

kable(nopbC1_subgroup, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nopbC1_subgroup), align = "c")
```

<br>

<center><b>
No problem detected WHYTRUST C1
</center></b>

```{r nopb_subgrouptr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nopbC1_subgrouptr <- propby(data, SUBGROUP_TRUST, noproblem_TRUSTC1)

nopbC1_subgrouptr <- nopbC1_subgrouptr %>%
  mutate(
    f = round(f * 100, 1),
    f_cum = round(f_cum * 100, 1)
  )

kable(nopbC1_subgrouptr, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nopbC1_subgrouptr), align = "c")
```

<br>




## Number of themes

<i>

### No. themes WHYTRANSP

</i>

### Average/Median number of themes WHYTRANSP

<center><b>
Number of themes, using the codes of Coder 1: average and median
</center></b>

```{r prep_themes1, message=FALSE, include = FALSE, cache = TRUE}
tibbleThemesC1 = meanandmoreby(data, NTHEMES_TRANSP1b, GRUPO)
# Select relevant columns and reshape the data using spread
table_themesC1 <-  tibbleThemesC1 %>%
  select(GRUPO, mean, median) %>% 
  gather(Statistic, Value, mean, median) %>%
  pivot_wider(names_from = GRUPO, values_from = Value) %>%
  separate_rows(Statistic, sep = "_") %>%
  select(1, 2, 5, 3, 4)
```


```{r result_themes1, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_themesC1, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), digits = 2) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(table_themesC1), align = "c")
```


<center><b>
Number of themes, using the codes of Coder 2: average and median
</center></b>

```{r prep_themes2, message=FALSE, include = FALSE, cache = TRUE}
tibbleThemesC2 = meanandmoreby(data, NTHEMES_TRANSP2b, GRUPO)
# Select relevant columns and reshape the data using spread
table_themesC2 <-  tibbleThemesC2 %>%
  select(GRUPO, mean, median) %>% 
  gather(Statistic, Value, mean, median) %>%
  pivot_wider(names_from = GRUPO, values_from = Value) %>%
  separate_rows(Statistic, sep = "_")%>%
  select(1, 2, 5, 3, 4)
```


```{r result_themes2, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_themesC2, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), digits = 2) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(table_themesC2), align = "c")
```

### Tests of significance across groups WHYTRANSP (pairwise T-tests)

<center><b>
Tests differences average number of themes Coder 1
</center></b>
```{r testthemes_c1, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testthemesC1=pairwise_t_test(data, NTHEMES_TRANSP1b ~ GRUPO)
testthemesC1 = testthemesC1 %>% 
  select(group1, group2, p, p.signif, p.adj, p.adj.signif)
kable(testthemesC1, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testthemesC1), align = "c")
```

<center><b>
Tests differences average number of themes Coder 2
</center></b>
```{r testthemes_c2, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testthemesC2=pairwise_t_test(data, NTHEMES_TRANSP2b ~ GRUPO)
testthemesC2 = testthemesC2 %>% 
  select(group1, group2, p, p.signif, p.adj, p.adj.signif)
kable(testthemesC2, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testthemesC2), align = "c")
```

<br>

<br>

<i>

### No. themes WHYTRUST


</i>

### Average/Median number of themes WHYTRUST

<center><b>
Number of themes, using the codes of Coder 1: average and median
</center></b>

```{r prep_themes1tr, message=FALSE, include = FALSE, cache = TRUE}
tibbleThemesC1tr = meanandmoreby(data, NTHEMES_TRUST1b, GRUPO)
# Select relevant columns and reshape the data using spread
table_themesC1tr <-  tibbleThemesC1tr %>%
  select(GRUPO, mean, median) %>% 
  gather(Statistic, Value, mean, median) %>%
  pivot_wider(names_from = GRUPO, values_from = Value) %>%
  separate_rows(Statistic, sep = "_") %>%
  select(1, 2, 5, 3, 4)
```


```{r result_themes1tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_themesC1tr, format = "html", col.names = c("Coder 1", "Control", "Choice", "PushDictation", "PushRecording"), digits = 2) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(table_themesC1tr), align = "c")
```


<center><b>
Number of themes, using the codes of Coder 2: average and median
</center></b>

```{r prep_themes2tr, message=FALSE, include = FALSE, cache = TRUE}
tibbleThemesC2tr = meanandmoreby(data, NTHEMES_TRUST2b, GRUPO)
# Select relevant columns and reshape the data using spread
table_themesC2tr <-  tibbleThemesC2tr %>%
  select(GRUPO, mean, median) %>% 
  gather(Statistic, Value, mean, median) %>%
  pivot_wider(names_from = GRUPO, values_from = Value) %>%
  separate_rows(Statistic, sep = "_") %>%
  select(1, 2, 5, 3, 4)
```


```{r result_themes2tr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_themesC2tr, format = "html", col.names = c("Coder 2", "Control", "Choice", "PushDictation", "PushRecording"), digits = 2) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(table_themesC2tr), align = "c")
```

### Tests of significance across groups WHYTRUST (pairwise T-tests)

<center><b>
Tests differences average number of themes Coder 1
</center></b>
```{r testthemes_c1tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testthemesC1tr=pairwise_t_test(data, NTHEMES_TRUST1b ~ GRUPO)
testthemesC1tr = testthemesC1tr %>% 
  select(group1, group2, p, p.signif, p.adj, p.adj.signif)
kable(testthemesC1tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testthemesC1tr), align = "c")
```

<center><b>
Tests differences average number of themes Coder 2
</center></b>
```{r testthemes_c2tr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testthemesC2tr =pairwise_t_test(data, NTHEMES_TRUST2b ~ GRUPO)
testthemesC2tr = testthemesC2tr %>% 
  select(group1, group2, p, p.signif, p.adj, p.adj.signif)
kable(testthemesC2tr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testthemesC2tr), align = "c")
```

<br>
<br>

<i>

### Main results No. themes by subgroups (text versus voice)

</i>

<br>

<center><b>
No. of themes WHYTRANSP C1
</center></b>

```{r nothemes_subgroup, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nothemesC1_subgroup <- meanandmoreby(data, NTHEMES_TRANSP1b, SUBGROUP_TRANSP)

nothemesC1_subgroup <- nothemesC1_subgroup %>% 
  filter(SUBGROUP_TRANSP!="NA") %>% 
  mutate(mean=round(mean,1),
         stdev=round(stdev,2))  

kable(nothemesC1_subgroup, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nothemesC1_subgroup), align = "c")
```

<br>

<center><b>
No. of themes WHYTRUST C1
</center></b>

```{r nothemes_subgrouptr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nothemesC1_subgrouptr <- meanandmoreby(data, NTHEMES_TRUST1b, SUBGROUP_TRUST)

nothemesC1_subgrouptr <- nothemesC1_subgrouptr %>% 
  filter(SUBGROUP_TRUST!="NA") %>% 
  mutate(mean=round(mean,1),
         stdev=round(stdev,2))

kable(nothemesC1_subgrouptr, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nothemesC1_subgrouptr), align = "c")
```

<br>

## Number of characters 
<br>
Note: This is computed in R directly, no coders involved.
<br>
<i>

### No. characters WHYTRANSP

</i>

```{r prep_nchar, message=FALSE, include = FALSE, cache = TRUE}
#For missings, replace the dots by NA
data$WHYTRANSP_FINAL.x[data$WHYTRANSP_FINAL.x=="."] <- NA

#Create a new variable which is the number of characters 
data$NCHARWHYTRANSP <- nchar(data$WHYTRANSP_FINAL.x)

#Prepare data
tibbleNchar = meanandmoreby(data, NCHARWHYTRANSP, GRUPO)
# Select relevant columns and reshape the data using spread
table_nchar <-  tibbleNchar %>%
  select(GRUPO, mean, median) %>% 
  gather(Statistic, Value, mean, median) %>%
  pivot_wider(names_from = GRUPO, values_from = Value) %>%
  separate_rows(Statistic, sep = "_") %>%
  select(1, 2, 5, 3, 4)
```

### Average/Median number of characters WHYTRANSP

<center><b>
Number of characters: average and median
</center></b>

```{r result_nchar, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_nchar, format = "html", col.names = c("No. Char", "Control", "Choice", "PushDictation", "PushRecording"), digits = 0) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(table_nchar), align = "c")
```

### Tests of significance across groups WHYTRANSP (pairwise T-tests)

<center><b>
Tests differences average number of characters
</center></b>
```{r testnchar, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testnchar=pairwise_t_test(data, NCHARWHYTRANSP ~ GRUPO)
testnchar = testnchar %>% 
  select(group1, group2, p, p.signif, p.adj, p.adj.signif)
kable(testnchar, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testnchar), align = "c")
```

<br>

<i>

### No. characters WHYTRUST

</i>

```{r prep_nchartr, message=FALSE, include = FALSE, cache = TRUE}
#For missings, replace the dots by NA
data$WHYTRUSTNH_FINAL.x[data$WHYTUSTNH_FINAL.x=="."] <- NA

#Create a new variable which is the number of characters 
data$NCHARWHYTRUST <- nchar(data$WHYTRUSTNH_FINAL.x)

#Prepare data
tibbleNchartr = meanandmoreby(data, NCHARWHYTRUST, GRUPO)
# Select relevant columns and reshape the data using spread
table_nchartr <-  tibbleNchartr %>%
  select(GRUPO, mean, median) %>% 
  gather(Statistic, Value, mean, median) %>%
  pivot_wider(names_from = GRUPO, values_from = Value) %>%
  separate_rows(Statistic, sep = "_") %>%
  select(1, 2, 5, 3, 4)
```


### Average/Median number of characters WHYTRUST

<center><b>
Number of characters: average and median
</center></b>

```{r result_nchartr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_nchartr, format = "html", col.names = c("No. Char", "Control", "Choice", "PushDictation", "PushRecording"), digits = 0) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(table_nchartr), align = "c")
```

### Tests of significance across groups WHYTRUST (pairwise T-tests)

<center><b>
Tests differences average number of characters
</center></b>
```{r testnchartr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testnchartr =pairwise_t_test(data, NCHARWHYTRUST ~ GRUPO)
testnchartr = testnchartr %>% 
  select(group1, group2, p, p.signif, p.adj, p.adj.signif)
kable(testnchartr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testnchartr), align = "c")
```

<br>


<i>

### Main results No. characters by subgroups (text versus voice)

</i>


<br>

<center><b>
No. of characters WHYTRANSP C1
</center></b>

```{r nochar_subgroup, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nocharC1_subgroup <- meanandmoreby(data, NCHARWHYTRANSP, SUBGROUP_TRANSP)

nocharC1_subgroup <- nocharC1_subgroup %>% 
  filter(SUBGROUP_TRANSP!="NA")%>% 
  mutate(mean=round(mean),
         stdev=round(stdev),
         median=round(median))  

kable(nocharC1_subgroup, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nocharC1_subgroup), align = "c")
```

<br>

<center><b>
No. of characters WHYTRUST C1
</center></b>

```{r nochar_subgrouptr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
nocharC1_subgrouptr <- meanandmoreby(data, NCHARWHYTRUST, SUBGROUP_TRUST)

nocharC1_subgrouptr <- nocharC1_subgrouptr %>% 
  filter(SUBGROUP_TRUST!="NA") %>% 
  mutate(mean=round(mean),
         stdev=round(stdev),
         median=round(median))  

kable(nocharC1_subgrouptr, format = "html") %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(nocharC1_subgrouptr), align = "c")
```

<br>

## Completion time
<br>
Note: This is computed in R directly, no coders involved. All times are focus time (in seconds), i.e., times that the active page is the survey question page. 
Note 2: We focus only on valid answers.
Note 3: For the push groups, the times reported include the potential follow-up questions, in case of skipping initially the experimental questions.
Note 4: This cannot be considered a direct indicator of quality, since shorter times can be simply due to the fact that speaking is quicker than typing. 
<br>

<i>

### Focus time WHYTRANSP

</i>

```{r prep_time, message=FALSE, include = FALSE, cache = TRUE}

data$TP_WHYTRANSP_EXP_active_time[is.na(data$TP_WHYTRANSP_EXP_active_time)] <- 0 #replace NA by 0 
data$TP_WHYTRANSP_EXP_active_time_s <- data$TP_WHYTRANSP_EXP_active_time/1000 #convert in seconds

#consider the time for the follow up
data$TP_WHYTRANSP_FOLLOW_active_time[is.na(data$TP_WHYTRANSP_FOLLOW_active_time)] <- 0 #replace NA by 0 
data$TP_WHYTRANSP_FOLLOW_active_time_s <- data$TP_WHYTRANSP_FOLLOW_active_time/1000 #convert in seconds
#sum both times
data$TP_WHYTRANSP_EXP_active_time_total_s <- data$TP_WHYTRANSP_EXP_active_time_s + data$TP_WHYTRANSP_FOLLOW_active_time_s 

#select only valid
datavalidWHYTRANSP = data %>% filter(VALID_TRANSPC3=="4 Valid")

#prepare data
tibbleTime = meanandmoreby(datavalidWHYTRANSP, TP_WHYTRANSP_EXP_active_time_total_s, GRUPO)
# Select relevant columns and reshape the data using spread
table_time <-  tibbleTime %>%
  select(GRUPO, mean, median) %>% 
  gather(Statistic, Value, mean, median) %>%
  pivot_wider(names_from = GRUPO, values_from = Value) %>%
  separate_rows(Statistic, sep = "_") %>%
  select(1, 2, 5, 3, 4)
```

### Average/Median focus time WHYTRANSP

<center><b>
Focus time: average and median
</center></b>

```{r result_time, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_time, format = "html", col.names = c("Focus time", "Control", "Choice", "PushDictation", "PushRecording"), digits = 0) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(table_time), align = "c")
```

### Tests of significance across groups WHYTRANSP (pairwise T-tests)

<center><b>
Tests differences average focus time
</center></b>
```{r testtime, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testtime=pairwise_t_test(datavalidWHYTRANSP, TP_WHYTRANSP_EXP_active_time_total_s ~ GRUPO)
testtime = testtime %>% 
  select(group1, group2, p, p.signif, p.adj, p.adj.signif)
kable(testtime, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testtime), align = "c")
```

<br>


<i>

### Focus time WHYTRUST

</i>

```{r prep_timetr, message=FALSE, include = FALSE, cache = TRUE}

data$TP_WHYTRUSTNH_EXP_active_time[is.na(data$TP_WHYTRUSTNH_EXP_active_time)] <- 0 #replace NA by 0 
data$TP_WHYTRUSTNH_EXP_active_time_s <- data$TP_WHYTRUSTNH_EXP_active_time/1000 #convert in seconds

#consider the time for the follow up
data$TP_WHYTRUSTNH_FOLLOW_active_time[is.na(data$TP_WHYTRUSTNH_FOLLOW_active_time)] <- 0 #replace NA by 0 
data$TP_WHYTRUSTNH_FOLLOW_active_time_s <- data$TP_WHYTRUSTNH_FOLLOW_active_time/1000 #convert in seconds
#sum both times
data$TP_WHYTRUSTNH_EXP_active_time_total_s <- data$TP_WHYTRUSTNH_EXP_active_time_s + data$TP_WHYTRUSTNH_FOLLOW_active_time_s 

#select only valid
datavalidWHYTRUSTNH = data %>% filter(VALID_TRUSTC3=="4 Valid")

#prepare data
tibbleTimetr = meanandmoreby(datavalidWHYTRUSTNH, TP_WHYTRUSTNH_EXP_active_time_total_s, GRUPO)
# Select relevant columns and reshape the data using spread
table_timetr <-  tibbleTimetr %>%
  select(GRUPO, mean, median) %>% 
  gather(Statistic, Value, mean, median) %>%
  pivot_wider(names_from = GRUPO, values_from = Value) %>%
  separate_rows(Statistic, sep = "_") %>%
  select(1, 2, 5, 3, 4)
```

### Average/Median focus time WHYTRUST

<center><b>
Focus time: average and median
</center></b>

```{r result_timetr, message=FALSE, include = TRUE, cache = TRUE}
# Create the table using kable in R Markdown
kable(table_timetr, format = "html", col.names = c("Focus time", "Control", "Choice", "PushDictation", "PushRecording"), digits = 0) %>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(table_timetr), align = "c")
```

### Tests of significance across groups WHYTRUST (pairwise T-tests)

<center><b>
Tests differences average focus time
</center></b>
```{r testtimetr, message=FALSE, warning=FALSE, include = TRUE, cache = TRUE}
testtimetr=pairwise_t_test(datavalidWHYTRUSTNH, TP_WHYTRUSTNH_EXP_active_time_total_s ~ GRUPO)
testtimetr = testtimetr %>% 
  select(group1, group2, p, p.signif, p.adj, p.adj.signif)
kable(testtimetr, format = "html")%>%
  kable_styling(full_width = FALSE) %>%
  row_spec(0, bold = TRUE) %>%
  row_spec(0:nrow(testtimetr), align = "c")
```

<br>

