---
title: "Creative flow in dance - mlm of CAT ratings"
author: "Klara Łucznik"
date: "8 April 2017"
output:
  pdf_document: default
  html_document: default
---

This script analyses:
1. Rating difference of high-flow and low-flow vids on scale of creativity and other related concepts: aesthetic appeal (liking), technical demands of dance (technique), meaningfulness of dance (meaningful), and coherence/collaboration (coherent). All analysis are performed separately for experts and non-experts
2. In second part the model of creativity in relation to all other factors is explored.

Data set was tranfromed in S4_analysis

##Data preparation 
Multi-level modelling is performed using MLwiN pack
```{r}
library(readr)
library(dplyr)
S5_long <- read_csv("~/S5_long.csv")

if (!require(lmtest)) install.packages("lmtest")
library(lmtest)
library(R2MLwiN)
options(MLwiN_path = "~/mlnscript")
```
Spliting the data to experts and non-experts cohorts
```{r}
S5_exp <- filter(S5_long, EXP==1)
S5_non <- filter(S5_long, EXP==0)
```

##Experts ratings ~ flow

Aesthetic appeal - Null model | experts
```{r}
(lm <- runMLwiN (liking ~ 1 + (1| ID) + (1 | vid), data = S5_exp))
```
Aesthetic appeal ~ flow | experts
```{r}
(lm1 <- runMLwiN (liking ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = lm@FP, FP.v = lm@FP.cov, RP.b = lm@RP, RP.v = lm@RP.cov)), data = S5_exp))
```
Aesthetic appeal - model comparison | experts
```{r}
lrtest(lm, lm1)
```
Technique - null model | experts
```{r}
(tm <- runMLwiN (technique ~ 1 + (1| ID) + (1 | vid), data = S5_exp))
```
Technique ~ flow | experts
```{r}
(tm1 <- runMLwiN (technique ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = tm@FP, FP.v = tm@FP.cov, RP.b = tm@RP, RP.v = tm@RP.cov)), data = S5_exp))
```
Technique - model comparison | experts
```{r}
lrtest(tm, tm1)
```
Meaningfulness - null model | experts
```{r}
(mm <- runMLwiN (meaningful ~ 1 + (1| ID) + (1 | vid), data = S5_exp))
```
Meaningful ~ flow | experts
```{r}
(mm1 <- runMLwiN (meaningful ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = mm@FP, FP.v = mm@FP.cov, RP.b = mm@RP, RP.v = mm@RP.cov)), data = S5_exp))
```
Meaningfulness - model comparison | experts
```{r}
lrtest(mm, mm1)
```
Coherence - null model | experts
```{r}
(cohm <- runMLwiN (coherent ~ 1 + (1| ID) + (1 | vid), data = S5_exp))
```
Coherence ~ flow | experts
```{r}
(cohm1 <- runMLwiN (coherent ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = cohm@FP, FP.v = cohm@FP.cov, RP.b = cohm@RP, RP.v = cohm@RP.cov)), data = S5_exp))
```
Coherence - model comparison | experts
```{r}
lrtest(cohm, cohm1)
```
Creativity -null model | experts
```{r}
(cm <- runMLwiN (creative ~ 1 + (1| ID) + (1 | vid), data = S5_exp))
```
Creativity ~ flow | experts
```{r}
(cm1 <- runMLwiN (creative ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = cm@FP, FP.v = cm@FP.cov, RP.b = cm@RP, RP.v = cm@RP.cov)), data = S5_exp))
```
Creativitiy - model comparison | experts
```{r}
lrtest(cm, cm1)
```

##Non-experts ratings ~ flow
Aesthetic appeal - null model | non-experts
```{r}
(lmn <- runMLwiN (liking ~ 1 + (1| ID) + (1 | vid), data = S5_non))
```
Aesthetic appeal ~ flow | non-experts
```{r}
(lmn1 <- runMLwiN (liking ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = lmn@FP, FP.v = lmn@FP.cov, RP.b = lmn@RP, RP.v = lmn@RP.cov)), data = S5_non))
```
Aesthetic appeal - model comparison | non-experts
```{r}
lrtest(lmn, lmn1)
```
Technique - null model | non-experts
```{r}
(tmn <- runMLwiN (technique ~ 1 + (1| ID) + (1 | vid), data = S5_non))
```
Technique ~ flow | non-experts
```{r}
(tmn1 <- runMLwiN (technique ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = tmn@FP, FP.v = tmn@FP.cov, RP.b = tmn@RP, RP.v = tmn@RP.cov)), data = S5_non))
```
Technique - model comparison | non-experts
```{r}
lrtest(tmn, tmn1)
```
Meaningfulness - null model | non-experts
```{r}
(mmn <- runMLwiN ( meaningful ~ 1 + (1| ID) + (1 | vid), data = S5_non))
```
Meaningfulness ~ flow | non-experts
```{r}
(mmn1 <- runMLwiN (meaningful ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = mmn@FP, FP.v = mmn@FP.cov, RP.b = mmn@RP, RP.v = mmn@RP.cov)), data = S5_non))
```
Meaningfulness - model comparison | non-experts
```{r}
lrtest(mmn, mmn1)
```
Coherence - null model | non-experts
```{r}
(cohmn <- runMLwiN (coherent~ 1 + (1| ID) + (1 | vid), data = S5_non))
```
Coherence ~ flow | non-experts
```{r}
(cohmn1 <- runMLwiN (coherent ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = cohmn@FP, FP.v = cohmn@FP.cov, RP.b = cohmn@RP, RP.v = cohmn@RP.cov)), data = S5_non))
```
Coherence - model comparison | non-experts
```{r}
lrtest(cohmn, cohmn1)
```
Creativity - null model | non-experts
```{r}
(cmn <- runMLwiN (creative ~ 1 + (1| ID) + (1 | vid), data = S5_non))
```
Creativity ~ flow | non-experts
```{r}
(cmn1 <- runMLwiN (creative ~ 1 + flow +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = cmn@FP, FP.v = cmn@FP.cov, RP.b = cmn@RP, RP.v = cmn@RP.cov)), data = S5_non))
```
Creativity - model comparison | non-experts
```{r}
lrtest(cmn, cmn1)
```

##Creativity model
Centering data
```{r}
S5_exp$cliking <- scale(S5_exp$liking,center = TRUE, scale = TRUE)
S5_exp$ctechnique<- scale(S5_exp$technique,center = TRUE, scale = TRUE)
S5_exp$cmeaningful <- scale(S5_exp$meaningful,center = TRUE, scale = TRUE)
S5_exp$ccoherent <- scale(S5_exp$coherent,center = TRUE, scale = TRUE)
S5_exp$ccreative <- scale(S5_exp$creative,center = TRUE, scale = TRUE)

S5_non$cliking <- scale(S5_non$liking,center = TRUE, scale = TRUE)
S5_non$ctechnique<- scale(S5_non$technique,center = TRUE, scale = TRUE)
S5_non$cmeaningful <- scale(S5_non$meaningful,center = TRUE, scale = TRUE)
S5_non$ccoherent <- scale(S5_non$coherent,center = TRUE, scale = TRUE)
S5_non$ccreative <- scale(S5_non$creative,center = TRUE, scale = TRUE)
```

##1. Experts' creative ratings
```{r}
(CM <- runMLwiN (ccreative ~ 1 + (1| ID) + (1 | vid), data = S5_exp))
```

```{r}
(CM2 <- runMLwiN (ccreative ~ 1 + ctechnique +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = CM@FP, FP.v = CM@FP.cov, RP.b = CM@RP, RP.v = CM@RP.cov)), data = S5_exp))
```
```{r}
lrtest(CM, CM2)
```

```{r}
(CM3 <- runMLwiN (ccreative ~ 1 + ctechnique + cliking + (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = CM2@FP, FP.v = CM2@FP.cov, RP.b = CM2@RP, RP.v = CM2@RP.cov)), data = S5_exp))

```

```{r}
lrtest(CM2, CM3)
```

```{r}
(CM4 <- runMLwiN (ccreative ~ 1 + ctechnique + cliking + cmeaningful + (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = CM3@FP, FP.v = CM3@FP.cov, RP.b = CM3@RP, RP.v = CM3@RP.cov)), data = S5_exp))

```

```{r}
lrtest(CM3, CM4)
```

```{r}
(CM5 <- runMLwiN (ccreative ~ 1 + ctechnique + cliking + cmeaningful + ccoherent + (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = CM4@FP, FP.v = CM4@FP.cov, RP.b = CM4@RP, RP.v = CM4@RP.cov)), data = S5_exp))

```

```{r}
lrtest(CM, CM5)
```

##2. Non-experts' creative ratings
```{r}
(CMN <- runMLwiN (ccreative ~ 1 +  (1| ID) + (1 | vid), data = S5_non))
```

```{r}
(CMN2 <- runMLwiN (ccreative ~ 1 + ctechnique +  (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = CMN@FP, FP.v = CMN@FP.cov, RP.b = CMN@RP, RP.v = CMN@RP.cov)), data = S5_non))
```
```{r}
lrtest(CMN, CMN2)
```

```{r}
(CMN3 <- runMLwiN (ccreative ~ 1 + ctechnique + cliking + (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = CMN2@FP, FP.v = CMN2@FP.cov, RP.b = CMN2@RP, RP.v = CMN2@RP.cov)), data = S5_non))
```
```{r}
lrtest(CMN2, CMN3)
```

```{r}
(CMN4 <- runMLwiN (ccreative ~ 1  + ctechnique + cliking + cmeaningful +(1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = CMN3@FP, FP.v = CMN3@FP.cov, RP.b = CMN3@RP, RP.v = CMN3@RP.cov)), data = S5_non))
```
```{r}
lrtest(CMN3, CMN4)
```

```{r}
(CMN5 <- runMLwiN (ccreative ~ 1  + ctechnique + cliking + cmeaningful + ccoherent + (1| ID) + (1 | vid), estoptions = list(startval = list(FP.b = CMN4@FP, FP.v = CMN4@FP.cov, RP.b = CMN4@RP, RP.v = CMN4@RP.cov)), data = S5_non))
```
```{r}
lrtest(CMN, CMN5)
```



