qqPlot: Quantile-Quantile Plots for various distributions
Source:R/1.3_Distr_DistrCollection_Functions.R
qqPlot.RdFunction qqPlot creates a QQ plot of the values in x including a line which passes through the first and third quartiles.
Usage
qqPlot(
x,
y,
confbounds = TRUE,
alpha,
main,
xlab,
ylab,
xlim,
ylim,
border = "red",
bounds.col = "black",
bounds.lty = 1,
start,
showPlot = TRUE,
axis.y.right = FALSE,
bw.theme = FALSE
)Arguments
- x
The sample for qqPlot.
- y
Character string specifying the distribution of
x. The functionqqPlotsupports the following character strings fory:`beta``cauchy``chi-squared``exponential``f``gamma``geometric``log-normal``lognormal``logistic``negative binomial``normal``Poisson``weibull`
By default
distributionis set to`normal`.- confbounds
Logical value indicating whether to display confidence bounds. By default,
confboundsis set toTRUE.- alpha
Numeric value specifying the significance level for the confidence bounds, set to `0.05` by default.
- main
A character string for the main title of the plot.
- xlab
A character string for the x-axis label.
- ylab
A character string for the y-axis label.
- xlim
A numeric vector of length 2 to specify the limits of the x-axis.
- ylim
A numeric vector of length 2 to specify the limits of the y-axis.
- border
A numerical value or single character string giving the color of the interpolation line. By default,
borderis set to`red`.- bounds.col
A numerical value or single character string giving the color of the confidence bounds lines. By default,
bounds.colis set to`black`.- bounds.lty
A numeric or character: line type for the confidence bounds lines. This can be specified with either an integer (0-6) or a name:
0: blank
1: solid
2: dashed
3: dotted
4: dotdash
5: longdash
6: twodash
Default is `1` (solid line).
- start
A named list giving the parameters to be fitted with initial values. Must be supplied for some distributions (see Details).
- showPlot
Logical value indicating whether to display the plot. By default,
showPlotis set toTRUE.- axis.y.right
Logical value indicating whether to display the y-axis on the right side. By default,
axis.y.rightis set toFALSE.- bw.theme
Logical value indicating whether to use a black-and-white theme from the
ggplot2package for the plot. By default,bw.themeis set toFALSE.
Value
The function qqPlot returns an invisible list containing:
- x
Sample quantiles.
- y
Theoretical quantiles.
- int
Intercept of the fitted line.
- slope
Slope of the fitted line.
- plot
The generated QQ plot.
Details
Distribution fitting is performed using the FitDistr function from this package.
For the computation of the confidence bounds, the variance of the quantiles is estimated using the delta method,
which involves the estimation of the observed Fisher Information matrix as well as the gradient of the CDF of the fitted distribution.
Where possible, those values are replaced by their normal approximation.
Examples
set.seed(123)
qqPlot(rnorm(20, mean=90, sd=5), "normal",alpha=0.30)
qqPlot(rcauchy(100), "cauchy")
qqPlot(rweibull(50, shape = 1, scale = 1), "weibull")
qqPlot(rlogis(50), "logistic")
qqPlot(rlnorm(50) , "log-normal")
qqPlot(rbeta(10, 0.7, 1.5),"beta")
qqPlot(rpois(20,3), "poisson")
qqPlot(rchisq(20, 10),"chi-squared")
qqPlot(rgeom(20, prob = 1/4), "geometric")
qqPlot(rnbinom(n = 20, size = 3, prob = 0.2), "negative binomial")
qqPlot(rf(20, df1 = 10, df2 = 20), "f")