table <- read.csv ("data_for_R.Table", sep='\t', stringsAsFactors=TRUE)
head (table, 20)
## P SE SL PL O SG PE Correct Nativity Order S
## 1 P1 Disgusted E E EG F Disgusted 1 Native NF S4
## 2 P1 Neutral E E EG M Neutral 1 Native NF S3
## 3 P1 Sad E E EG F Sad 1 Native NF S2
## 4 P1 Sad E E EG M Neutral 0 Native NF S5
## 5 P1 Happy E E EG M Happy 1 Native NF S1
## 6 P1 Neutral E E EG F Neutral 1 Native NF S4
## 7 P1 Happy E E EG F Happy 1 Native NF S4
## 8 P1 Happy E E EG M Disgusted 0 Native NF S3
## 9 P1 Angry E E EG M Angry 1 Native NF S3
## 10 P1 Happy E E EG M Happy 1 Native NF S5
## 11 P1 Disgusted E E EG M Disgusted 1 Native NF S5
## 12 P1 Sad E E EG F Sad 1 Native NF S6
## 13 P1 Happy E E EG F Happy 1 Native NF S2
## 14 P1 Disgusted E E EG F Disgusted 1 Native NF S2
## 15 P1 Angry E E EG M Angry 1 Native NF S5
## 16 P1 Disgusted E E EG F Disgusted 1 Native NF S6
## 17 P1 Afraid E E EG M Afraid 1 Native NF S5
## 18 P1 Sad E E EG M Neutral 0 Native NF S1
## 19 P1 Afraid E E EG F Afraid 1 Native NF S6
## 20 P1 Sad E E EG M Sad 1 Native NF S3
nativity.contrast <- cbind (c(-0.5, +0.5)) # Foreign = -0.5; Native = +0.5
colnames (nativity.contrast) <- c("-F+N")
contrasts (table$Nativity) <- nativity.contrast
contrasts (table$Nativity)
## -F+N
## Foreign -0.5
## Native 0.5
language.contrast <- cbind (c(-0.5, +0.5)) # E = -0.5; G = +0.5
colnames (language.contrast) <- c("-E+G")
contrasts (table$PL) <- language.contrast
contrasts (table$PL)
## -E+G
## E -0.5
## G 0.5
gender.contrast <- cbind (c(+0.5, -0.5)) # F = +0.5; M = -0.5
colnames (gender.contrast) <- c("-M+F")
contrasts (table$SG) <- gender.contrast
contrasts (table$SG)
## -M+F
## F 0.5
## M -0.5
order.contrast <- cbind (c(+0.5, -0.5)) # FN = +0.5; NF = -0.5
colnames (order.contrast) <- c("-NF+FN")
contrasts (table$Order) <- order.contrast
contrasts (table$Order)
## -NF+FN
## FN 0.5
## NF -0.5
model <- lme4::glmer (Correct ~ Nativity * (SG * PL + Order) + (Nativity * SG | P) + (Nativity * (PL + Order) | S), data=table, family=binomial, control = lme4::glmerControl(optCtrl = list(maxfun = 1e5)))
## boundary (singular) fit: see help('isSingular')
summary (model)
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula: Correct ~ Nativity * (SG * PL + Order) + (Nativity * SG | P) +
## (Nativity * (PL + Order) | S)
## Data: table
## Control: lme4::glmerControl(optCtrl = list(maxfun = 1e+05))
##
## AIC BIC logLik deviance df.resid
## 1424.5 1640.7 -671.2 1342.5 1399
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.9945 0.2743 0.4148 0.5250 0.7508
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## P (Intercept) 0.00000 0.0000
## Nativity-F+N 0.10471 0.3236 NaN
## SG-M+F 0.03576 0.1891 NaN 1.00
## Nativity-F+N:SG-M+F 0.06471 0.2544 NaN 0.87 0.91
## S (Intercept) 0.15578 0.3947
## Nativity-F+N 0.15682 0.3960 -0.77
## PL-E+G 0.07417 0.2723 0.47 0.20
## Order-NF+FN 0.06583 0.2566 0.99 -0.86 0.32
## Nativity-F+N:PL-E+G 0.58482 0.7647 -0.98 0.87 -0.30 -1.00
## Nativity-F+N:Order-NF+FN 0.05964 0.2442 -0.32 -0.35 -0.99 -0.17
##
##
##
##
##
##
##
##
##
##
## 0.15
## Number of obs: 1440, groups: P, 20; S, 12
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.621277 0.150415 10.779 <2e-16 ***
## Nativity-F+N 0.008678 0.223893 0.039 0.9691
## SG-M+F 0.396764 0.279421 1.420 0.1556
## PL-E+G 0.365161 0.211143 1.729 0.0837 .
## Order-NF+FN 0.378694 0.162891 2.325 0.0201 *
## SG-M+F:PL-E+G 0.292192 0.454462 0.643 0.5203
## Nativity-F+N:SG-M+F -0.111476 0.440135 -0.253 0.8001
## Nativity-F+N:PL-E+G -0.887944 0.602567 -1.474 0.1406
## Nativity-F+N:Order-NF+FN 0.166064 0.327351 0.507 0.6119
## Nativity-F+N:SG-M+F:PL-E+G -1.126683 1.176721 -0.957 0.3383
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) Nt-F+N SG-M+F PL-E+G O-NF+F SG-M+F: Nt-F+N:SG-M+F N-F+N:P
## Nativty-F+N -0.365
## SG-M+F 0.093 0.020
## PL-E+G 0.385 -0.010 0.076
## Order-NF+FN 0.402 -0.193 -0.034 0.065
## SG-M+F:PL-E 0.090 -0.030 0.350 0.205 0.019
## Nt-F+N:SG-M+F -0.013 0.201 -0.273 -0.013 0.017 0.181
## N-F+N:PL-E+ -0.600 0.359 -0.076 -0.382 -0.180 -0.049 0.054
## N-F+N:O-NF+ -0.027 0.011 -0.013 -0.070 -0.027 -0.014 -0.014 -0.025
## N-F+N:SG-M+F: -0.094 0.087 -0.541 -0.089 -0.035 -0.333 0.320 0.195
## N-F+N:O
## Nativty-F+N
## SG-M+F
## PL-E+G
## Order-NF+FN
## SG-M+F:PL-E
## Nt-F+N:SG-M+F
## N-F+N:PL-E+
## N-F+N:O-NF+
## N-F+N:SG-M+F: 0.013
## optimizer (Nelder_Mead) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
library (ggplot2)
ggplot(data = table,aes(x=Nativity,y=Correct,col=PL)) + geom_jitter() + facet_wrap(~PL)
xtabs(~ (PE + SE) + (SL + PL), data = table)
## , , SL = E, PL = E
##
## SE
## PE Afraid Angry Disgusted Happy Neutral Sad
## Afraid 58 0 0 3 0 13
## Angry 2 57 14 4 0 0
## Disgusted 0 3 46 7 0 2
## Happy 0 0 0 40 2 3
## Neutral 0 0 0 3 58 5
## Sad 0 0 0 3 0 37
##
## , , SL = G, PL = E
##
## SE
## PE Afraid Angry Disgusted Happy Neutral Sad
## Afraid 48 1 6 2 1 3
## Angry 1 54 0 4 0 1
## Disgusted 0 3 30 5 0 0
## Happy 2 2 4 43 0 0
## Neutral 8 0 4 6 51 5
## Sad 1 0 16 0 8 51
##
## , , SL = E, PL = G
##
## SE
## PE Afraid Angry Disgusted Happy Neutral Sad
## Afraid 56 0 1 6 0 6
## Angry 0 60 10 6 0 0
## Disgusted 0 0 46 7 0 0
## Happy 1 0 0 34 0 0
## Neutral 0 0 2 4 60 7
## Sad 3 0 1 3 0 47
##
## , , SL = G, PL = G
##
## SE
## PE Afraid Angry Disgusted Happy Neutral Sad
## Afraid 39 1 4 1 0 4
## Angry 2 56 2 1 0 0
## Disgusted 2 1 44 0 0 0
## Happy 6 1 1 49 0 0
## Neutral 7 1 2 9 58 7
## Sad 4 0 7 0 2 49