Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming a QQ plot

I have a sample of math test scores for male and female students. I want to draw QQ plot for each gender to see if each of them is normally distributed. I know how to draw the QQ plot for the overall sample, but how can I draw them separately?

like image 639
zca0 Avatar asked Nov 12 '11 11:11

zca0


1 Answers

Here is a simple solution using base graphics:

scores <- rnorm(200, mean=12, sd=2)
gender <- gl(2, 50, labels=c("M","F"))
opar <- par(mfrow=c(1,2))
for (g in levels(gender))
  qqnorm(scores[gender==g], main=paste("Gender =", g))
par(opar)

A more elegant lattice solution then:

qqmath(~ scores | gender, data=data.frame(scores, gender), type=c("p", "g"))

See the on-line help for qqmath for more discussion and example of possible customization.

like image 110
chl Avatar answered Sep 26 '22 17:09

chl