r - Q-Q line in log-log space (log="xy"): abline's argument 'untf' does not work as expected -


i try understand why qqline not give me expect if (and if) log="xy":

th <- 0.5 n <- 1e3 set.seed(271) x <- rgamma(n, shape=th) qf <- 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) # 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) # untf=true, fine 

now ?abline addresses untf. according that, following should work (in opinion):

## 4) q-q plot in log10-log10 space plot(qf(ppoints(n)), sort(x), log="xy") qqline(y=sort(x), distribution=qf, untf=true) # ... 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 correct (but draws line, not curve resulting transforming q-q line in 'non-log-log' space) 

my questions are: 1) why untf=true not give right answer log="xy" although did log="x" , log="y"? 2) on more general basis, what's 'right' q-q line in log-log-space (anyways)?

please note have posted similar question r-help, have not received answer.

update

i did more experiments, reproducing (by foot) strange curve qqline() in log-log space produces. figure log10() instead of log() might reason incorrect line. blue line indeed seems correct 1 if 1 wants have line in log-log space. not clear me why points of standard q-q line displayed in log-log scale not give right curve, although points of q-q plot constructed way, too.

th <- 0.5 n <- 1e2 # note difference n=1e2 vs n=1e4! set.seed(271) x <- rgamma(n, shape=th) qf <- function(p) qgamma(p, shape=th)  ## q-q plot qq.x <- qf(ppoints(n)) qq.y <- sort(x) plot(qq.x, qq.y, log="xy", main=substitute("q-q plot 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) # ... wrong (*) qqline(y=qq.y, distribution=qf, col="red") # ... still wrong ## => doesn't pass first , third quartile, closer 'right' line (blue) large n qqline(y=sort(log10(x)), distribution=function(p) log10(qf(p)), col="blue") ## => seems correct (but draws line, not curve resulting transforming ##    q-q line in 'non-log-log' space)  ## foot (as seen, reproduces (*)) probs <- c(0.25, 0.75) q.x <- qf(probs) q.y <- quantile(x, probs=probs, names=false) slope <- diff(q.y)/diff(q.x) int <- q.y[1l] - slope * q.x[1l] f <- function(x) slope * x + int # line in *normal* space qq.y. <- f(qq.x) # points of q-q line evaluated in normal space lines(qq.x, qq.y., col="darkgreen") ## => reproduces qqline(.., untf=true), see (*) above, is, ##    standard q-q line added plot in log-log scale = wrong (although points ##    of q-q plot constructed way!)  ## legend legend("topleft", lty=rep(1,5), col=c("darkgreen", "black", "red", "blue", "gray50"),        legend=c("standard q-q line '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 , 3rd quartiles")) 


Comments