# T2func: Algorithm for the Tucker2 model In ThreeWay: Three-Way Component Analysis

## Description

Alternating Least Squares algorithm for the minimization of the Tucker2 loss function.

## Usage

 ```1 2``` ``` T2func(X, n, m, p, r1, r2, r3, start, conv, model, A, B, C, H) ```

## Arguments

 `X` Matrix (or data.frame coerced to a matrix) of order (`n` `x` `mp`) containing the matricized array (frontal slices) `n` Number of `A`-mode entities `m` Number of `B`-mode entities `p` Number of `C`-mode entities `r1` Number of extracted components for the `A`-mode `r2` Number of extracted components for the `B`-mode `r3` Number of extracted components for the `C`-mode `start` Starting point: 0 starting point of the algorithm from generalized eigenvalue decomposition, 1 random starting point (orthonormalized component matrices), 2 if users specified component matrices `conv` Convergence criterion `model` Tucker2 model choice (1 for T2-AB, 2 for T2-AC, 3 for T2-BC) `A` Optional (necessary if start=2) starting value for `A` `B` Optional (necessary if start=2) starting value for `B` `C` Optional (necessary if start=2) starting value for `C` `H` Optional (necessary if start=2) starting value for the matricized core array (frontal slices)

## Value

A list including the following components:

 `A` Orthonormal component matrix for the `A`-mode `B` Orthonormal component matrix for the `B`-mode `C` Orthonormal component matrix for the `C`-mode `H` Matricized core array (frontal slices) `f` Loss function value `fp` Fit percentage `iter` Number of iterations `cputime` Computation time `La` Matrix which should be diagonal, and if so, contain ‘intrinsic eigenvalues’ for `A`-mode `Lb` Matrix which should be diagonal, and if so, contain ‘intrinsic eigenvalues’ for `B`-mode `Lc` Matrix which should be diagonal, and if so, contain ‘intrinsic eigenvalues’ for `C`-mode

## Note

The loss function to be minimized is ||X_A - A G_A kron(C',B')||^2 where X_A and G_A denote the matricized (frontal slices) data array and core array, respectively, and kron stands for the Kronecker product.
`T2func` is the same as `T2funcrep` except that all printings are available.

## Author(s)

Maria Antonietta Del Ferraro mariaantonietta.delferraro@yahoo.it
Henk A.L. Kiers h.a.l.kiers@rug.nl
Paolo Giordani paolo.giordani@uniroma1.it

## References

H.A.L. Kiers, P.M. Kroonenberg \& J.M.F. ten Berge (1992). An efficient algorithm for TUCKALS3 on data with large numbers of observation units. Psychometrika 57:415–422.
P.M. Kroonenberg and J. de Leeuw (1980). Principal component analysis of three-mode data by means of alternating least squares algorithms. Psychometrika 45:69–97.

`T2`, `T2funcrep`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16``` ```data(Bus) # labels for Bus data laba <- rownames(Bus) labb <- substr(colnames(Bus)[1:5], 1, 1) labc <- substr(colnames(Bus)[seq(1,ncol(Bus),5)], 3, 8) # T2-AB solution using two components for the A- and B-modes # (rational starting point by SVD [start=0]) BusT2 <- T2func(Bus, 7, 5, 37, 2, 2, 37, 0, 1e-6, 1) # T2-AC solution using two components for for the A- and C-modes # (random orthonormalized starting point [start=1]) BusT2 <- T2func(Bus, 7, 5, 37, 2, 5, 2, 1, 1e-6, 2) # T2-BC solution using two components for the B- and C- modes # (user starting point [start=2]) BusT2 <- T2func(Bus, 7, 5, 37, 7, 2, 2, 1, 1e-6, 3, diag(7), matrix(rnorm(5*2),nrow=5), matrix(rnorm(37*2),nrow=37), matrix(rnorm(7*4),nrow=7)) ```