get.cauchy.par: Fitting parameters of a Cauchy distribution from two or more...

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/rriskDistributions_functions.R

Description

get.cauchy.par returns the parameters of a Cauchy distribution where the pth percentiles match with the quantiles q.

Usage

1
2
get.cauchy.par(p = c(0.025, 0.5, 0.975), q, show.output = TRUE,
   plot = TRUE, tol = 0.001, fit.weights = rep(1, length(p)), scaleX = c(0.1, 0.9), ...)

Arguments

p

numeric, single value or vector of probabilities.

q

numeric, single value or vector of quantiles corresponding to p.

show.output

logical, if TRUE the optim result will be printed (default value is TRUE).

plot

logical, if TRUE the graphical diagnostics will be plotted (default value is TRUE).

tol

numeric, single positive value giving the absolute convergence tolerance for reaching zero (default value is 0.001).

fit.weights

numerical vector of the same length as a probabilities vector p containing positive values for weighting quantiles. By default all quantiles will be weighted by 1.

scaleX

numerical vector of the length 2 containing values (from the open interval (0, 1)) for scaling quantile-axis (relevant only if plot = TRUE). The smaller the left value, the further the graph is extrapolated within the lower percentile, the greater the right value, the further it goes within the upper percentile.

...

further arguments passed to the functions plot and points (relevant only if plot = TRUE).

Details

The number of probabilities, the number of quantiles and the number of weightings must be identical and should be at least two. Using the default p, the three corresponding quantiles are the 2.5th percentile, the median and the 97.5th percentile, respectively. get.cauchy.par uses the R function optim with the method L-BFGS-B.

If show.output = TRUE the output of the function optim will be shown. The item convergence equal to 0 means the successful completion of the optimization procedure, otherwise it indicates a convergence error. The item value displays the achieved minimal value of the functions that were minimized.

The estimated distribution parameters returned by the function optim are accepted if the achieved value of the minimized function (output component value of optim) is smaller than the argument tol.

The items of the probability vector p should lie between 0 and 1.

The items of the weighting vector fit.weights should be positive values.

The function which will be minimized is defined as a sum of squared differences between the given probabilities and the theoretical probabilities of the specified distribution evaluated at the given quantile points (least squares estimation).

Value

Returns fitted parameters of a Cauchy distribution or missing values (NA's) if the distribution cannot fit the specified quantiles.

Note

It should be noted that there might be deviations between the estimated and the theoretical distribution parameters in certain circumstances. This is because the estimation of the parameters is based on a numerical optimization method and depends strongly on the initial values. In addition, one must always keep in mind that a distribution for different combinations of parameters may look very similar. Therefore, the optimization method cannot always find the "right" distribution, but a "similar" one.

If the function terminates with the eror massage "convergence error occurred or specified tolerance not achieved", one may try to set the convergence tolerance to a higher value. It is yet to be noted, that good til very good fits of parameters could only be obtained for tolerance values that are smaller than 0.001.

Author(s)

Matthias Greiner matthias.greiner@bfr.bund.de (BfR),
Katharina Schueller schueller@stat-up.de (STAT-UP Statistical Consulting),
Natalia Belgorodski belgorodski@stat-up.de (STAT-UP Statistical Consulting)

See Also

See pcauchy for distribution implementation details.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
q <- stats::qcauchy(p = c(0.025, 0.5, 0.975), location = 0, scale = 1)
old.par <- graphics::par(mfrow = c(2, 3))
get.cauchy.par(q = q)
get.cauchy.par(q = q, scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(1, 10, 1), scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(1, 100, 1), scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(10, 1, 10), scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(100, 1, 100), scaleX = c(0.5, 0.5))
graphics::par(old.par)

q <- stats::qcauchy(p = c(0.025, 0.5, 0.975), location = 3, scale = 5)
old.par <- graphics::par(mfrow = c(2, 3))
get.cauchy.par(q = q, scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(1, 10, 1), scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(1, 100, 1), scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(10, 1, 10), scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(100, 1, 100), scaleX = c(0.5, 0.5))
graphics::par(old.par)

q <- stats::qcauchy(p = c(0.025, 0.5, 0.975), location = 0.1, scale = 0.1)
old.par <- graphics::par(mfrow = c(2, 3))
get.cauchy.par(q = q, scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(1, 10, 1), scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(1, 100, 1), scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(10, 1, 10), scaleX = c(0.5, 0.5))
get.cauchy.par(q = q, fit.weights = c(100, 1, 100), scaleX = c(0.5, 0.5))
graphics::par(old.par)

## example with only two quantiles
q <- stats::qcauchy(p = c(0.025, 0.975), location = 0.1, scale = 0.1)
old.par <- graphics::par(mfrow = c(2, 3))
get.cauchy.par(p = c(0.025, 0.975), q = q, scaleX = c(0.5, 0.5))
get.cauchy.par(p = c(0.025, 0.975), q = q, fit.weights = c(10, 1), scaleX = c(0.5, 0.5))
get.cauchy.par(p = c(0.025, 0.975), q = q, fit.weights = c(100, 1), scaleX = c(0.5, 0.5))
get.cauchy.par(p = c(0.025, 0.975), q = q, fit.weights = c(1, 10), scaleX = c(0.5, 0.5))
get.cauchy.par(p = c(0.025, 0.975), q = q, fit.weights = c(1, 100), scaleX = c(0.5, 0.5))
graphics::par(old.par)

rriskDistributions documentation built on May 2, 2019, 3:44 a.m.