snmatch | R Documentation |
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.
snmatch(x, y, p = c(0.025, 0.5, 0.975))
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. |
The skew-normal density is parameterized by a location parameter μ, a scale parameter ω and a shape parameter ρ that regulates skewness. The probability density function at any x on the real line is:
p(x) = (2/ω) φ((x-μ)/ω) ψ(ρ (x-μ)/ω),
where φ() and ψ() 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.
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. |
Oswaldo Gressani oswaldo_gressani@hotmail.fr.
Azzalini, A. (2018). The Skew-Normal and Related families. Cambridge University Press.
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.