library(tidyverse)
## ── Attaching packages ───────────────────── tidyverse 1.2.1 ──
## ✓ ggplot2 3.3.0 ✓ purrr 0.3.3
## ✓ tibble 3.0.1 ✓ dplyr 0.8.3
## ✓ tidyr 0.8.99.9000 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 3.5.2
## Warning: package 'purrr' was built under R version 3.5.2
## Warning: package 'dplyr' was built under R version 3.5.2
## Warning: package 'stringr' was built under R version 3.5.2
## Warning: package 'forcats' was built under R version 3.5.2
## ── Conflicts ──────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(here)
## here() starts at /Users/jenny/OneDrive - UNSW/ALL_R_stuff/1. PROJECTS/4. DATA_ANALYSIS/HONOURS2020/JULIA
library(lme4)
## Warning: package 'lme4' was built under R version 3.5.2
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
library(lmerTest)
## Warning: package 'lmerTest' was built under R version 3.5.2
##
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
##
## lmer
## The following object is masked from 'package:stats':
##
## step
# note if you run LMM with just the lme4 package you wont get any pvalues
# loading lmerTest as well gets you pvalues when you test anova(model)
df <- read_csv(here("data", "combined", "5_zdiff_binscreened.csv"))
## Parsed with column specification:
## cols(
## pp_no = col_character(),
## condition = col_character(),
## emotion = col_double(),
## trial = col_character(),
## muscle = col_character(),
## bin = col_character(),
## Zdiff = col_double()
## )
# fix data types, all chars to factors
df$emotion <- as.factor(df$emotion)
df <- df %>% mutate_if(is.character,as.factor)
glimpse(df)
## Rows: 18,576
## Columns: 7
## $ pp_no <fct> pp401, pp401, pp401, pp401, pp401, pp401, pp401, pp401…
## $ condition <fct> dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn,…
## $ emotion <fct> 626, 626, 626, 626, 626, 626, 626, 626, 626, 626, 626,…
## $ trial <fct> trial1, trial1, trial1, trial1, trial1, trial1, trial1…
## $ muscle <fct> brow, brow, brow, brow, brow, brow, cheek, cheek, chee…
## $ bin <fct> bin1, bin2, bin3, bin4, bin5, bin6, bin1, bin2, bin3, …
## $ Zdiff <dbl> 0.149188943, 0.159161634, -0.245679429, -0.559687470, …
Make dataframe with just happy/angry for cheek
dfHA_cheek <- df %>%
filter(emotion %in% c("626", "727")) %>%
filter(muscle == "cheek") %>%
arrange(pp_no, emotion, trial, bin)
glimpse(dfHA_cheek)
## Rows: 4,668
## Columns: 7
## $ pp_no <fct> pp401, pp401, pp401, pp401, pp401, pp401, pp401, pp401…
## $ condition <fct> dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn,…
## $ emotion <fct> 626, 626, 626, 626, 626, 626, 626, 626, 626, 626, 626,…
## $ trial <fct> trial1, trial1, trial1, trial1, trial1, trial1, trial2…
## $ muscle <fct> cheek, cheek, cheek, cheek, cheek, cheek, cheek, cheek…
## $ bin <fct> bin1, bin2, bin3, bin4, bin5, bin6, bin1, bin2, bin3, …
## $ Zdiff <dbl> -0.065056480, 0.063689305, 0.494685856, 1.083790897, 1…
Evidence of mimicry to happy would be evidenced by greater cheek acvitity over time (bin) for happy than angry.
LMM- looking to predict Zdiff from emotion (happy angry), and bin (1-6) and their interaction, allowing intercepts to vary for participant and trial.
lm_model_cheek <- lmer(Zdiff ~ emotion + bin + emotion*bin + (1|pp_no) + (1|trial), data=dfHA_cheek, REML = FALSE)
anova(lm_model_cheek)
## Type III Analysis of Variance Table with Satterthwaite's method
## Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
## emotion 62.252 62.252 1 4188.3 65.589 7.217e-16 ***
## bin 144.069 28.814 5 4184.9 30.358 < 2.2e-16 ***
## emotion:bin 21.863 4.373 5 4185.0 4.607 0.0003405 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(lm_model_cheek)
## Linear mixed model fit by maximum likelihood . t-tests use
## Satterthwaite's method [lmerModLmerTest]
## Formula: Zdiff ~ emotion + bin + emotion * bin + (1 | pp_no) + (1 | trial)
## Data: dfHA_cheek
##
## AIC BIC logLik deviance df.resid
## 11939.5 12034.8 -5954.7 11909.5 4227
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.6553 -0.4834 -0.1722 0.1860 10.6593
##
## Random effects:
## Groups Name Variance Std.Dev.
## pp_no (Intercept) 0.047420 0.21776
## trial (Intercept) 0.005171 0.07191
## Residual 0.949123 0.97423
## Number of obs: 4242, groups: pp_no, 50; trial, 8
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 0.00910 0.06546 142.64672 0.139 0.889623
## emotion727 -0.01724 0.07319 4185.47020 -0.236 0.813770
## binbin2 0.19731 0.07334 4185.00812 2.690 0.007164 **
## binbin3 0.49472 0.07344 4185.04562 6.736 1.85e-11 ***
## binbin4 0.63802 0.07318 4184.88791 8.719 < 2e-16 ***
## binbin5 0.63550 0.07313 4184.84401 8.690 < 2e-16 ***
## binbin6 0.56491 0.07355 4185.11625 7.681 1.95e-14 ***
## emotion727:binbin2 -0.12266 0.10360 4184.95942 -1.184 0.236491
## emotion727:binbin3 -0.36833 0.10353 4184.89917 -3.558 0.000378 ***
## emotion727:binbin4 -0.39241 0.10334 4184.81961 -3.797 0.000148 ***
## emotion727:binbin5 -0.31631 0.10346 4184.89337 -3.057 0.002246 **
## emotion727:binbin6 -0.15180 0.10398 4185.05305 -1.460 0.144375
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) emt727 binbn2 binbn3 binbn4 binbn5 binbn6 e727:2 e727:3
## emotion727 -0.561
## binbin2 -0.560 0.501
## binbin3 -0.559 0.500 0.499
## binbin4 -0.561 0.502 0.501 0.500
## binbin5 -0.562 0.502 0.501 0.501 0.502
## binbin6 -0.559 0.500 0.499 0.498 0.500 0.500
## emtn727:bn2 0.397 -0.706 -0.708 -0.353 -0.355 -0.355 -0.353
## emtn727:bn3 0.397 -0.707 -0.354 -0.709 -0.355 -0.355 -0.353 0.499
## emtn727:bn4 0.398 -0.708 -0.355 -0.354 -0.708 -0.356 -0.354 0.500 0.501
## emtn727:bn5 0.397 -0.707 -0.354 -0.354 -0.355 -0.707 -0.353 0.500 0.500
## emtn727:bn6 0.395 -0.704 -0.353 -0.352 -0.353 -0.354 -0.707 0.497 0.497
## e727:4 e727:5
## emotion727
## binbin2
## binbin3
## binbin4
## binbin5
## binbin6
## emtn727:bn2
## emtn727:bn3
## emtn727:bn4
## emtn727:bn5 0.501
## emtn727:bn6 0.498 0.498
plot(lm_model_cheek)
##### qqplot
qqnorm(resid(lm_model_cheek))
qqline(resid(lm_model_cheek))
Yikes qqplot not good, what to do about that….?
Make dataframe with just happy/angry for BROW
dfHA_brow <- df %>%
filter(emotion %in% c("626", "727")) %>%
filter(muscle == "brow") %>%
arrange(pp_no, emotion, trial, bin)
glimpse(dfHA_brow)
## Rows: 4,668
## Columns: 7
## $ pp_no <fct> pp401, pp401, pp401, pp401, pp401, pp401, pp401, pp401…
## $ condition <fct> dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn, dyn,…
## $ emotion <fct> 626, 626, 626, 626, 626, 626, 626, 626, 626, 626, 626,…
## $ trial <fct> trial1, trial1, trial1, trial1, trial1, trial1, trial2…
## $ muscle <fct> brow, brow, brow, brow, brow, brow, brow, brow, brow, …
## $ bin <fct> bin1, bin2, bin3, bin4, bin5, bin6, bin1, bin2, bin3, …
## $ Zdiff <dbl> 0.149188943, 0.159161634, -0.245679429, -0.559687470, …
Evidence of mimicry to ANGRY would be evidenced by greater brow acvitity over time (bin) for angry than happy.
LMM- looking to predict Zdiff from emotion (happy angry), and bin (1-6) and their interaction, allowing intercepts to vary for participant and trial.
lm_model_brow <- lmer(Zdiff ~ emotion + bin + emotion*bin + (1|pp_no) + (1|trial), data=dfHA_brow, REML = FALSE)
anova(lm_model_brow)
## Type III Analysis of Variance Table with Satterthwaite's method
## Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
## emotion 123.555 123.555 1 4244.1 138.6287 < 2.2e-16 ***
## bin 14.970 2.994 5 4241.0 3.3593 0.004959 **
## emotion:bin 29.645 5.929 5 4241.0 6.6523 3.524e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(lm_model_brow)
## Linear mixed model fit by maximum likelihood . t-tests use
## Satterthwaite's method [lmerModLmerTest]
## Formula: Zdiff ~ emotion + bin + emotion * bin + (1 | pp_no) + (1 | trial)
## Data: dfHA_brow
##
## AIC BIC logLik deviance df.resid
## 11827.3 11922.8 -5898.6 11797.3 4283
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.2590 -0.4120 -0.1134 0.1939 11.4263
##
## Random effects:
## Groups Name Variance Std.Dev.
## pp_no (Intercept) 0.047736 0.21849
## trial (Intercept) 0.003859 0.06212
## Residual 0.891266 0.94407
## Number of obs: 4298, groups: pp_no, 50; trial, 8
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 4.107e-02 6.296e-02 1.718e+02 0.652 0.515066
## emotion727 5.092e-02 7.068e-02 4.242e+03 0.720 0.471288
## binbin2 4.463e-03 7.082e-02 4.241e+03 0.063 0.949751
## binbin3 -1.978e-01 7.058e-02 4.241e+03 -2.803 0.005084 **
## binbin4 -1.533e-01 7.077e-02 4.241e+03 -2.166 0.030381 *
## binbin5 -1.038e-01 7.072e-02 4.241e+03 -1.467 0.142316
## binbin6 -1.187e-02 7.102e-02 4.241e+03 -0.167 0.867272
## emotion727:binbin2 1.221e-01 9.994e-02 4.241e+03 1.222 0.221793
## emotion727:binbin3 3.954e-01 9.977e-02 4.241e+03 3.963 7.51e-05 ***
## emotion727:binbin4 4.273e-01 9.970e-02 4.241e+03 4.286 1.86e-05 ***
## emotion727:binbin5 4.266e-01 9.970e-02 4.241e+03 4.279 1.92e-05 ***
## emotion727:binbin6 3.592e-01 1.001e-01 4.241e+03 3.587 0.000338 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) emt727 binbn2 binbn3 binbn4 binbn5 binbn6 e727:2 e727:3
## emotion727 -0.568
## binbin2 -0.566 0.505
## binbin3 -0.568 0.506 0.505
## binbin4 -0.567 0.505 0.504 0.506
## binbin5 -0.567 0.505 0.504 0.506 0.505
## binbin6 -0.565 0.503 0.502 0.504 0.502 0.503
## emtn727:bn2 0.401 -0.707 -0.709 -0.358 -0.357 -0.357 -0.356
## emtn727:bn3 0.402 -0.708 -0.357 -0.707 -0.358 -0.358 -0.356 0.501
## emtn727:bn4 0.402 -0.709 -0.358 -0.359 -0.710 -0.358 -0.357 0.501 0.502
## emtn727:bn5 0.402 -0.709 -0.358 -0.359 -0.358 -0.709 -0.357 0.501 0.502
## emtn727:bn6 0.401 -0.706 -0.356 -0.357 -0.356 -0.357 -0.709 0.499 0.500
## e727:4 e727:5
## emotion727
## binbin2
## binbin3
## binbin4
## binbin5
## binbin6
## emtn727:bn2
## emtn727:bn3
## emtn727:bn4
## emtn727:bn5 0.503
## emtn727:bn6 0.500 0.500
plot(lm_model_brow)
##### qqplot
qqnorm(resid(lm_model_brow))
qqline(resid(lm_model_brow))
Yikes qqplot not good, what to do about that….?