fitdist(data, distr, method="mle", start, chisqbreaks, meancount)
## S3 method for class 'fitdist':
print(x,...)
## S3 method for class 'fitdist':
plot(x,breaks="default",...)
## S3 method for class 'fitdist':
summary(object,...)
"name"
naming a distribution for which the corresponding
density function dname
, the corresponding distribution function pname
and the corresponding
quantile function qname
"mle"
for 'maximum likelihood' and "mom"
for 'matching moments'.method="mom"
,
and may be omitted for some distributions for which reasonable
starting values are c
"default"
the histogram is plotted with the function hist
with its default breaks definition. Else breaks
is passed to the function hist
.
This argument is not taken into account with discrefitdist
returns an object of class 'fitdist', a list with 16 components,"mle"
for 'maximum likelihood' and "mom"
for 'matching moments'NULL
if method="mom"
NULL
if method="mom"
NULL
if method="mom"
NULL
if not computedNULL
if not computedNULL
if not computedNULL
if not computedNULL
if not computedNULL
if not computedNULL
if not computedmethod="mle"
,
maximum likelihood estimations of the distribution parameters are computed using
the function mledist
.
Direct optimization of the log-likelihood is performed using optim
, with its
default method "Nelder-Mead"
for distributions characterized by more than one parameter and
the method "BFGS"
for distributions characterized by only one parameter.
For the following named distributions, reasonable starting values will
be computed if start
is omitted : "norm"
, "lnorm"
,
"exp"
and "pois"
, "cauchy"
, "gamma"
, "logis"
,
"nbinom"
(parametrized by mu and size), "geom"
, "beta"
and "weibull"
. Note that these starting
values may not be good enough if the fit is poor. The function is not able to fit a uniform distribution.
With the parameter estimates, the function returns the log-likelihood and the standard errors of
the estimates calculated from the
Hessian at the solution found by optim
.
When method="mom"
,
the estimated values of the distribution parameters are provided only for the following
distributions : "norm"
, "lnorm"
, "pois"
, "exp"
, "gamma"
,
"nbinom"
, "geom"
, "beta"
, "unif"
and "logis"
.
For distributions characterized by one parameter ("geom"
, "pois"
and "exp"
), this parameter is simply
estimated by matching theoretical and observed means, and for distributions characterized by
two parameters, these parameters are estimated by matching theoretical and observed means
and variances (Vose, 2000).
Goodness-of-fit statistics are computed. The Chi-squared statistic is computed using cells defined by the argument
chisqbreaks
or cells automatically defined from the data in order
to reach roughly the same number of observations per cell, roughly equal to the argument
meancount
, or sligthly more if there are some ties. If chisqbreaks
and meancount
are both
omitted, meancount
is fixed in order to obtain roughly $(4n)^{2/5}$ cells, with $n$ the length of the dataset (Vose, 2000).
The Chi-squared statistic is not computed if the program fails
to define enough cells due to a too small dataset. When the Chi-squared statistic is computed, and if the degree
of freedom (nb of cells - nb of parameters - 1) of the corresponding distribution is strictly positive, the p-value
of the Chi-squared test is returned.
For the distributions assumed continuous (all but "binom"
,
"nbinom"
, "geom"
, "hyper"
and "pois"
), Kolmogorov-Smirnov and Anderson-Darling
statistics are also computed, as defined by Cullen and Frey (1999).
An approximate Kolmogorov-Smirnov test is
performed by assuming the distribution parameters known. The critical value defined by Stephens (1986)
for a completely specified distribution is used to reject or not the
distribution at the significance level 0.05. Because of this approximation, the result of the test
(decision of rejection of the distribution or not) is returned only for datasets with more than 30 observations.
Note that this approximate test may be too conservative.
For datasets with more than 5 observations and for distributions for
which the test is described by Stephens (1986) ("norm"
, "lnorm"
,
"exp"
, "cauchy"
, "gamma"
, "logis"
and "weibull"
),
the Anderson-darling test is performed as described by Stephens (1986). This test takes into account the
fact that the parameters are not known but estimated from the data. The result is the decision to reject
or not the distribution at the significance level 0.05.
The plot of an object of class "fitdist" returned by fitdist
uses the function plotdist
.plotdist
, optim
, mledist
, momdist
and fitdistcens
.x1<-c(6.4,13.3,4.1,1.3,14.1,10.6,9.9,9.6,15.3,22.1,13.4,
13.2,8.4,6.3,8.9,5.2,10.9,14.4)
f1<-fitdist(x1,"norm")
print(f1)
plot(f1)
summary(f1)
f1$chisqtable
f1b<-fitdist(x1,"norm",method="mom",meancount=6)
summary(f1b)
f1b$chisqtable
f1c<-fitdist(x1,"lnorm",method="mom",meancount=6)
summary(f1c)
f1c$chisqtable
dgumbel<-function(x,a,b) 1/b*exp((a-x)/b)*exp(-exp((a-x)/b))
pgumbel<-function(q,a,b) exp(-exp((a-q)/b))
qgumbel<-function(p,a,b) a-b*log(-log(p))
f1c<-fitdist(x1,"gumbel",start=list(a=10,b=5))
print(f1c)
plot(f1c)
x2<-c(rep(4,1),rep(2,3),rep(1,7),rep(0,12))
f2<-fitdist(x2,"pois",chisqbreaks=c(0,1))
plot(f2)
summary(f2)
f2$chisqtable
xw<-rweibull(n=100,shape=2,scale=1)
fa<-fitdist(xw,"weibull")
summary(fa)
fa$chisqtable
fb<-fitdist(xw,"gamma")
summary(fb)
fc<-fitdist(xw,"exp")
summary(fc)
Run the code above in your browser using DataLab