Mes données sont des temps de lecture, par région, pour les phrases d'une expérience, items expérimentaux et fillers. Mes variables fixes sont : Relativiser (2modalités) et Attachment (2modalités). Les variables aléatoires sont Participant et ItemNbr.
Je veux réaliser une analyse où une autre variable continue BiasValue est une covariable d'Attachment : je veux enlever la variance de l'effet d'Attachment due à BiasValue.
J'ai procédé comme suit pour l'analyse :
1- Distribution des données pour "fitting"
Code : Tout sélectionner
library(lme4)
library(languageR)
SPR = read.table("DataWord.txt", header=TRUE) # read data
# fixed factors are Relativiser (qui, lequel), Attachment (N1, N2)
# BiasValue is the result from a pretest evaluating a bias for one construction
over an other, used as covariable with Attachment
# random factors are Participant and ItemNbr
# the dependant variable is RT
# the "Word" column distinguish between FILLERS and experimental words, coded
for their function in the sentence
###### data transformation: classical log or a transformation fitting the
distribution better
# Box-Cox transform
SPR.lm <- lm(RT ~ Relativiser * Attachment + Participant + ItemNbr + BiasValue,
data = SPR)
SPR.bc <- MASS:::boxcox(SPR.lm)
SPR.bc$x[which.max(SPR.bc$y)]
# the result suggest an inverse square root transform would be best
# comparison between a log transform and an inverse square root transform
SPR.lm <- lm(log(RT) ~ Relativiser * Attachment + Participant + ItemNbr +
BiasValue, data = SPR)
SPR.lm2 <- lm(I(RT^(-1/2)) ~ Relativiser * Attachment + Participant + ItemNbr +
BiasValue, data = SPR)
par(mfrow = c(2, 2))
plot(SPR.lm, which = 1:2)
plot(SPR.lm2, which = 1:2)
# the 2nd transformation is better
SPR$transRT <- I((SPR$RT)^(-1/2))
2- Enlever les participants aux RT déviant
Code : Tout sélectionner
# identification of deviant participants
abs(scale(unlist(lapply(split(SPR$transRT, as.factor(as.character(SPR$Participant))), mean)))) < 3
abs(scale(unlist(lapply(split(SPR$transRT, as.factor(as.character(SPR$Participant))), mean)))) < 2.5
abs(scale(unlist(lapply(split(SPR$transRT, as.factor(as.character(SPR$Participant))), mean)))) < 2
# exclude deviant participants
SPR.RTcor <- subset(SPR, Participant != ("IM") , Participant != ("PL"))
SPR.RTcorr <- subset(SPR, Participant != ("AF"))
3- comparaison des distributions selon 2 transformations, avec et sans déviants
Code : Tout sélectionner
#### comparison of data distributions, without deviants
SPR.lm3 <- lm(transRT ~ Relativiser * Attachment + Participant + ItemNbr + BiasValue, data = SPR.RTcorr)
par(mfrow = c(2, 2))
plot(SPR.lm2, which = 1:2)
plot(SPR.lm3, which = 1:2)
# maybe delete the deviant data points as seen in the graph
4- régression pour calculer les RT résiduels (classique pour ce type d'expérience)
Code : Tout sélectionner
# regression against Nbr of characters, position in the sentence and in the list
SPR.anal = lmer(transRT ~ CharNbr + WdNbr + SentNbr + (1| Participant), SPR.RTcorr)
# residual RTs
SPR.RTcorr$RTResidual <- residuals(SPR.anal)
# centering
SPR.RTcorr$cRelativiser <- as.numeric(scale(ifelse(SPR.RTcorr$Relativiser == "Qui",1,0), scale=F))
SPR.RTcorr$cAttachment <- as.numeric(scale(ifelse(SPR.RTcorr$Attachment == "N1",1,0), scale=F))
SPR.RTcorr$cBiasValue <- as.numeric(scale(SPR.RTcorr$BiasValue, scale=F))
# subset for experimental data only
SPR.exp <- subset(SPR.RTcorr, Word != "FILLER")
5- évaluation de la collinéarité
Code : Tout sélectionner
# analysis for experimental trials only and log transformed residual RTs
SPR.anal = lmer(RTResidual ~ cRelativiser * cAttachment + (1|Participant) + (1|ItemNbr) + cBiasValue, data=SPR.exp)
summary(SPR.anal)
# the highest value is 0.57
6- régression avec les résidus
Code : Tout sélectionner
# regression with residuals
SPR.exp$iRelAtt <- residuals(lm(I(cRelativiser * cAttachment) ~ cRelativiser + cAttachment, SPR.exp))
SPR.anal1 = lmer(RTResidual ~ cRelativiser + cAttachment + iRelAtt + (1|Participant) + (1|ItemNbr) + cBiasValue, data=SPR.exp)
summary(SPR.anal)
# the highest value is 0.57
##### is there collinearity problem?
7- analyse pour une région de la phrase
Code : Tout sélectionner
#### analysis of the data word by word, here with RELATIVISER ONLY
#### Relativiser and Attachment are two fixed factors and BiasValue should be a covariate for Attachment, to remove the variance due to BiasValue
SPR.RELATIVISER <- subset (SPR.exp, Word == "Rel")
SPR.RELATIVISER = lmer(RTResidual ~Relativiser*Attachment + (1|Participant) + (1|ItemNbr) + BiasValue, data=SPR.RELATIVISER)
summary(SPR.RELATIVISER) # Print results of LME analysis
plot(fitted(SPR.RELATIVISER), residuals(SPR.RELATIVISER))
qqnorm(residuals(SPR.RELATIVISER))
SPR.RELATIVISER.mc <- mcmcsamp(SPR.RELATIVISER, 10000)
densityplot(SPR.RELATIVISER.mc)
qqmath(SPR.RELATIVISER.mc)
xyplot(SPR.RELATIVISER.mc)
HPDinterval(SPR.RELATIVISER.mc)
# I get an error for HPDinterval
J'aimerais savoir si le script est correct et surtout si dans SPR.RELATIVISER je mets bien BiasValue comme covariable (je n'ai pas trouvé comment faire).
J'ai un message d'erreur pour "HPDinterval(SPR.RELATIVISER.mc)"
Erreur dans UseMethod("HPDinterval") :
pas de méthode applicable pour "HPDinterval"
Cela fait beaucoup de questions...
Merci beaucoup.