简体   繁体   English

R:带有回归线的格子QQ图

[英]R: Lattice Q-Q Plot with regression Line

I can create a lattice qq-plot with: 我可以使用以下方法创建一个晶格qq图:

qqnorm(surfchem.cast$Con)

but I have not learned how to add a panel.abline or prepane.qqmathline() . 但是我还没有学会如何添加panel.ablineprepane.qqmathline()

I've looked in the lattice graphics book and searched the web without finding the correct syntax. 我看了看格子图形书籍,然后在网上搜索时找不到正确的语法。 A pointer to how to add this line representing the linear relationship between theoretical and data quantiles will be greatly appreciated. 将会非常感谢有关如何添加代表理论分位数和数据分位数之间线性关系的这条线的指针。 I also do not find a question here where the answer is for a qq plot rather than an xyplot. 我在这里也找不到问题,答案是针对qq图而不是xyplot。

The convention with QQ plots is to plot the line that goes through the first and fourth quartiles of the sample and the test distribution, not the line of best fit. QQ绘图的惯例是绘制穿过样本和测试分布的第一和第四四分位数的线, 而不是最佳拟合线。

set.seed(1)
Z <- rnorm(100)
qqnorm(Z)
qqline(Z,probs=c(0.25,0.75))

The reason for this is that, if your sample is not normally distributed, the deviations tend to be at the extremes. 这样做的原因是,如果您的样本不是正态分布的,则偏差往往会达到极限。

set.seed(1)
Z <- runif(100)   # NOTE: uniform distribution...
qqnorm(Z)
qqline(Z, probs=c(0.25,0.75))

If you want the line connecting the corners, as in your comment, use different probabilities. 如果您希望直线连接拐角,如注释中所述,请使用不同的概率。 The reason you need to use (0.01,0.99) rather than (0,1) is that the latter will produce infinities. 您需要使用(0.01,0.99)而不是(0,1)的原因是后者会产生无穷大。

set.seed(1)
Z <- runif(100)   # NOTE: uniform distribution...
qqnorm(Z)
qqline(Z, probs=c(0.01,0.99))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM