Fits a normal Laplace distribution to data.
Displays the histogram, log-histogram (both with fitted densities),
Q-Q plot and P-P plot for the fit which has the maximum likelihood.
Usage
nlFit(x, freq = NULL, breaks = "FD", paramStart = NULL,
startMethod = "Nelder-Mead",
startValues = c("MoM", "US"),
method = c("Nelder-Mead", "BFGS", "L-BFGS-B",
"nlm", "nlminb"),
hessian = FALSE,
plots = FALSE, printOut = FALSE,
controlBFGS = list(maxit = 200),
controlLBFGSB = list(maxit = 200),
controlNLMINB = list(),
controlNM = list(maxit = 1000),
maxitNLM = 1500, ...)
## S3 method for class 'nlFit'
print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'nlFit'
plot(x, which = 1:4,
plotTitles = paste(c("Histogram of ","Log-Histogram of ",
"Q-Q Plot of ","P-P Plot of "), x$obsName,
sep = ""),
ask = prod(par("mfcol")) < length(which) & dev.interactive(), ...)
## S3 method for class 'nlFit'
coef(object, ...)
## S3 method for class 'nlFit'
vcov(object, ...)
Arguments
x
Data vector for nlFit.
freq
A vector of weights with length equal to length(x).
breaks
Breaks for plotted histogram, defaults to those generated by
hist(x, right = FALSE, plot = FALSE).
paramStart
A user specified starting parameter vector taking the form
c(mu, sigma, alpha, beta).
startMethod
Method used by nlFitStart in calls to
optim.
startValues
Code giving the method of determining starting values
for finding the maximum likelihood estimate of the parameters.
method
Different optimisation methods to consider.
See Details.
hessian
Logical. If TRUE the value of the Hessian
is returned.
plots
Logical. If FALSE the printing of the histogram,
log-histogram, Q-Q plot and P-P plot are suppressed.
printOut
Logical. If FALSE the printing of the results of
fitting will be suppressed.
controlBFGS
A list of control parameters for optim when
using the "BFGS" method of optimisation.
controlLBFGSB
A list of control parameters for optim when
using the "L-BFGS-B" method of optimisation.
controlNLMINB
A list of control parameters for optim when
using the "nlminb" method of optimisation.
controlNM
A list of control parameters for optim when
using the "Nelder-Mead" method of optimisation.
maxitNLM
A positive integer specifying the maximum number of
iterations that are to be undertaken when using the "nlm" method
of optimisation.
object
Object of class "nlFit" for print.nlFit,
plot.nlFit, coef.nlFit and vcov.nlFit.
digits
Desired number of digits to be shown when the object
is printed.
which
If a subset of the plots if required, specify a subset of
the numbers 1:4.
plotTitles
Titles to appear as the main title above the plots.
ask
Logical. If TRUE, the user is asked before
each plot, see par(ask = .).
...
Passes arguments to par, hist, logHist,
qqnl and ppnl. For the print, coef and
vcov methods this parameter has no effect.
Details
startMethod must be "Nelder-Mead".
startValues can only be "MoM" when using the Method of
Moments for estimation, or "US" for user-supplied parameters. For
details regarding the use of paramStart, startMethod and
startValues, see nlFitStart.
Three optimisation methods are available for use:
"BFGS"Uses the quasi-Newton method "BFGS" as
documented in optim.
"L-BFGS-B"Uses the constrained method "L-BFGS-B" as
documented in optim.
"Nelder-Mead"Uses an implementation of the Nelder and
Mead method as documented in optim.
"nlm"Uses the nlm function in R.
"nlminb"Uses the nlminb function in R,
with constrained parameters.
For details on how to pass control information for optimisation using
optim and nlm, see optim and
nlm.
When method = "nlm" or method = "nlm" is used, warnings
may be produced. However, these do not appear to be problematic.
Value
A list with components:
param
A vector giving the maximum likelihood estimate of
parameters, as
c(mu, sigma, alpha, beta).
maxLik
The value of maximised log-likelihood.
hessian
If hessian was set to TRUE, the value of
the Hessian. Not present otherwise.
method
Optimisation method used.
conv
Convergence code. See the relevant documentation (either
optim or nlm) for details on convergence.
iter
Number of iterations made by the optimisation routine.
obs
The data used to fit the normal Laplace distribution.
obsName
A character vector with the actual x argument name.
paramStart
Starting value of parameters returned by call to
nlFitStart.
svName
Descriptive name for the method of finding start values.
optim, nlm, par,
hist, logHist, qqnl,
ppnl, dnl and
nlFitStart.
Examples
param <- c(0, 2, 1, 1)
dataVector <- rnl(1000, param = param)
## Let's see how well nlFit works
nlFit(dataVector)
nlFit(dataVector, plots = TRUE)
fit <- nlFit(dataVector)
par(mfrow = c(1, 2))
plot(fit, which = c(1, 3)) # See only histogram and Q-Q plot
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(NormalLaplace)
Loading required package: DistributionUtils
Loading required package: RUnit
Loading required package: GeneralizedHyperbolic
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/NormalLaplace/nlFit.Rd_%03d_medium.png", width=480, height=480)
> ### Name: nlFit
> ### Title: Fit the Normal Laplace Distribution to Data
> ### Aliases: nlFit print.nlFit plot.nlFit coef.nlFit vcov.nlFit
> ### Keywords: distribution
>
> ### ** Examples
>
> param <- c(0, 2, 1, 1)
> dataVector <- rnl(1000, param = param)
>
> ## Let's see how well nlFit works
> nlFit(dataVector)
Data: dataVector
Parameter estimates:
mu sigma alpha beta
0.06784 4.12759 4.34682 4.06827
Likelihood: 2839.657
Method: Nelder-Mead
Convergence code: 0
Iterations: 203
> nlFit(dataVector, plots = TRUE)
Data: dataVector
Parameter estimates:
mu sigma alpha beta
0.06784 4.12759 4.34682 4.06827
Likelihood: 2839.657
Method: Nelder-Mead
Convergence code: 0
Iterations: 203
> fit <- nlFit(dataVector)
> par(mfrow = c(1, 2))
> plot(fit, which = c(1, 3)) # See only histogram and Q-Q plot
>
>
>
>
>
> dev.off()
null device
1
>