data(english)
# ---- orthogonalize orthographic consistency measures
items = english[english$AgeSubject == "young",]
items.pca = prcomp(items[ , c(18:27)], center = TRUE, scale = TRUE)
x = as.data.frame(items.pca$rotation[,1:4])
items$PC1 = items.pca$x[,1]
items$PC2 = items.pca$x[,2]
items$PC3 = items.pca$x[,3]
items$PC4 = items.pca$x[,4]
items2 = english[english$AgeSubject != "young", ]
items2$PC1 = items.pca$x[,1]
items2$PC2 = items.pca$x[,2]
items2$PC3 = items.pca$x[,3]
items2$PC4 = items.pca$x[,4]
english = rbind(items, items2)
# ---- add Noun-Verb frequency ratio
english$NVratio = log(english$NounFrequency+1)-log(english$VerbFrequency+1)
# ---- build model with ols() from Design
library(Design)
english.dd = datadist(english)
options(datadist = 'english.dd')
english.ols = ols(RTlexdec ~ Voice + PC1 + MeanBigramFrequency +
rcs(WrittenFrequency, 5) + rcs(WrittenSpokenFrequencyRatio, 3) +
NVratio + WordCategory + AgeSubject +
rcs(FamilySize, 3) + InflectionalEntropy +
NumberComplexSynsets + rcs(WrittenFrequency, 5) : AgeSubject,
data = english, x = TRUE, y = TRUE)
# ---- plot partial effects
par(mfrow = c(4, 3), mar = c(4, 4, 1, 1), oma = rep(1, 4))
plot(english.ols, adj.subtitle = FALSE, ylim = c(6.4, 6.9), conf.int = FALSE)
par(mfrow = c(1, 1))
# ---- validate the model
validate(english.ols, bw = TRUE, B = 200)
Run the code above in your browser using DataLab