rmse: Calculate the root mean squared error

View source: R/rmse.R

rmseR 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=nrow(R),ncol=ncol(R)), omit.diagonal = TRUE,
     verbose = FALSE, per.variable = FALSE)

Arguments

R

The original matrix

Rhat

The approximating matrix

W

A matrix of weights

omit.diagonal

Use all elements (omit.diagonal=FALSE) or only below-diagonal elements (omit.diagonal=TRUE)

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, and calculates the RMSE using all elements below the diagonal of the supplied matrix. If weights are supplied, the RMSE calculation excludes those observations that have zero weight.

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. Available online as latest article doi: 10.1080/00031305.2023.2186952

Examples

data(banknotes)
X <- as.matrix(banknotes[,1:6])
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)

Correlplot documentation built on March 7, 2023, 8:33 p.m.