2013-03-16 42 views
1

如果我執行我的多元數據的mahalanobis距離與卡方分佈相關的多元qqplot,我預計伴隨的qqline是一個截距爲0和斜率爲1的直線。但是,如果我運行下面的代碼:qqline沒有給出我預期的線

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") 

我得到如下圖所示:

qqplot with abline and qqline

我預計qqline(紅色)是一樣的截距0和斜率線1(黑色)。任何人都可以向我解釋爲什麼這兩行不匹配?

(我運行v版本2.15.3(2013-03-01))

回答

3

默認情況下qqline繪製一條線穿過第一和第三個四分位數。請參閱幫助文件(?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

相關問題