1 Formatting options

2 Set-up

3 Data management

In this section, we load the exam scores data set, activate the help page for it, and examine the first 6 lines of the data frame object.

# load the package to working directory
library(mlmRev)
# load the data from the package
data(Exam, package="mlmRev")
# invoke help document
?Exam
# view first 6 lines
head(Exam)
  school  normexam schgend   schavg      vr     intake  standLRT sex type
1      1  0.261324   mixed 0.166175 mid 50% bottom 25%  0.619059   F  Mxd
2      1  0.134067   mixed 0.166175 mid 50%    mid 50%  0.205802   F  Mxd
3      1 -1.723882   mixed 0.166175 mid 50%    top 25% -1.364576   M  Mxd
4      1  0.967586   mixed 0.166175 mid 50%    mid 50%  0.205802   F  Mxd
5      1  0.544341   mixed 0.166175 mid 50%    mid 50%  0.371105   F  Mxd
6      1  1.734899   mixed 0.166175 mid 50% bottom 25%  2.189437   M  Mxd
  student
1     143
2     145
3     142
4     141
5     138
6     155

4 Summary statistics

We first compute the correlation coefficient between exam scores and LRT scores using all students in the data set. We then compute the mean exam scores and mean LRT scores by school. The correlation coefficient between mean school exam scores and mean school LRT scores is then calculated.

with(Exam, cor(normexam, standLRT))
[1] 0.59165
# compute the means by school
mLRT <- with(Exam, tapply(standLRT, school, mean))
mexam <- with(Exam, tapply(normexam, school, mean))
cor(mexam, mLRT)
[1] 0.692412

5 Visualization

We draw a scatter diagram of the exam scores against the LRT scores and add the regression line. Next we superimpose on the scatter plot the mean school exam scores and mean school LRT scores (in color cyan) and add the regression line based on the mean school scores.

with(Exam, plot(normexam ~ standLRT, 
                bty = 'n', 
                cex = 0.5,
                xlab = 'Standardized LR test score', 
                ylab = 'Normalized exam score'))
grid()
with(Exam, abline(lm(normexam ~ standLRT)))
points(mLRT, mexam, pch=16, col=5)
abline(lm(mexam ~ mLRT), col=5)

6 References

Goldstein, H., Rasbash, J., et al (1993). A multilevel analysis of school examination results. Oxford Review of Education, 19, 425-433.