Learn R Programming

languageR (version 1.5.0)

shrinkage: Data set illustrating shrinkage

Description

Simulated data set for illustrating shrinkage.

Usage

data(shrinkage)

Arguments

Format

A data frame with 200 observations on the following 6 variables.

intercept

a numeric vector for the intercept.

frequency

a numeric vector for word frequency.

subject

a factor for subjects with levels S1, S2, ... , S10.

error

a numeric vector for residuals.

ranef

a numeric vector for random effect.

RT

a numeric vector for simulated RTs.

Examples

Run this code
# NOT RUN {
data(shrinkage)

require(lme4)
require(lmerTest)
require(optimx)

shrinkage.lmer = lmer(RT ~ frequency + (1|subject), 
  data = shrinkage,
  control=lmerControl(optimizer="optimx",optCtrl=list(method="nlminb"))
shrinkage.lmList = lmList(RT ~ frequency | subject, data = shrinkage)

# and visualize the difference between random regression 
# and mixed-effects regression

mixed = coef(shrinkage.lmer)[[1]]
random = coef(shrinkage.lmList)
subj = unique(shrinkage[,c("subject", "ranef")])
subj = subj[order(subj$subject),]
subj$random = random[,1]
subj$mixed = mixed[,1]
subj = subj[order(subj$random),]
subj$rank = 1:nrow(subj)

par(mfrow=c(1,2))
plot(subj$rank, subj$random, xlab="rank", ylab="RT", ylim=c(200,550), type="n")
text(subj$rank, subj$random, as.character(subj$subject), cex=0.8, col="red")
mtext("random regression", 3, 1)
points(subj$rank, 400+subj$ranef, col="blue")
abline(h=400)
plot(subj$rank, subj$mixed, xlab="rank", ylab="RT", ylim=c(200,550), type="n")
text(subj$rank, subj$mixed, as.character(subj$subject), cex=0.8, col = "red")
mtext("mixed-effects regression", 3, 1)
points(subj$rank, 400+subj$ranef, col="blue")
abline(h=400)
par(mfrow=c(1,1))
# }

Run the code above in your browser using DataLab