How to plot Q-Q plot of Exp versus Weibull in R

80 Views Asked by At

I have a random sample $X$ of size $500$ from an $Exp(1000)$ distribution. I assume that $\lambda =0.2$ and I convert $X$ into $Y$ by the Box-Cox transfoamrtion $y(\lambda )=\frac{x^{\lambda}-1}{\lambda}$. I want to plot the Q-Q plot of the sample $Y$ versus Weibull distribution $Weib(5,1000)$ in R as follows:

enter image description here

The figure comes from a paper.

What I've tried:

    set.seed(123)
    x <- rexp(500, 1000)
    lambda <- 0.2
    y <- (x ^ lambda - 1) / lambda
    z <- rweibull(500,5,1000)

There is a problem when I put ${\rm qqplot(z,y)}$. I would be grateful if someone could help about that.

1

There are 1 best solutions below

1
On BEST ANSWER

Here is some r code that qqplots

  1. Empirical quantiles of the Cox-Box transform of a sample of i.i.d. exponential distribution with scale = $1000$ vs the theoretical quantiles of the Weibull distribution with parameter shape =5, scale = 1000
  2. The Cox-Box transformed quantiles of the exponential distribution with $\lambda=1000$ vs the theoretical quantiles of the Weibull distribution with parameter shape =5, scale = 1000
### Cox-Box transform
cox_box <- function(y,lambda =0.2){
      (y^lambda -1)/lambda
    }
    
y <- rexp(1000,1000) # sample
ylambda <- cox_box(y) # transformed sample
    
p <- seq(0,.999, by = 0.001)
w <- qweibull(p,5,1000) # theoretical quantiles Weibull
yq <- qexp(p,1000)      # theoretical quantiles Exponential
yq_lambda <- cox_box(yq) # transformed quantiles
    
qqplot(ylambda,w)
lines(yq_lambda,w, col = 'blue')
    
qqplot(yq_lambda,w)
lines(yq_lambda,w, col = 'blue')