ncenter {multiway}R Documentation

Center n-th Dimension of Array

Description

Fiber-center across the levels of the specified mode. Can input 2-way, 3-way, and 4-way arrays, or input a list containing array elements.

Usage

ncenter(X, mode = 1)

Arguments

X

Array (2-way, 3-way, or 4-way) or a list containing array elements.

mode

Mode to center across.

Details

With X a matrix (I-by-J) there are two options:

mode=1: x[i,j] - mean(x[,j])
mode=2: x[i,j] - mean(x[i,])

With X a 3-way array (I-by-J-by-K) there are three options:

mode=1: x[i,j,k] - mean(x[,j,k])
mode=2: x[i,j,k] - mean(x[i,,k])
mode=3: x[i,j,k] - mean(x[i,j,])

With X a 4-way array (I-by-J-by-K-by-L) there are four options:

mode=1: x[i,j,k,l] - mean(x[,j,k,l])
mode=2: x[i,j,k,l] - mean(x[i,,k,l])
mode=3: x[i,j,k,l] - mean(x[i,j,,l])
mode=4: x[i,j,k,l] - mean(x[i,j,k,])

Value

Returns centered version of X.

Note

When entering a list with array elements, each element must be an array (2-way, 3-way, or 4-way) that contains the specified mode to center across.

Author(s)

Nathaniel E. Helwig <helwig@umn.edu>

Examples

##########   EXAMPLE 1   ##########
X <- matrix(rnorm(2000),100,20)
Xc <- ncenter(X)          # center across rows
sum(colSums(Xc))
Xc <- ncenter(Xc,mode=2) # recenter across columns
sum(colSums(Xc)) 
sum(rowSums(Xc))


##########   EXAMPLE 2   ##########
X <- array(rnorm(20000),dim=c(100,20,10))
Xc <- ncenter(X,mode=2)   # center across columns
sum(rowSums(Xc))


##########   EXAMPLE 3   ##########
X <- array(rnorm(100000),dim=c(100,20,10,5))
Xc <- ncenter(X,mode=4)   # center across 4-th mode
sum(rowSums(Xc))


##########   EXAMPLE 4   ##########
X <- replicate(5,array(rnorm(20000),dim=c(100,20,10)),simplify=FALSE)
Xc <- ncenter(X)
sum(colSums(Xc[[1]]))


[Package multiway version 1.0-6 Index]