compute_rms: Compute the root mean-squared error of a PCA projection

Description Usage Arguments Value Examples

View source: R/pca_full.R

Description

Root mean-squared error is the square root of the element-wise error's mean. This is a useful quantity to display during parameter estimation in pca_updates since it is a measure of how well the PCA projection is fitting the data.

Usage

1
compute_rms(X, A, S, M, ndata, verbose = TRUE)

Arguments

X

matrix – the data matrix with variables in rows and observations in columns.

A

matrix – initialised loadings matrix with observed variables in rows and latent variables in columns.

S

matrix – initialised factor scores matrix with latent variables in rows and observations in columns.

M

matrix – logical matrix whose values indicate whether the corresponding entry in X is observed.

ndata

numerical – the total number of observed values.

verbose

logical – whether extra output should be displayed.

Value

A list of length 2:

errMx

matrix – matrix of element-wise differences (errors) between the observed data and the PCA projection.

rms

numerical – root mean-squared error of the PCA projection.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
p <- 20
n <- 7
set.seed(10045)
X <- matrix(rnorm(p*n), p, n)
miss.inds <- sample(1:(p*n), (p*n)/4)
X[miss.inds] <- NA
M <- !is.na(X)
Nobs_i <- rowSums(M)
Mu <- rowSums(X, na.rm = TRUE) / Nobs_i
update_bias <- TRUE
Xcent <- subtractMu(Mu=Mu, X=X, M=M, p=p, n=n, update_bias=update_bias, verbose=TRUE)
init.model <- initParms(p=p, n=n, ncomp=2, verbose = TRUE)
compute_rms(X=X, A=init.model$A, S=init.model$S, M=M, ndata=sum(Nobs_i), verbose=TRUE)

HGray384/pcaNet documentation built on Nov. 14, 2020, 11:11 a.m.