| Type: | Package |
| Title: | Matrix Normal Distribution |
| Version: | 1.2 |
| Date: | 2026-09-03 |
| Author: | Michail Tsagris [aut, cre], Alzeley Omar [ctb] |
| Maintainer: | Michail Tsagris <mtsagris@uoc.gr> |
| Depends: | R (≥ 4.0) |
| Imports: | rangen, Rfast |
| 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. |
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| NeedsCompilation: | no |
| Packaged: | 2026-09-03 06:20:18 UTC; mtsag |
| Repository: | CRAN |
| Date/Publication: | 2026-09-03 07:20:02 UTC |
Matrix Normal Distribution
Description
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.
Details
| Package: | MN |
| Type: | Package |
| Version: | 1.2 |
| Date: | 2026-09-03 |
Maintainers
Michail Tsagris <mtsagris@uoc.gr>.
Author(s)
Michail Tsagris mtsagris@uoc.gr and Omar Alzeley oazeley@uqu.edu.sa
References
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
Description
Density of the matrix normal distribution.
Usage
dmn(X, M, U, V, logged = FALSE)
Arguments
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? |
Value
A numeric vector with the (logged) density values.
Author(s)
Omar Alzeley.
R implementation and documentation: Omar Alzeley oazeley@uqu.edu.sa.
References
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.
See Also
Examples
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
Description
Distance-Distance Plot
Usage
ddplot(X, M, U, V)
Arguments
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 |
Details
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.
Value
A scatter plot of the Mahalanobis distances.
Author(s)
Michail Tsagris and Omar Alzeley.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr and Omar Alzeley oazeley@uqu.edu.sa.
References
Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
See Also
Examples
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
Description
Kolmogorov-Smirnov test for matrix normality
Usage
ddkstest(X, M, U, V, alpha = 0.05)
Arguments
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. |
Details
The Kolmogorov-Smirnov test for matrix normality is performed. See Pocuca (2019) for more details.
Value
A message. If the Kronecker product covariance structure is not present, the message reads "Reject" and "Not reject otherwise".
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
Pocuca N., Gallaugher M. P., Clark K. M. & McNicholas P. D. (2019). Assessing and Visualizing Matrix Variate Normality. arXiv:1910.02859.
See Also
Examples
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
Description
Log-likelihood ratio test for equality of all parameters.
Usage
mn.equaltest(Y1, Y2, tol = 1e-6)
Arguments
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. |
Details
A log-likelihood ratio test comparing the equality of all parameters, mean matrices and covariance matrices mean matrices is performed.
Value
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. |
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
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.
See Also
Examples
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
Description
Log-likelihood ratio test for equality of mean matrices.
Usage
mn.ttest(Y1, Y2, tol = 1e-6, maxiter = 100)
Arguments
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. |
Details
A log-likelihood ratio test comparing the equality of mean matrices, M_1=M_2 is performed,
and the alternative is that the mean matrices are not equal.
Value
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. |
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
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.
See Also
Examples
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
Description
Matrix normal regression.
Usage
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)
Arguments
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. |
Details
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.
Value
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. |
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
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.
See Also
Examples
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
Description
Maximum likelihood estimation of the matrix normal distribution.
Usage
mn.mle(Y, tol = 1e-6)
Arguments
Y |
A list with k elements (k is the sample size), k matrices of dimension |
tol |
The tolerance value to terminate the iterative algorithm. |
Value
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 |
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
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.
See Also
Examples
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
Description
Random matrices simulation from the matrix normal distribution.
Usage
rmn(k, M, U, V)
Arguments
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 |
Value
A list with k elements, k matrices of dimension n \ times p each. These are the random matrices drawn from a matrix normal distribution.
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
https://en.wikipedia.org/wiki/Matrix_normal_distribution#Definition
See Also
Examples
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)