Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qqline does not give the line that I expected

If I perform a multivariate qqplot of the mahalanobis distance of my multivariate data plotted against the Chi-squared distribution, I expect the accompanying qqline to be a line with intercept 0 and slope 1. But if I run the following code:

scores<-matrix(rnorm(100*3),nc=3)
mah_scores = mahalanobis(scores,center=colMeans(scores),cov=cov(scores))
chi_scores = qchisq(ppoints(nrow(scores)),df=3)
qqplot(x=chi_scores,y=mah_scores,asp=1)
abline(a=0,b=1)
qqline(mah_scores, distribution = function(p) qchisq(p,df = 3),col="red")

I get the following figure:

qqplot with abline and qqline

I expected the qqline (in red) to be the same as the line with intercept 0 and slope 1 (in black). Can anyone explain to me why these 2 lines don't match up?

(I'm running R version 2.15.3 (2013-03-01))

like image 772
Peter Avatar asked Nov 26 '25 16:11

Peter


1 Answers

By default qqline draws a line through the first and third quartiles. See the help file (?qqline).

#highlight first and third quartiles
points(quantile(chi_scores,c(.25,.75)),
       quantile(mah_scores,c(.25,.75)),col="blue",cex=2,bg="blue",pch=21)

enter image description here

like image 135
Roland Avatar answered Nov 28 '25 15:11

Roland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!