R code for mixed linear models - Written by Rebecca Keogh - lme4 package

library (“lme4”)

setwd ("~/Desktop/Manuscripts/tDCS_Imagery/tdcs_imagery”) % Sets path - use cd of where csv is
%% Can also do this by going to misc and changing by hand

data = read.csv("data.csv") % Loads data 

which(!complete.cases(data)) % Shows which have missing data

%%make variable categorical

data$order = factor(c(data$order))
data$block = factor(c(data$block))
data$tDCS = factor(c(data$tDCS))

%%check

data$order 
data$block
data$tDCS 

%% Only intercept not slope

tdcs.model = lmer(imagery ~ tDCS + block + order + (1|subject) ,
data=data, REML=FALSE) %Runs LME on data - subjects is random effect with intercept + slope controlled for - rest are fixed

summary(tdcs.model) %Prints model variables etc

tdcs.null = lmer(imagery ~ block + order + (1|subject),
data=data, REML=FALSE) %Runs LME on null model - subjects is random effect with intercept + slope controlled for - rest are fixed

summary(tdcs.null) %Prints model variables etc

Anova

%% Assumptions

plot(fitted(tdcs.model),residuals(tdcs.model)) % Linearity want to see random spatter of blobs dots - also homoscadaicty

hist(residuals(tdcs.model)) - normality 

qqnorm(residuals(tdcs.model)) - normality - should form diagonal line

anova(tdcs.model,tdcs.null)