snmatch {blapsr}R Documentation

Fit a skew-normal distribution to a target density.

Description

The routine fits a skew-normal univariate distribution to a target density. Parameters of the resulting skew-normal fit are estimated by the method of moments.

Usage

snmatch(x, y, p = c(0.025, 0.5, 0.975))

Arguments

x

A numeric vector on the domain of the target density.

y

The y-coordinates of the target density on grid x.

p

Vector of probabilities at which to compute quantiles of the skew-normal fit.

Details

The skew-normal density is parameterized by a location parameter \mu, a scale parameter \omega and a shape parameter \rho that regulates skewness. The probability density function at any x on the real line is:

p(x) = (2/\omega) \phi((x-\mu)/\omega) \psi(\rho (x-\mu)/\omega),

where \phi() and \psi() denote the standard Gaussian density and cumulative distribution function respectively (see Azzalini 2018). The first moment and second and third central moments of the target density are computed based on the x, y coordinates using the trapezoidal rule and matched against the theoretical moments of a skew-normal distribution. The solution to this system of equations is the method of moment estimate of the location, scale and shape parameters of a skew-normal density.

Value

A list with the following components:

location

Estimated location parameter.

scale

Estimated scale parameter.

shape

Estimated shape parameter.

snfit

Fitted values of the skew-normal density computed on an equally spaced grid between min(x) and max(x).

quant

Vector of quantiles of the skew-normal fit computed on the input vector of probabilities p.

xgrid

Equidistant grid on which the skew-normal fitted density is computed.

Author(s)

Oswaldo Gressani oswaldo_gressani@hotmail.fr.

References

Azzalini, A. (2018). The Skew-Normal and Related families. Cambridge University Press.

Examples

# Pdf of skew-normal density
sn.target <- function(x, location, scale, shape){
               val <- 2 * stats::dnorm(x, mean = location, sd = scale) *
               pnorm(shape * (x - location) / scale)
               return(val)
              }

# Extract x and y coordinates from target
x.grid <- seq(-2, 6, length = 200)
y.grid <- sapply(x.grid, sn.target, location = 0, scale = 2, shape = 3)

# Computation of the fit and graphical illustration
fit <- snmatch(x.grid, y.grid)
domx <- seq(-2, 6, length = 1000)
plot(domx, sapply(domx, sn.target, location = 0, scale = 2, shape = 3),
     type = "l", ylab = "f(x)", xlab = "x", lwd= 2)
lines(fit$xgrid, fit$snfit, type="l", col = "red", lwd = 2, lty = 2)
legend("topright", lty = c(1,2), col = c("black", "red"), lwd = c(2, 2),
       c("Target","SN fit"), bty="n")

# Extract estimated parameters
fit$location # Estimated location parameter
fit$scale    # Estimated scale parameter
fit$shape    # Estimated shape parameter


[Package blapsr version 0.6.1 Index]