---
title: "Manipulation Check"
author: "Connor Esterwood"
date: "`r Sys.Date()`"
output: rmdformats::html_clean
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r, include=FALSE}

#Checks packages and installs/loads if needed.

install.packages("pacman")

pacman::p_load(
  rmdformats,
  readxl,
  easystats,
  kableExtra,
  tidyverse,
  formattable,
  gtsummary,
  psych,
  viridis,
  hrbrthemes,
  DT,
  ggsignif,
  ggplot2,
  tidyr,
  viridis,
  hrbrthemes,
  ggpubr,
  dplyr
  )

```


## Read and Summarize Data

```{r, echo=FALSE}

## Read in data
############ WIDE ##############

Data <- read.csv(fileEncoding = "UTF-8-BOM", "Data_Wide.csv")

##############################
## make dataset with a few variables to summarize

summary_dat <- Data %>% dplyr::select(condition)

##############################
## summarize the data

summary_dat %>% tbl_summary() %>% as_kable_extra() %>% kable_classic_2()

```


## Reduce Dataset to Only Manipulation Variables


```{r, echo=FALSE}

Data_Manipulations <- Data[which(
  Data$condition == "No_Error" | Data$condition == "No_Repair"),]

```

## Manipulation Check - Violation 1

```{r, echo=FALSE}

## Conduct Pairwise t.test

pairwise.t.test(Data_Manipulations$Trust_Change_T1,Data_Manipulations$condition, p.adjust.method = "bonferroni")

### Plot Results

T1 <- Data_Manipulations %>%
  ggplot( aes(x=condition, y=Trust_Change_T1, fill=condition)) +
    geom_boxplot(width=.1) +
    geom_jitter(color="black", size=1, alpha=0.1) +
    theme_minimal() +
    scale_fill_ft()+
    geom_signif(comparisons = list(c("No_Error","No_Repair")), map_signif_level = TRUE, annotations = "p < 0.001") +
    theme(
      legend.position="none",
      plot.title = element_text(size=11)
    ) +
    ggtitle("Trust Change Event 01") +
    ylab("Trust Change") +
    xlab("") +
    ylim(-6,3)

T1

```

## Maniplulation Check - Violation 2

```{r, echo=FALSE}

pairwise.t.test(Data_Manipulations$Trust_Change_T2,Data_Manipulations$condition, p.adjust.method = "bonferroni")

### PLOT


T2 <- Data_Manipulations %>%
  ggplot( aes(x=condition, y=Trust_Change_T2, fill=condition)) +
    geom_boxplot(width=.1) +
    geom_jitter(color="black", size=1, alpha=0.1) +
    theme_minimal() +
    scale_fill_ft()+
    geom_signif(comparisons = list(c("No_Error","No_Repair")), map_signif_level = TRUE, annotations = "p = 0.004") +
    theme(
      legend.position="none",
      plot.title = element_text(size=11)
    ) +
    ggtitle("Trust Change Event 02") +
    ylab("Trust Change") +
    xlab("") +
    ylim(-6,3)

T2

```



## Manipulation Check - Violation 3

```{r, echo=FALSE}

pairwise.t.test(Data_Manipulations$Trust_Change_T3,Data_Manipulations$condition, p.adjust.method = "bonferroni")

### PLOT


T3 <- Data_Manipulations %>%
  ggplot( aes(x=condition, y=Trust_Change_T3, fill=condition)) +
    geom_boxplot(width=.1) +
    geom_jitter(color="black", size=1, alpha=0.1) +
    theme_minimal() +
    scale_fill_ft()+
    geom_signif(comparisons = list(c("No_Error","No_Repair")), map_signif_level = TRUE, annotations = "p < 0.001") +
    theme(
      legend.position="none",
      plot.title = element_text(size=11)
    ) +
    ggtitle("Trust Change Event 03") +
    ylab("Trust Change") +
    xlab("") +
    ylim(-6,3)

T3

```

## Combined Publication Ready Plot

```{r}

figure <- ggarrange(T1, T2, T3,
                    labels = c("", "", ""),
                    ncol = 2, nrow = 2)
figure

```