Learn R Programming

fitdistrplus (version 1.0-2)

graphcomp: Graphical comparison of multiple fitted distributions (for non-censored continuous data)

Description

cdfcomp plots the empirical cumulative distribution against fitted distribution functions, denscomp plots the histogram against fitted density functions, qqcomp plots theoretical quantiles against empirical ones, ppcomp plots theoretical probabilities against empirical ones.

Usage

cdfcomp(ft, xlim, ylim, xlogscale = FALSE, ylogscale = FALSE, main, xlab, ylab, 
    datapch, datacol, fitlty, fitcol, addlegend = TRUE, legendtext, 
    xlegend = "bottomright", ylegend = NULL, horizontals = TRUE, 
    verticals = FALSE, use.ppoints = TRUE, a.ppoints = 0.5, 
    lines01 = FALSE, discrete, ...)
    
denscomp(ft, xlim, ylim, probability = TRUE, main, xlab, ylab, datapch, 
    datacol, fitlty, fitcol, addlegend = TRUE, legendtext, xlegend = "topright", 
    ylegend = NULL, demp = FALSE, dempcol = "grey", ...)

qqcomp(ft, xlim, ylim, xlogscale = FALSE, ylogscale = FALSE, main, xlab, ylab, 
    fitpch, fitcol, addlegend = TRUE, legendtext, xlegend = "bottomright", 
    ylegend = NULL, use.ppoints = TRUE, a.ppoints = 0.5, line01 = TRUE, 
    line01col = "black", line01lty = 1, ynoise = TRUE, ...)   
    
ppcomp(ft, xlim, ylim, xlogscale = FALSE, ylogscale = FALSE, main, xlab, ylab, 
    fitpch, fitcol, addlegend = TRUE, legendtext, xlegend = "bottomright", 
    ylegend = NULL, use.ppoints = TRUE, a.ppoints = 0.5, line01 = TRUE, 
    line01col = "black", line01lty = 1, ynoise = TRUE, ...)

Arguments

ft
One "fitdist" object or a list of objects of class "fitdist".
xlim
The $x$-limits of the plot.
ylim
The $y$-limits of the plot.
xlogscale
If TRUE, uses a logarithmic scale for the $x$-axis.
ylogscale
If TRUE, uses a logarithmic scale for the $y$-axis.
main
A main title for the plot, see also title.
xlab
A label for the $x$-axis, defaults to a description of x.
ylab
A label for the $y$-axis, defaults to a description of y.
datapch
An integer specifying a symbol to be used in plotting data points, see also points.
datacol
A specification of the color to be used in plotting data points.
fitcol
A (vector of) color(s) to plot fitted distributions. If there are fewer colors than fits they are recycled in the standard fashion.
fitlty
A (vector of) line type(s) to plot fitted distributions/densities. If there are fewer colors than fits they are recycled in the standard fashion. See also par.
fitpch
A (vector of) line type(s) to plot fitted quantiles/probabilities. If there are fewer colors than fits they are recycled in the standard fashion.
addlegend
If TRUE, a legend is added to the plot.
legendtext
A character or expression vector of length $\geq 1$ to appear in the legend, see also legend.
xlegend, ylegend
The $x$ and $y$ co-ordinates to be used to position the legend. They can be specified by keyword or in any way which is accepted by 'xy.coords': see legend for details.
horizontals
If TRUE, draws horizontal lines for the step empirical cdf function. See also plot.stepfun.
verticals
If TRUE, draws also vertical lines for the empirical cdf function. Only taken into account if horizontals=TRUE.
use.ppoints
If TRUE, probability points of the empirical distribution are defined as (1:n - a.ppoints)/(n - 2a.ppoints + 1) using function ppoints. If FALSE, probability
a.ppoints
If use.ppoints=TRUE, this is passed to function ppoints.
lines01
A logical to plot two horizontal lines at h=0 and h=1 for cdfcomp.
line01
A logical to plot an horizontal line $y=x$ for qqcomp and ppcomp.
line01col, line01lty
Color and line type for line01.
demp
A logical to add the empirical density on the plot using the density function.
dempcol
A color for the empirical density in case it is added on the plot.
ynoise
A logical to add a small Gaussian noise when plotting empirical quantiles/probabilities for qqcomp and ppcomp.
probability
A logical to use the probability scale for denscomp, see also hist.
...
Further graphical arguments passed to graphical functions used in cdfcomp, denscomp, ppcomp and qqcomp.
discrete
If TRUE, the distribution is considered as discrete. If missing, discrete is set to TRUE when the distribution name of the first fit belongs to "binom", "nbinom", "geom",

Details

cdfcomp provides a plot of the empirical distribution and each fitted distribution in cdf, by default using the Hazen's rule for the empirical distribution, with probability points defined as (1:n - 0.5)/n. If discrete is TRUE probability points are always defined as (1:n)/n. denscomp provides a density plot of each fitted distribution with the histogram of the data (data are assumed continuous). ppcomp provides a plot of the probabilities of each fitted distribution (x-axis) against the empirical probabilities (y-axis) by default defined as (1:n - 0.5)/n (data are assumed continuous). qqcomp provides a plot of the quantiles of each theoretical distribution (x-axis) against the empirical quantiles of the data (y-axis), by default defining probability points as (1:n - 0.5)/n for theoretical quantile calculation (data are assumed continuous). By default a legend is added to these plots. Many graphical arguments are optional, dedicated to personalize the plots, and fixed to default values if omitted.

See Also

See plot, legend, ppoints, plot.stepfun for classic plotting functions and plotdist.

Examples

Run this code
# (1) Plot various distributions fitted to serving size data
#
data(groundbeef)
serving <- groundbeef$serving
fitW <- fitdist(serving,"weibull")
fitln <- fitdist(serving,"lnorm")
fitg <- fitdist(serving,"gamma")
cdfcomp(list(fitW,fitln,fitg),horizontals = FALSE)
cdfcomp(list(fitW,fitln,fitg),horizontals = TRUE)
cdfcomp(list(fitW,fitln,fitg),horizontals = TRUE, verticals=TRUE,datacol="purple")
cdfcomp(list(fitW,fitln,fitg),legendtext=c("Weibull","lognormal","gamma"),
    main="ground beef fits",xlab="serving sizes (g)",
    ylab="F",xlim = c(0,250),xlegend = "center",lines01 = TRUE)
denscomp(list(fitW,fitln,fitg),legendtext=c("Weibull","lognormal","gamma"),
    main="ground beef fits",xlab="serving sizes (g)",xlim = c(0,250),
    xlegend = "topright")
ppcomp(list(fitW,fitln,fitg),legendtext=c("Weibull","lognormal","gamma"),
    main="ground beef fits",xlegend = "bottomright",line01 = TRUE)
qqcomp(list(fitW,fitln,fitg),legendtext=c("Weibull","lognormal","gamma"),
    main="ground beef fits",xlegend = "bottomright",line01 = TRUE,
    xlim = c(0,300), ylim = c(0,300), fitpch=16)

# (2) Plot lognormal distributions fitted by 
# maximum goodness-of-fit estimation
# using various distances (data plotted in log scale)
#
data(endosulfan)
ATV <-subset(endosulfan,group == "NonArthroInvert")$ATV
flnMGEKS <- fitdist(ATV,"lnorm",method="mge",gof="KS")
flnMGEAD <- fitdist(ATV,"lnorm",method="mge",gof="AD")
flnMGEADL <- fitdist(ATV,"lnorm",method="mge",gof="ADL")
flnMGEAD2L <- fitdist(ATV,"lnorm",method="mge",gof="AD2L")
cdfcomp(list(flnMGEKS,flnMGEAD,flnMGEADL,flnMGEAD2L),
    xlogscale=TRUE,main="fits of a lognormal dist. using various GOF dist.",
    legendtext=c("MGE KS","MGE AD","MGE ADL","MGE AD2L"),
    verticals=TRUE,xlim=c(10,100000))
qqcomp(list(flnMGEKS,flnMGEAD,flnMGEADL,flnMGEAD2L),
    main="fits of a lognormal dist. using various GOF dist.",
    legendtext=c("MGE KS","MGE AD","MGE ADL","MGE AD2L"),
    xlogscale = TRUE, ylogscale = TRUE)
ppcomp(list(flnMGEKS,flnMGEAD,flnMGEADL,flnMGEAD2L),
    main="fits of a lognormal dist. using various GOF dist.",
    legendtext=c("MGE KS","MGE AD","MGE ADL","MGE AD2L"))

# (3) Plot normal and logistic distributions fitted by 
# maximum likelihood estimation
# using various plotting positions in cdf plots
#
data(endosulfan)
log10ATV <-log10(subset(endosulfan,group == "NonArthroInvert")$ATV)
fln <- fitdist(log10ATV,"norm")
fll <- fitdist(log10ATV,"logis")
# default plot using Hazen plotting position: (1:n - 0.5)/n
cdfcomp(list(fln,fll),legendtext=c("normal","logistic"),xlab="log10ATV")
# plot using mean plotting position (named also Gumbel plotting position)
# (1:n)/(n + 1)
cdfcomp(list(fln,fll),legendtext=c("normal","logistic"),xlab="log10ATV",
    use.ppoints = TRUE, a.ppoints = 0)
# plot using basic plotting position: (1:n)/n
cdfcomp(list(fln,fll),legendtext=c("normal","logistic"),xlab="log10ATV",
    use.ppoints = FALSE)

# (4) Comparison of fits of two distributions fitted to discrete data
#
data(toxocara)
number <- toxocara$number
fitp <- fitdist(number,"pois")
fitnb <- fitdist(number,"nbinom")
cdfcomp(list(fitp,fitnb),legendtext=c("Poisson","negative binomial"))

Run the code above in your browser using DataLab