1. What “maximum‑likelihood extended to skew and kurtosis” really means
| Classical MLE (the “vanilla” case) | What you are asking for (the extension) |
|---|
| Assumption – the data are generated from a symmetric distribution (most often the multivariate normal). The likelihood is built only from the first two moments (mean µ and covariance Σ). | Assumption – the data may be asymmetric (non‑zero skewness) and/or heavy‑ or light‑tailed (non‑Gaussian kurtosis). The likelihood must therefore contain additional shape parameters that control skewness (γ) and kurtosis (κ). |
| Result – the MLE of µ and Σ are the sample mean and (scaled) sample covariance. | Result – the MLE of (µ, Σ, γ, κ) are obtained by maximising a more complicated likelihood that includes a density that can flexibly change its third‑ and fourth‑order moments. |
In practice the extension is achieved by choosing a parametric family whose pdf already contains skewness and/or kurtosis parameters and then performing ordinary maximum‑likelihood estimation (MLE) on that family.
The most common families are:
| Family | Skewness? | Kurtosis? | Typical extra parameters | R packages (most used) |
|---|
| Skew‑Normal (SN) | ✔︎ | ✖︎ (still Gaussian tails) | α (shape vector) | sn |
| Skew‑t (ST) | ✔︎ | ✔︎ (heavy tails) | α (shape), ν (df) | sn, skewt |
| Generalized Hyperbolic (GH) | ✔︎ | ✔︎ (very flexible tails) | λ, α, β, δ, μ | ghyp |
| Pearson system / Johnson SU | ✔︎ | ✔︎ (via shape) | 4 shape parameters | PearsonDS, SuppDists |
| Edgeworth / Gram‑Charlier expansions | ✔︎ | ✔︎ (via cumulants) | κ₃, κ₄ (cumulants) | custom code (no ready‑made package) |
| Multivariate Skew‑Normal / Skew‑t | ✔︎ | ✔︎ (t‑version) | α (p‑vector), ν (df) | sn, mixsmsn |
| Generalized Lambda Distribution (GLD) | ✔︎ | ✔︎ (via shape) | λ₁…λ₄ | GLDEX |
All of these are maximum‑likelihood‑compatible: you write the log‑likelihood
[
\ell(\theta)=\sum_{i=1}^{n}\log f(x_i\mid\theta)
]
where (\theta) now contains the usual location‑scale parameters plus the skewness/kurtosis parameters, and you maximise (\ell(\theta)) numerically (Newton‑Raphson, EM, BFGS, etc.).
2. A concrete example in R – multivariate skew‑t PCA (ML‑based)
Below is a self‑contained script that
- Fits a multivariate skew‑t distribution to a data matrix (MLE of µ, Σ, α, ν).
- Extracts the “principal components” from the estimated covariance matrix (the same way PCA does).
- Provides the log‑likelihood, skewness, and kurtosis diagnostics.
- Keeps the same 2‑D/3‑D visualisation you already have.
# --------------------------------------------------------------
# pca_skewt_ml()
#
# Parameters
# ----------
# rawdata : data.frame or matrix (variables in columns)
# dim : "2D" or "3D"
# normalize_data : TRUE – work on the correlation matrix
# FALSE – work on the raw covariance matrix
# ncomp : number of components to retain (default = all)
#
# Returns
# -------
# A list with
# $x : component scores (regression scores)
# $rotation : loadings (eigenvectors of Σ̂)
# $fit : log‑likelihood, skewness vector, kurtosis (df)
# --------------------------------------------------------------
pca_skewt_ml <- function(rawdata,
dim = "2D",
normalize_data = TRUE,
ncomp = NULL) {
## ------------------------------------------------------------
## 0. Packages -------------------------------------------------
## ------------------------------------------------------------
if (!requireNamespace("sn", quietly = TRUE))
stop("Package 'sn' required. Install with install.packages('sn').")
if (!requireNamespace("rgl", quietly = TRUE))
stop("Package 'rgl' required for 3‑D plots. Install it first.")
## ------------------------------------------------------------
## 1. Pre‑process ---------------------------------------------
## ------------------------------------------------------------
dat <- if (normalize_data) scale(rawdata) else as.matrix(rawdata)
## ------------------------------------------------------------
## 2. Fit a multivariate skew‑t distribution (MLE) ----------
## ------------------------------------------------------------
# sn::mstFit() uses an EM‑type algorithm that returns
# dp – location (µ)
# Omega – scale matrix (Σ)
# alpha – skewness vector (γ)
# nu – degrees of freedom (controls kurtosis)
fit <- sn::mstFit(dat, method = "EM") # default: full covariance
mu_hat <- fit$dp
Sigma_hat <- fit$Omega
alpha_hat <- fit$alpha
nu_hat <- fit$nu
loglik <- fit$loglik
## ------------------------------------------------------------
## 3. Classical PCA on the estimated Σ̂ ------------------------
## ------------------------------------------------------------
eig <- eigen(Sigma_hat, symmetric = TRUE)
# keep only the requested number of components
if (is.null(ncomp)) ncomp <- length(eig$values)
ncomp <- min(ncomp, length(eig$values))
loadings <- eig$vectors[, 1:ncomp, drop = FALSE] # orthogonal eigenvectors
scores <- scale(dat, center = mu_hat, scale = FALSE) %*% loadings
## ------------------------------------------------------------
## 4. Assemble return object (prcomp‑like) --------------------
## ------------------------------------------------------------
out <- list()
out$x <- scores
out$rotation <- loadings
out$center <- mu_hat
out$scale <- if (normalize_data) attr(dat, "scaled:scale") else rep(1, ncol(dat))
out$method <- "Maximum‑Likelihood Skew‑t PCA"
out$fit <- list(loglik = loglik,
skewness = alpha_hat,
df = nu_hat)
class(out) <- "prcomp_skewt"
## ------------------------------------------------------------
## 5. Plotting ------------------------------------------------
## ------------------------------------------------------------
if (dim == "2D") {
plot(out$x[, 1], out$x[, 2],
xlab = "PC1", ylab = "PC2",
main = "Skew‑t ML‑PCA – 2D",
pch = 19, col = "steelblue")
# arrows for loadings (scaled for visual balance)
sf <- max(abs(out$x)) * 0.7
arrows(0, 0,
out$rotation[, 1] * sf,
out$rotation[, 2] * sf,
length = 0.1, col = "red")
text(out$rotation[, 1] * sf * 1.1,
out$rotation[, 2] * sf * 1.1,
labels = rownames(out$rotation),
col = "red", cex = 0.8)
} else if (dim == "3D") {
scores_df <- as.data.frame(out$x)
rgl::open3d()
rgl::plot3d(scores_df[, 1:3],
col = "steelblue", size = 5,
xlab = "PC1", ylab = "PC2", zlab = "PC3",
main = "Skew‑t ML‑PCA – 3D")
rgl::text3d(scores_df[, 1:3],
texts = rownames(rawdata), cex = 0.8, col = "black")
for (i in seq_len(nrow(out$rotation))) {
rgl::lines3d(rbind(c(0,0,0), out$rotation[i, 1:3]),
col = "red", lwd = 2)
rgl::text3d(out$rotation[i, 1:3],
texts = rownames(out$rotation)[i],
col = "red", cex = 0.8, pos = 4)
}
} else {
stop("Invalid dimension. Choose '2D' or '3D'.")
}
invisible(out)
}
How to use it
library(sn) # loads the functions used above
data(iris)
X <- iris[, 1:4] # four numeric variables
# 2‑D plot, correlation‑scaled data
pca_skewt_ml(X, dim = "2D", normalize_data = TRUE, ncomp = 2)
# 3‑D plot, raw covariance (no scaling)
pca_skewt_ml(X, dim = "3D", normalize_data = FALSE, ncomp = 3)
Inspecting the fit
res <- pca_skewt_ml(X, dim = "2D", normalize_data = TRUE)
# Log‑likelihood
res$fit$loglik
# Skewness vector (α) – each element tells you the direction of asymmetry
res$fit$skewness
# Degrees of freedom (ν) – smaller ν ⇒ heavier tails (excess kurtosis)
res$fit$df
*If ν is large (≈ 30–∞) the model collapses to a skew‑normal; if α = 0 it collapses to a t‑distribution; if both are zero you recover the ordinary Gaussian PCA.
3. Other “MLE with skew & kurtosis” families you might encounter
| Distribution | When to use it | Key R functions / packages |
|---|
| Skew‑Normal (SN) | Data are asymmetric but have roughly Gaussian tails. | sn::selm(), sn::msn() |
| Skew‑t (ST) | Asymmetric and heavy‑tailed (common in finance, psychometrics). | sn::stFit(), sn::mstFit() |
| Generalized Hyperbolic (GH) | Very flexible tails (both heavy and light) and skewness. | ghyp::fit.ghyp() |
| Pearson System | You can match any combination of mean, variance, skewness, kurtosis. | PearsonDS::pearsonFit() |
| Edgeworth / Gram‑Charlier | Approximate non‑normal densities using cumulants (γ₃, γ₄). | Custom code; see stats::polyroot for solving moment equations. |
| Generalized Lambda (GLD) | Purely quantile‑based; can mimic many shapes. | GLDEX::gld() |
| Mixture of Normals | Implicitly captures skewness/kurtosis via component weights. | mclust::Mclust(), mixtools::normalmixEM() |
All of them are maximum‑likelihood compatible: you write the log‑likelihood for the chosen density and maximise it (usually with a built‑in optimizer). The extra shape parameters are estimated together with the location‑scale parameters, giving you a full description of the first four moments.
4. How skewness & kurtosis appear in the likelihood
4.1 Skew‑Normal (univariate) pdf
[
f(x\mid\mu,\sigma,\alpha)=\frac{2}{\sigma},
\phi!\Bigl(\frac{x-\mu}{\sigma}\Bigr),
\Phi!\Bigl(\alpha,\frac{x-\mu}{\sigma}\Bigr)
]
- (\phi) = standard normal pdf, (\Phi) = standard normal cdf.
- (\alpha) controls skewness: (\alpha=0) → symmetric normal.
The log‑likelihood is simply
[
\ell(\mu,\sigma,\alpha)=\sum_{i=1}^{n}
\log\Bigl[2,\phi(z_i),\Phi(\alpha z_i)\Bigr],
\qquad z_i=\frac{x_i-\mu}{\sigma}.
]
4.2 Skew‑t (univariate) pdf
[
f(x\mid\mu,\sigma,\alpha,\nu)=
\frac{2}{\sigma},
t_{\nu}!\Bigl(\frac{x-\mu}{\sigma}\Bigr),
T_{\nu+1}!\Bigl(\alpha,\frac{x-\mu}{\sigma}
\sqrt{\frac{\nu+1}{\nu + (x-\mu)^2/\sigma^2}}\Bigr)
]
- (t_{\nu}) = Student‑t pdf, (T_{\nu+1}) = Student‑t cdf.
- (\alpha) → skewness, (\nu) → kurtosis (tail heaviness).
Again the log‑likelihood is the sum of the log of this expression; numerical optimisation (EM or BFGS) is used.
4.3 Multivariate case
The multivariate skew‑t density (Azzalini & Capitanio, 2003) can be written as
[
f_{\text{MST}}(\mathbf{x})=
2,t_{p}(\mathbf{x}\mid\boldsymbol\mu,\boldsymbol\Sigma,\nu),
T_{1}!\Bigl(\alpha^{\top}\boldsymbol\omega^{-1}(\mathbf{x}-\boldsymbol\mu)
\sqrt{\frac{\nu+p}{\nu+ d(\mathbf{x})}}\Bigr)
]
where
- (t_{p}) = multivariate t pdf,
- (T_{1}) = univariate t cdf,
- (\boldsymbol\omega) = Cholesky factor of (\boldsymbol\Sigma),
- (d(\mathbf{x}) = (\mathbf{x}-\boldsymbol\mu)^{\top}\boldsymbol\Sigma^{-1}(\mathbf{x}-\boldsymbol\mu)).
The log‑likelihood is the log of the product of the two terms above, summed over all observations. The EM algorithm used in sn::mstFit() treats the latent “skewness” variable as missing data, leading to closed‑form E‑steps and a simple M‑step for (\boldsymbol\mu,\boldsymbol\Sigma,\alpha,\nu).
5. When should you use an MLE with skew/kurtosis?
| Situation | Recommended family | Why |
|---|
| Mild asymmetry, near‑Gaussian tails | Skew‑Normal | Only one extra shape parameter (α). Fast EM algorithm. |
| Heavy tails + asymmetry (finance, psychometrics) | Skew‑t | Captures both skewness (α) and tail weight (ν). |
| Very flexible tail behaviour (e.g., insurance loss data) | Generalized Hyperbolic or Pearson System | Four shape parameters give you independent control of skewness and kurtosis. |
| You need a closed‑form moment‑matching estimator | Edgeworth / Gram‑Charlier | Useful for theoretical work, but not a true pdf (may become negative). |
| You want a distribution‑free way to model shape | Finite mixture of normals | Skewness/kurtosis emerge from mixture weights; MLE is straightforward with mclust. |
6. Quick checklist for implementing your own “MLE with skew & kurtosis”
- Pick a parametric family that includes the shape parameters you need.
- Write the log‑likelihood (or use a package that already provides it).
- Choose an optimiser:
- EM (available for SN, ST, MST) – stable, often faster.
- General‑purpose optimisers (
optim, nlm, nlminb) – needed for Pearson, GH, GLD.
- Check convergence – look at the gradient, Hessian, or EM log‑likelihood monotonicity.
- Validate the fit:
- Compare empirical vs. model skewness/kurtosis (
moments::skewness, moments::kurtosis).
- Plot a Q‑Q plot of the fitted distribution (
qqplot).
- Use information criteria (AIC, BIC) to compare families.
- If you need PCA‑type scores, extract the covariance matrix (Σ̂) from the fitted model and run a standard eigen‑decomposition (as shown in the script).
7. TL;DR (the “answer in a nutshell”)
- Maximum‑likelihood “extended to skew and kurtosis” means fitting a distribution whose density already contains parameters for asymmetry (skewness) and tail weight (kurtosis) and then maximising its likelihood.
- The most common choices are the skew‑normal (adds a shape vector α) and the skew‑t (adds α + degrees‑of‑freedom ν).
- In R you can do it in a few lines with the
sn package (sn::mstFit() for multivariate skew‑t, sn::selm() for skew‑normal).
- After you have the estimated covariance matrix Σ̂ you can perform ordinary PCA on Σ̂ to obtain orthogonal component loadings and scores – the only difference from classical PCA is that the estimates of Σ̂, µ, α, ν come from a likelihood that accounts for skewness and kurtosis.
- The script
pca_skewt_ml() above shows the whole pipeline (fit → eigen‑decompose → 2‑D/3‑D plot) and returns the log‑likelihood, the skewness vector, and the degrees‑of‑freedom (kurtosis) for inspection.
Feel free to copy the function, adapt the number of components, or swap sn::mstFit() for another family (e.g., ghyp::fit.ghyp() for a Generalized Hyperbolic model) – the rest of the code stays the same. If you run into any specific data‑set issues or need help interpreting the shape parameters, just let me know!