how can I generate an exponential Q-Q plot in R? For a normal Q-Q plot I use
qqnorm(sample)
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.
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.
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)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With