if (FALSE) {
## Load Library:
require(sn)
## mstFit -
# Fit Example:
N <- 1000
xi <- c(0, 0)
Omega <- diag(2); Omega[2,1] <- Omega[1,2] <- 0.5
alpha <- c(2, -2)
nu <- 4
set.seed(4711)
X <- rmst(n=N, xi, Omega, alpha, nu=4)
ans <- mstFit(X)
# Show fitted Parameters:
print(ans)
# 2-D Density Plot:
plot(hexBinning(X[,1], X[, 2], bins = 30), main="Skew Student-t")
# Add Contours:
N <- 101
x <- seq(min(X[, 1]), max(X[, 1]), l=N)
y <- seq(min(X[, 2]), max(X[, 2]), l=N)
u <- grid2d(x, y)$x
v <- grid2d(x, y)$y
XY <- cbind(u, v)
param <- ans@fit$dp
Z <- matrix(dmst(
XY, param[[1]][1,], param[[2]], param[[3]], param[[4]]), ncol=N)
contour(x, y, Z, add=TRUE, col="green", lwd=2)
grid(col="brown", lty=3)
## mstFit -
# Fit Example with fixed nu=4:
ans <- mstFit(X, fixed.nu=4)
# Show fitted Parameters:
print(ans)
# 2-D Density Plot:
plot(hexBinning(X[,1], X[, 2], bins = 30), main="Student-t | fixed nu")
# Add Contours:
param <- ans@fit$dp
Z <- matrix(dmst(
XY, param[[1]][1,], param[[2]], param[[3]], nu=4), ncol=N)
contour(x, y, Z, add=TRUE, col="green", lwd=2)
grid(col="brown", lty=3)
}
Run the code above in your browser using DataLab