Learn R Programming

tensorBSS (version 0.3.9)

tensorCentering: Center an Array of Observations

Description

Centers an array of array-valued observations by substracting a location array (the mean array by default) from each observation.

Usage

tensorCentering(x, location = NULL)

Value

Array of centered observations with the same dimensions as the input array. The used location is returned as attribute "location".

Arguments

x

Array of order at least two with the last dimension corresponding to the sampling units.

location

The location to be used in the centering. Either NULL, defaulting to the mean array, or a user-specified \(p_1 \times p_2 \times \ldots \times p_r\)-dimensional array.

Author

Joni Virta

Details

Centers a \(p_1 \times p_2 \times \ldots \times p_r \times n\)-dimensional array by substracting the \(p_1 \times p_2 \times \ldots \times p_r\)-dimensional location from each of the observed arrays.

Examples

Run this code
## Generate sample data.
n <- 1000
x <- t(cbind(rnorm(n, mean = 0),
             rnorm(n, mean = 1),
             rnorm(n, mean = 2),
             rnorm(n, mean = 3),
             rnorm(n, mean = 4),
             rnorm(n, mean = 5)))
             
dim(x) <- c(3, 2, n)

## Centered data
xcen <- tensorCentering(x)

## Check the means of individual cells
apply(xcen, 1:2, mean)

Run the code above in your browser using DataLab