简体   繁体   中英

R: Lattice Q-Q Plot with regression Line

I can create a lattice qq-plot with:

qqnorm(surfchem.cast$Con)

but I have not learned how to add a panel.abline or prepane.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.

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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