Note that there are some explanatory texts on larger screens.

plurals
  1. POQ-Q line in log-log space (log="xy"): abline's argument 'untf' does not work as expected
    text
    copied!<p>I try to understand why <code>qqline</code> does not give me what I expect if (and only if) <code>log="xy"</code>:</p> <pre><code>th &lt;- 0.5 n &lt;- 1e3 set.seed(271) x &lt;- rgamma(n, shape=th) qF &lt;- function(p) qgamma(p, shape=th) ## 1) Q-Q plot in normal space plot(qF(ppoints(n)), sort(x)) qqline(y=sort(x), distribution=qF) # fine ## 2) Q-Q plot in log10-x space plot(qF(ppoints(n)), sort(x), log="x") qqline(y=sort(x), distribution=qF, untf=TRUE) # with untf=TRUE, fine ## 3) Q-Q plot in log10-y space plot(qF(ppoints(n)), sort(x), log="y") qqline(y=sort(x), distribution=qF, untf=TRUE) # with untf=TRUE, fine </code></pre> <p>Now the <code>?abline</code> addresses <code>untf</code>. According to that, the following should also work (in my opinion):</p> <pre><code>## 4) Q-Q plot in log10-log10 space plot(qF(ppoints(n)), sort(x), log="xy") qqline(y=sort(x), distribution=qF, untf=TRUE) # ... but this is wrong qqline(y=sort(x), distribution=qF, col="red") # ... (still) wrong qqline(y=sort(log10(x)), distribution=function(p) log10(qF(p)), col="blue") # seems to be correct (but draws a line, not the curve resulting from transforming the Q-Q line in 'non-log-log' space) </code></pre> <p>My questions are: 1) Why does <code>untf=TRUE</code> not give the right answer for <code>log="xy"</code> although it did for <code>log="x"</code> and <code>log="y"</code>? 2) On a more general basis, what's the 'right' Q-Q line in log-log-space (anyways)?</p> <p>Please note that I have posted a similar question to <a href="https://www.stat.math.ethz.ch/pipermail/r-help/2013-June/356127.html" rel="nofollow">R-help</a>, but have not received an answer.</p> <p><strong>UPDATE</strong></p> <p>I did more experiments, reproducing (by foot) the strange curve that <code>qqline()</code> in log-log space produces. I also figure that <code>log10()</code> instead of <code>log()</code> might be the reason for an incorrect line. So the blue line indeed seems to be the correct one <em>if</em> one wants to have a <em>line</em> in log-log space. What is not clear to me is why the points of the standard Q-Q line displayed in log-log scale do not give the right curve, although the points of the Q-Q plot are constructed this way, too. </p> <pre><code>th &lt;- 0.5 n &lt;- 1e2 # note the difference for n=1e2 vs n=1e4! set.seed(271) x &lt;- rgamma(n, shape=th) qF &lt;- function(p) qgamma(p, shape=th) ## Q-Q plot qq.x &lt;- qF(ppoints(n)) qq.y &lt;- sort(x) plot(qq.x, qq.y, log="xy", main=substitute("Q-Q plot with sample size n="*n., list(n.=n)), xlab="Theoretical quantiles", ylab="Sample quantiles") abline(v=quantile(qq.x, probs=0.25), col="gray50") # vertical line through 25%-quantile abline(v=quantile(qq.x, probs=0.75), col="gray50") # vertical line through 75%-quantile qqline(y=qq.y, distribution=qF, untf=TRUE) # ... this is wrong (*) qqline(y=qq.y, distribution=qF, col="red") # ... still wrong ## =&gt; doesn't pass first and third quartile, but closer to 'right' line (blue) for large n qqline(y=sort(log10(x)), distribution=function(p) log10(qF(p)), col="blue") ## =&gt; seems to be correct (but draws a line, not the curve resulting from transforming ## the Q-Q line in 'non-log-log' space) ## by foot (as will be seen, this reproduces (*)) probs &lt;- c(0.25, 0.75) q.x &lt;- qF(probs) q.y &lt;- quantile(x, probs=probs, names=FALSE) slope &lt;- diff(q.y)/diff(q.x) int &lt;- q.y[1L] - slope * q.x[1L] f &lt;- function(x) slope * x + int # line in *normal* space qq.y. &lt;- f(qq.x) # points of the Q-Q line evaluated in normal space lines(qq.x, qq.y., col="darkgreen") ## =&gt; reproduces qqline(.., untf=TRUE), see (*) above, that is, ## standard Q-Q line added to a plot in log-log scale = wrong (although points ## of the Q-Q plot are constructed this way!) ## legend legend("topleft", lty=rep(1,5), col=c("darkgreen", "black", "red", "blue", "gray50"), legend=c("Standard Q-Q line with 'untf=TRUE'", "Standard Q-Q line plotted in log-log scale", "Standard Q-Q line", "Q-Q line of log10(x) vs log10-quantiles", "1st and 3rd quartiles")) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload