[R] How to construct a 'proper' Q-Q line in log-log space?
Marius Hofert
marius.hofert at math.ethz.ch
Sun Jun 30 01:08:47 CEST 2013
Dear expeRts,
I would like to create a Q-Q plot including a Q-Q line for Gamma
distributed data.
The specialty is that it should be in log-log scale. For Q-Q line in
log-log scale,
I discovered the argument 'untf' of abline. As you can see in 2), this
works fine.
But for 3) it does not provide the correct line.
How would one add a Q-Q line to a Q-Q plot in log-log scale?
Cheers,
Marius
th <- 0.5
n <- 250
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 log-x space
plot(qF(ppoints(n)), sort(x), log="x")
qqline(y=sort(x), distribution=qF, untf=TRUE) # fine
## 3) Q-Q plot in log-log space
plot(qF(ppoints(n)), sort(x), log="xy")
qqline(y=sort(x), distribution=qF, untf=TRUE) # => wrong!
qqline(y=sort(log(x)), distribution=function(p) log(qF(p)), col="red")
# almost, but not as 'green' below
## 4) Q-Q plot of log values directly
plot(log(qF(ppoints(n))), sort(log(x)))
qqline(y=sort(log(x)), distribution=function(p) log(qF(p)), untf=TRUE,
col="green") # fine
More information about the R-help
mailing list