rmse {Correlplot}R Documentation

Calculate the root mean squared error

Description

Program rmse calculates the RMSE for a matrix approximation.

Usage

rmse(R, Rhat, W = matrix(1, nrow(R), ncol(R)) - diag(nrow(R)),
     verbose = FALSE, per.variable = FALSE)

Arguments

R

The original matrix

Rhat

The approximating matrix

W

A symmetric matrix of weights

verbose

Print output (verbose=TRUE) or not (verbose=FALSE)

per.variable

Calculate the RMSE for the whole matrix (per.variable=FALSE) or for each variable seperately (per.variable=TRUE)

Details

By default, function rmse assumes a symmetric correlation matrix as input, together with its approximation. The approximation does not need to be symmetric. Weight matrix W has to be symmetric. By default, the diagonal is excluded from RMSE calcuations (W = J - I). To include it, specify W = J, that is set W = matrix(1, nrow(R), ncol(R))

Value

the calculated rmse

Author(s)

Jan Graffelman (jan.graffelman@upc.edu)

References

Graffelman, J. and De Leeuw, J. (2023) Improved approximation and visualization of the correlation matrix. The American Statistician pp. 1–20. doi:10.1080/00031305.2023.2186952

Examples

data(banknotes)
X <- as.matrix(banknotes[,1:6])
p <- ncol(X)
J <- matrix(1,p,p)
R <- cor(X)
out.sd <- eigen(R)
V <- out.sd$vectors
Dl <- diag(out.sd$values)
V2 <- V[,1:2]
D2 <- Dl[1:2,1:2]
Rhat <- V2%*%D2%*%t(V2)
rmse(R,Rhat,W=J)

[Package Correlplot version 1.1.0 Index]