Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate an exponential Q-Q plot in R?

Tags:

r

statistics

how can I generate an exponential Q-Q plot in R? For a normal Q-Q plot I use

qqnorm(sample)
like image 714
stochazesthai Avatar asked Apr 21 '14 11:04

stochazesthai


People also ask

How do you create a Q-Q plot in R?

In R, there are two functions to create Q-Q plots: qqnorm and qqplot . qqnorm creates a Normal Q-Q plot. You give it a vector of data and R plots the data in sorted order versus quantiles from a standard Normal distribution. For example, consider the trees data set that comes with R.

What R package is Q-Q plot in?

The qqPlot function is a modified version of the R functions qqnorm and qqplot . The EnvStats function qqPlot allows the user to specify a number of different distributions in addition to the normal distribution, and to optionally estimate the distribution parameters of the fitted distribution.


2 Answers

EDIT (To reflect @Dason's input).

Like this:

set.seed(1)          # for reproducibility 
Z <- rexp(1000)      # random sample from exponential distribution
p <- ppoints(100)    # 100 equally spaced points on (0,1), excluding endpoints
q <- quantile(Z,p=p) # percentiles of the sample distribution
plot(qexp(p) ,q, main="Exponential Q-Q Plot",
     xlab="Theoretical Quantiles",ylab="Sample Quantiles")
qqline(q, distribution=qexp,col="blue", lty=2)
like image 194
jlhoward Avatar answered Oct 31 '22 16:10

jlhoward


Here is a ggplot2 solution.

Z <- rexp(1000, rate = 2)
library(MASS)
params <- as.list(fitdistr(Z, "exponential")$estimate)

library(ggplot2)
qplot(sample = Z, geom = 'blank') +
  stat_qq(distribution = qexp, dparams = params)
like image 33
Ramnath Avatar answered Oct 31 '22 18:10

Ramnath