subtractMu: Subtract the row means from a matrix of data with missing...

Description Usage Arguments Value Examples

View source: R/pca_full.R

Description

internal function within pca_full to subtract the row means from a matrix of data using only the observed values. Offers little utility standalone.

Usage

1
subtractMu(Mu, X, M, p, n, update_bias, verbose = TRUE)

Arguments

Mu

numeric – the sample mean of the observed variables.

X

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

M

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

p

numeric – the number of variables.

n

numeric – the number of observations.

update_bias

logical – whether the mean should be subtracted. or not.

verbose

logical – whether extra output should be displayed.

Value

X matrix – centered data matrix.

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)
X-Xcent
Mu # all observed values in each column equal to Mu

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