| Title: | Matrix Normal Distribution |
|---|---|
| Description: | Density computation, random matrix generation, maximum likelihood estimation, and regression for the matrix normal distribution. References: Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. <doi:10.48550/arXiv.1910.02859> and the relevant wikipedia page. |
| Authors: | Michail Tsagris [aut, cre], Alzeley Omar [ctb] |
| Maintainer: | Michail Tsagris <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.2 |
| Built: | 2026-09-21 11:12:42 UTC |
| Source: | https://github.com/cran/MN |
Density computation, random matrix generation and maximum likelihood estimation of the matrix normal distribution. For references see: Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859 and the relevant wikipedia page.
| Package: | MN |
| Type: | Package |
| Version: | 1.2 |
| Date: | 2026-09-03 |
Michail Tsagris <[email protected]>.
Michail Tsagris [email protected] and Omar Alzeley [email protected]
Pocuca, N., Gallaugher, M. P., Clark, K. M., & McNicholas, P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
Density of the matrix normal distribution.
dmn(X, M, U, V, logged = FALSE)dmn(X, M, U, V, logged = FALSE)
X |
A list with k elements, k matrices of dimension |
M |
The mean matrix of the distribution, a numerical matrix of dimensions |
U |
The covariance matrix associated with the rows, a numerical matrix of dimensions |
V |
The covariance matrix associated with the columns, a numerical matrix of dimensions |
logged |
Should the logarithm of the density be computed? |
A numeric vector with the (logged) density values.
Omar Alzeley.
R implementation and documentation: Omar Alzeley [email protected].
https://en.wikipedia.org/wiki/Matrix_normal_distribution#Definition
Pocuca, N., Gallaugher, M. P., Clark, K. M., & McNicholas, P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- rmn(10, M, U, V) dmn(X, M, U, V, TRUE)M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- rmn(10, M, U, V) dmn(X, M, U, V, TRUE)
Distance-Distance Plot
ddplot(X, M, U, V)ddplot(X, M, U, V)
X |
A list with k elements, k matrices of dimension |
M |
The mean matrix of the distribution, a numerical matrix of dimensions |
U |
The covariance matrix associated with the rows, a numerical matrix of dimensions |
V |
The covariance matrix associated with the columns, a numerical matrix of dimensions |
The distance-distance plot is produced. This is a scatter plot of the Mahalanobis distances computed using the estimated parameters from the multivariate normal and matrix normal distribution. See Pocuca et al. (2019) for more details.
A scatter plot of the Mahalanobis distances.
Michail Tsagris and Omar Alzeley.
R implementation and documentation: Michail Tsagris [email protected] and Omar Alzeley [email protected].
Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- rmn(100, M, U, V) ddplot(X, M, U, V)M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- rmn(100, M, U, V) ddplot(X, M, U, V)
Kolmogorov-Smirnov test for matrix normality
ddkstest(X, M, U, V, alpha = 0.05)ddkstest(X, M, U, V, alpha = 0.05)
X |
A list with k elements, k matrices of dimension |
M |
The mean matrix of the distribution, a numerical matrix of dimensions |
U |
The covariance matrix associated with the rows, a numerical matrix of dimensions |
V |
The covariance matrix associated with the columns, a numerical matrix of dimensions |
alpha |
The significance level for the test, set by default equal to 0.05. |
The Kolmogorov-Smirnov test for matrix normality is performed. See Pocuca (2019) for more details.
A message. If the Kronecker product covariance structure is not present, the message reads "Reject" and "Not reject otherwise".
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- rmn(200, M, U, V) ddkstest(X, M, U, V)M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- rmn(200, M, U, V) ddkstest(X, M, U, V)
Log-likelihood ratio test for equality of all parameters.
mn.equaltest(Y1, Y2, tol = 1e-6)mn.equaltest(Y1, Y2, tol = 1e-6)
Y1 |
The observations of the first sample. A list with k1 elements (k1 is the sample size),
k1 matrices of dimension |
Y2 |
The observations of the first sample. A list with k2 elements (k2 is the sample size),
k2 matrices of dimension |
tol |
The tolerance value to terminate the iterative algorithm. |
A log-likelihood ratio test comparing the equality of all parameters, mean matrices and covariance matrices mean matrices is performed.
This is an "htest"class object. Thus it returns a list including:
statistic |
The test statistic value. |
parameter |
The degrees of freedom of the test. |
p.value |
The p-value of the test. |
alternative |
A character with the alternative hypothesis. |
method |
A character with the test used. |
data.name |
A character vector with two elements. |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
https://en.wikipedia.org/wiki/Matrix_normal_distribution#Definition
Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) Y1 <- MN::rmn(250, M, U, V) Y2 <- MN::rmn(200, M, U, V) mn.equaltest(Y1, Y2)M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) Y1 <- MN::rmn(250, M, U, V) Y2 <- MN::rmn(200, M, U, V) mn.equaltest(Y1, Y2)
Log-likelihood ratio test for equality of mean matrices.
mn.ttest(Y1, Y2, tol = 1e-6, maxiter = 100)mn.ttest(Y1, Y2, tol = 1e-6, maxiter = 100)
Y1 |
The observations of the first sample. A list with k1 elements (k1 is the sample size),
k1 matrices of dimension |
Y2 |
The observations of the first sample. A list with k2 elements (k2 is the sample size),
k2 matrices of dimension |
tol |
The tolerance value to terminate the iterative algorithm. |
maxiter |
The maximum number of iterations allowed. |
A log-likelihood ratio test comparing the equality of mean matrices, is performed,
and the alternative is that the mean matrices are not equal.
This is an "htest"class object. Thus it returns a list including:
statistic |
The test statistic value. |
parameter |
The degrees of freedom of the test. |
p.value |
The p-value of the test. |
alternative |
A character with the alternative hypothesis. |
method |
A character with the test used. |
data.name |
A character vector with two elements. |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
https://en.wikipedia.org/wiki/Matrix_normal_distribution#Definition
Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) Y1 <- MN::rmn(150, M, U, V) Y2 <- MN::rmn(100, M, U, V) mn.ttest(Y1, Y2)M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) Y1 <- MN::rmn(150, M, U, V) Y2 <- MN::rmn(100, M, U, V) mn.ttest(Y1, Y2)
Matrix normal regression.
mn.reg(Y, X, tol = 1e-6, maxiter = 100, Xnew = NULL) mn.reg2(Y, x, tol = 1e-6, maxiter = 100, xnew = NULL) mn.reg_null(Y, tol = 1e-6, maxiter = 100)mn.reg(Y, X, tol = 1e-6, maxiter = 100, Xnew = NULL) mn.reg2(Y, x, tol = 1e-6, maxiter = 100, xnew = NULL) mn.reg_null(Y, tol = 1e-6, maxiter = 100)
Y |
A list with k elements (k is the sample size), k matrices of dimension |
X |
A list with the matrix covariates. A list with k elements (k is the sample size),
k matrices of dimension |
x |
A matrix with covariates, where the i-th row represents the covariate vector is related to the i-th response matrix Y. |
tol |
The tolerance value to terminate the iterative algorithm. |
maxiter |
The maximum number of iterations allowed. |
Xnew |
If you have new X values (list of matrices or a list with a single matrix) and want to predict the values of the response matrices pass them here. |
xnew |
If you have new x values (matrix or vector) and want to predict the values of the response matrices pass them here. |
The function mn.reg() performs matrix normal regression with matrix covariates. The function mn.reg2() performs matrix normal regression with a matrix of covariates. The function mn.reg_null() performs matrix normal regression with the constant only. This is useful for performing a log-likelihood ratio test of a regression model against the constant term.
A list including:
runtime |
The runtime required for the whole fitting procedure. |
iters |
The number of iterations required for the estimation of the U and V matrices. |
loglik |
The log-likelihood value. |
B |
The estimated matrix of coefficients. |
U |
The estimated covariance matrix associated with the rows, a numerical matrix of
dimensions |
V |
The estimated covariance matrix associated with the columns, a numerical matrix
of dimensions |
est |
The estimated matrix responses for the new x values, otherwise this is NULL. |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
https://en.wikipedia.org/wiki/Matrix_normal_distribution#Definition
Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) Y <- MN::rmn(150, M, U, V) x <- iris[, 1:2] colnames(x) <- c("sepal-length", "sepal-width") mod2 <- mn.reg2(Y, x) M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- MN::rmn(150, M/3, U, V) mod <- mn.reg(Y, X)M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) Y <- MN::rmn(150, M, U, V) x <- iris[, 1:2] colnames(x) <- c("sepal-length", "sepal-width") mod2 <- mn.reg2(Y, x) M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- MN::rmn(150, M/3, U, V) mod <- mn.reg(Y, X)
Maximum likelihood estimation of the matrix normal distribution.
mn.mle(Y, tol = 1e-6)mn.mle(Y, tol = 1e-6)
Y |
A list with k elements (k is the sample size), k matrices of dimension |
tol |
The tolerance value to terminate the iterative algorithm. |
A list including:
runtime |
The runtime required for the whole fitting procedure. |
iters |
The number of iterations required for the estimation of the U and V matrices. |
loglik |
The log-likelihood value. |
M |
The estimated mean matrix of the distribution, a numerical matrix of dimensions |
U |
The estimated covariance matrix associated with the rows, a numerical matrix of dimensions |
V |
The estimated covariance matrix associated with the columns, a numerical matrix of dimensions |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
https://en.wikipedia.org/wiki/Matrix_normal_distribution#Definition
Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) Y <- rmn(200, M, U, V) mod <- mn.mle(Y)M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) Y <- rmn(200, M, U, V) mod <- mn.mle(Y)
Random matrices simulation from the matrix normal distribution.
rmn(k, M, U, V)rmn(k, M, U, V)
k |
The sample size, the number of matrices to simulate. |
M |
The mean matrix of the distribution, a numerical matrix of dimensions |
U |
The covariance matrix associated with the rows, a numerical matrix of dimensions |
V |
The covariance matrix associated with the columns, a numerical matrix of dimensions |
A list with k elements, k matrices of dimension each. These are the random matrices drawn from a matrix normal distribution.
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
https://en.wikipedia.org/wiki/Matrix_normal_distribution#Definition
M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- rmn(10, M, U, V)M <- as.matrix(iris[1:8, 1:4]) U <- cov( matrix( rnorm(100 * 8), ncol = 8 ) ) V <- cov( iris[1:50, 1:4] ) X <- rmn(10, M, U, V)