Fits Richard A. Harshman's Parallel Factors-2 (Parafac2) model to 3-way or 4-way ragged data arrays. Parameters are estimated via alternating least squares with optional constraints.
X: For 3-way Parafac2: list of length K where k-th element is I[k]-by-J matrix or three-way data array with dim=c(I,J,K). For 4-way Parafac2: list of length L where l-th element is I[l]-by-J-by-K array or four-way data array with dim=c(I,J,K,L). Missing data are allowed (see Note).
nfac: Number of factors.
nstart: Number of random starts.
const: Character vector of length 3 or 4 giving the constraints for each mode (defaults to unconstrained). See const for the 24 available options.
control: List of parameters controlling options for smoothness constraints. This is passed to const.control, which describes the available options.
Gfixed: Used to fit model with fixed Phi matrix: crossprod(Gfixed) = Phi.
Bfixed: Used to fit model with fixed Mode B weights.
Cfixed: Used to fit model with fixed Mode C weights.
Dfixed: Used to fit model with fixed Mode D weights.
Gstart: Starting Mode A crossproduct matrix: crossprod(Gstart) = Phi. Default uses random weights.
Bstart: Starting Mode B weights. Default uses random weights.
Cstart: Starting Mode C weights. Default uses random weights.
Dstart: Starting Mode D weights. Default uses random weights.
Gstruc: Structure constraints for Mode A crossproduct matrix: crossprod(Gstruc) = Phistruc. See Note.
Bstruc: Structure constraints for Mode B weights. See Note.
Cstruc: Structure constraints for Mode C weights. See Note.
Dstruc: Structure constraints for Mode D weights. See Note.
Gmodes: Mode ranges for Mode A weights (for unimodality constraints). Ignored.
Bmodes: Mode ranges for Mode B weights (for unimodality constraints). See Note.
Cmodes: Mode ranges for Mode C weights (for unimodality constraints). See Note.
Dmodes: Mode ranges for Mode D weights (for unimodality constraints). See Note.
maxit: Maximum number of iterations.
ctol: Convergence tolerance (R^2 change).
parallel: Logical indicating if parLapply should be used. See Examples.
cl: Cluster created by makeCluster. Only used when parallel=TRUE.
output: Output the best solution (default) or output all nstart solutions.
verbose: If TRUE, fitting progress is printed via txtProgressBar. Ignored if parallel=TRUE.
backfit: Should backfitting algorithm be used for cmls?
Details
Given a list of matrices X[[k]] = matrix(xk,I[k],J) for k = seq(1,K), the 3-way Parafac2 model (with Mode A nested in Mode C) can be written as
X[[k]] = tcrossprod(A[[k]] %*% diag(C[k,]), B) + E[[k]]
subject to crossprod(A[[k]]) = Phi
where A[[k]] = matrix(ak,I[k],R) are the Mode A (first mode) weights for the k-th level of Mode C (third mode), Phi is the common crossproduct matrix shared by all K levels of Mode C, B = matrix(b,J,R) are the Mode B (second mode) weights, C = matrix(c,K,R) are the Mode C (third mode) weights, and E[[k]] = matrix(ek,I[k],J) is the residual matrix corresponding to k-th level of Mode C.
Given a list of arrays X[[l]] = array(xl, dim = c(I[l],J,K)) for l = seq(1,L), the 4-way Parafac2 model (with Mode A nested in Mode D) can be written as
X[[l]][,,k] = tcrossprod(A[[l]] %*% diag(D[l,]*C[k,]), B) + E[[l]][,,k]
subject to crossprod(A[[l]]) = Phi
where A[[l]] = matrix(al,I[l],R) are the Mode A (first mode) weights for the l-th level of Mode D (fourth mode), Phi is the common crossproduct matrix shared by all L levels of Mode D, D = matrix(d,L,R) are the Mode D (fourth mode) weights, and E[[l]] = array(el, dim = c(I[l],J,K)) is the residual array corresponding to l-th level of Mode D.
Weight matrices are estimated using an alternating least squares algorithm with optional constraints.
Returns
If output = "best", returns an object of class "parafac2" with the following elements: - A: List of Mode A weight matrices.
B: Mode B weight matrix.
C: Mode C weight matrix.
D: Mode D weight matrix.
Phi: Mode A crossproduct matrix.
SSE: Sum of Squared Errors.
Rsq: R-squared value.
GCV: Generalized Cross-Validation.
edf: Effective degrees of freedom.
iter: Number of iterations.
cflag: Convergence flag. See Note.
const: See argument const.
control: See argument control.
fixed: Logical vector indicating whether 'fixed' weights were used for each mode.
struc: Logical vector indicating whether 'struc' constraints were used for each mode.
Otherwise returns a list of length nstart where each element is an object of class "parafac2".
References
Harshman, R. A. (1972). PARAFAC2: Mathematical and technical notes. UCLA Working Papers in Phonetics, 22, 30-44.
Helwig, N. E. (2013). The special sign indeterminacy of the direct-fitting Parafac2 model: Some implications, cautions, and recommendations, for Simultaneous Component Analysis. Psychometrika, 78, 725-739.
Helwig, N. E. (2017). Estimating latent trends in multivariate longitudinal data via Parafac2 with functional and structural constraints. Biometrical Journal, 59(4), 783-803.
Helwig, N. E. (in prep). Constrained parallel factor analysis via the R package multiway.
Kiers, H. A. L., ten Berge, J. M. F., & Bro, R. (1999). PARAFAC2-part I: A direct-fitting algorithm for the PARAFAC2 model. Journal of Chemometrics, 13, 275-294.
Missing data should be specified as NA values in the input X. The missing data are randomly initialized and then iteratively imputed as a part of the algorithm.
Structure constraints should be specified with a matrix of logicals (TRUE/FALSE), such that FALSE elements indicate a weight should be constrained to be zero. Default uses unstructured weights, i.e., a matrix of all TRUE values.
When using unimodal constraints, the *modes inputs can be used to specify the mode search range for each factor. These inputs should be matrices with dimension c(2,nfac) where the first row gives the minimum mode value and the second row gives the maximum mode value (with respect to the indicies of the corresponding weight matrix).
Output cflag gives convergence information: cflag = 0 if algorithm converged normally, cflag = 1 if maximum iteration limit was reached before convergence, and cflag = 2 if algorithm terminated abnormally due to a problem with the constraints.
Warnings
The algorithm can perform poorly if the number of factors nfac is set too large.
See Also
The fitted.parafac2 function creates the model-implied fitted values from a fit "parafac2" object.
The resign.parafac2 function can be used to resign factors from a fit "parafac2" object.
The rescale.parafac2 function can be used to rescale factors from a fit "parafac2" object.
The reorder.parafac2 function can be used to reorder factors from a fit "parafac2" object.
The cmls function (from CMLS package) is called as a part of the alternating least squares algorithm.