---
title: "CIN exploratory analysis personality"
author: "Marijn Struiksma"
#date: "`r Sys.Date()`"
date: "12-05-2022"
output: 
  word_document:
    reference_docx: CIN_template.docx
    toc: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE)
```
```{r message=FALSE, warning=FALSE }
library(readr)
library(doBy)
library(psych)
library(lme4)
library(lmerTest)
library(ggplot2)
library(emmeans)
library(sjPlot)
library(sjmisc)
library(sjlabelled)
library(tidyverse)
library(dplyr)
library(papaja)
library(readxl)
```

# Personality traits

In this exploratory analysis we will add the scores from different questionnaires to the final modals of the EEG analysis. We measured 7 different personality traits:
1 STAI state anxiety
2 STAI trait anxiety
3 Rosenberg self-esteem
4 IRI, Perspective taking, Empathic concent, Fantasy scale and Personal distress
5 Connor-Davidson resilience scale
6 Outlook
7 Resilience

We first load the EEG and personality data.

```{r readdata} 
#load the EEG data for analysis
load("CBN_EEG_trial_data_for_MLM_analysis_79sjs.RData")
Questionnaires_7scores <- read_excel("Questionnaires_7scores.xlsx")
load("CBN_SCR_trial_data_for_MLM_analysis_79sjs.RData")
```

We then combine the EEG and personality data and standardize the personality scores.

```{r preprocessing EEG, eval=TRUE, results="hide", echo=FALSE, warning=FALSE}
data_combined <- left_join(EEGdata, Questionnaires_7scores, by = c("Participant" = "Subject Code"),copy = FALSE)

# Scaling variables and checking the averages
data_combined$STAIstate=scale(data_combined$`1STAIstate`)
dim(data_combined$STAIstate);str(data_combined$STAIstate)
hist(data_combined$STAIstate)

data_combined$STAItrait=scale(data_combined$`2STAItrait`)
dim(data_combined$STAItrait);str(data_combined$STAItrait)
hist(data_combined$STAItrait)
  
data_combined$RSE=scale(data_combined$`3RSE`)
dim(data_combined$RSE);str(data_combined$RSE)
hist(data_combined$RSE)
  
data_combined$PT=scale(data_combined$`4PT`)
dim(data_combined$PT);str(data_combined$PT)
hist(data_combined$PT)
  
data_combined$EC=scale(data_combined$`4EC`)
dim(data_combined$EC);str(data_combined$EC)
hist(data_combined$EC)
  
data_combined$FS=scale(data_combined$`4FS`)
dim(data_combined$FS);str(data_combined$FS)
hist(data_combined$FS)
  
data_combined$PD=scale(data_combined$`4PD`)
dim(data_combined$PD);str(data_combined$PD)
hist(data_combined$PD)
  
data_combined$CDRisc=scale(data_combined$`5CDRisc`)
dim(data_combined$CDRisc);str(data_combined$CDRisc)
hist(data_combined$CDRisc)
  
data_combined$Outlook=scale(data_combined$`6Outlook`)
dim(data_combined$Outlook);str(data_combined$Outlook)
hist(data_combined$Outlook)
  
data_combined$Resilience=scale(data_combined$`7Resilience`)
dim(data_combined$Resilience);str(data_combined$Resilience)
hist(data_combined$Resilience)
  
```

# 200-250ms window

```{r eval=TRUE}
# Take the best model and compare to a model with personality traits
P2M1b<-lmer(P2_200.250.m ~ SpeechAct+BlockCent+(1|Participant)+(1|item),data=data_combined,REML = F)
#summary(P2M1b)
P2M1b_personality<-lmer(P2_200.250.m ~ SpeechAct+BlockCent+STAIstate+STAItrait+RSE+PT+EC+FS+PD+CDRisc+Outlook+Resilience +(1|Participant)+(1|item),data=data_combined,REML = F);summary(P2M1b_personality)

anova(P2M1b,P2M1b_personality) # p=.59 not significant, so P2M1b is a sparser model

```
The best model is still the original model without the personality traits.

# 350-450ms window

```{r eval=TRUE} 
# Take the best model and compare to a model with personality traits
N400M4a<-lmer(N400_350.450.m ~ SpeechAct + Person + BlockCent + Block2Cent + SpeechAct:BlockCent + (1|Participant)+(1|item),data=data_combined,REML = F)
#summary(N400M4a)
N400M4a_personality<-lmer(N400_350.450.m ~ SpeechAct + Person + BlockCent + Block2Cent + SpeechAct:BlockCent +STAIstate+STAItrait+RSE+PT+EC+FS+PD+CDRisc+Outlook+Resilience + (1|Participant)+(1|item),data=data_combined,REML = F); summary(N400M4a_personality)

anova(N400M4a,N400M4a_personality) # p=.89 not significant, so N400M4a is a sparser model

```
The best model is still the original model without the personality traits.

# 500-650ms window

```{r eval=TRUE} 
# Take the best model and compare to a model with personality traits
LPPM11g<-lmer(LPP_500.650.m ~ SpeechAct + Person + BlockCent + Block2Cent + SpeechAct:BlockCent + Person:Block2Cent + (1 | Participant) + (1 | item), data=data_combined,REML = F)
#summary(LPPM11g)
LPPM11g_personality<-lmer(LPP_500.650.m ~ SpeechAct + Person + BlockCent + Block2Cent + SpeechAct:BlockCent + Person:Block2Cent +STAIstate+STAItrait+RSE+PT+EC+FS+PD+CDRisc+Outlook+Resilience  + (1 | Participant) + (1 | item), data=data_combined,REML = F); summary(LPPM11g_personality)

anova(LPPM11g,LPPM11g_personality) # p=.90 not significant, so LPPM11g is a sparser model

```
The best model is still the original model without the personality traits.

# SCR
```{r preprocessing SCR, eval=TRUE, include=FALSE, echo=FALSE, warning=FALSE}
scr_combined <- left_join(SCRdata, Questionnaires_7scores, by = c("Participant" = "Subject Code"),copy = FALSE)

# Scaling variables and checking the averages
scr_combined$STAIstate=scale(scr_combined$`1STAIstate`)
dim(scr_combined$STAIstate);str(scr_combined$STAIstate)
hist(scr_combined$STAIstate)

scr_combined$STAItrait=scale(scr_combined$`2STAItrait`)
dim(scr_combined$STAItrait);str(scr_combined$STAItrait)
hist(scr_combined$STAItrait)
  
scr_combined$RSE=scale(scr_combined$`3RSE`)
dim(scr_combined$RSE);str(scr_combined$RSE)
hist(scr_combined$RSE)
  
scr_combined$PT=scale(scr_combined$`4PT`)
dim(scr_combined$PT);str(scr_combined$PT)
hist(scr_combined$PT)
  
scr_combined$EC=scale(scr_combined$`4EC`)
dim(scr_combined$EC);str(scr_combined$EC)
hist(scr_combined$EC)
  
scr_combined$FS=scale(scr_combined$`4FS`)
dim(scr_combined$FS);str(scr_combined$FS)
hist(scr_combined$FS)
  
scr_combined$PD=scale(scr_combined$`4PD`)
dim(scr_combined$PD);str(scr_combined$PD)
hist(scr_combined$PD)
  
scr_combined$CDRisc=scale(scr_combined$`5CDRisc`)
dim(scr_combined$CDRisc);str(scr_combined$CDRisc)
hist(scr_combined$CDRisc)
  
scr_combined$Outlook=scale(scr_combined$`6Outlook`)
dim(scr_combined$Outlook);str(scr_combined$Outlook)
hist(scr_combined$Outlook)
  
scr_combined$Resilience=scale(scr_combined$`7Resilience`)
dim(scr_combined$Resilience);str(scr_combined$Resilience)
hist(scr_combined$Resilience)
  
```


```{r eval=TRUE, out.width="50%"} 
# Take the best model and compare to a model with personality traits
SCRM9d<-lmer(logISCR.m ~ SpeechAct + Person + BlockCent + Block2Cent + Person:BlockCent + Person:Block2Cent + BlockCent:Block2Cent + (1 | Participant), data=scr_combined,REML = F)
#summary(SCRM9d)
SCRM9d_personality<-lmer(logISCR.m ~ SpeechAct + Person + BlockCent + Block2Cent + Person:BlockCent + Person:Block2Cent + BlockCent:Block2Cent +STAIstate+STAItrait+RSE+PT+EC+FS+PD+CDRisc+Outlook+Resilience + (1 | Participant), data=scr_combined,REML = F); summary(SCRM9d_personality)

anova(SCRM9d,SCRM9d_personality) # p=.45 not significant, so SCRM9d is a sparser model

```
The best model is still the original model without the personality traits.
