
by
Rasmus Bro & Claus A. Andersson
The N-way toolbox provides means for
Fitting multi-way PARAFAC models
Fitting three-way PARAFAC2 models
Fitting multi-way PLS regression models
Fitting multi-way Tucker models
Fitting the generalized rank annihilation method
Fitting the direct trilinear decomposition
Fitting models subject to constraints on the parameters such as e.g. nonnegativity, unimodality, orthogonality
Fitting models with missing values (using expectation maximization)
Fitting models with a weighted least squares loss function (including MILES)
Predicting scores for new samples using a given model
Predicting the dependent variable(s) of PLS models
Performing multi-way scaling and centering
Performing cross-validation of models
Calculating core consistency of PARAFAC models
Using additional diagnostic tools to evaluate the appropriate number of components
Perform rotations of core and models in Tucker models
Plus additional utility functions
In addition to the N-way toolbox, you can find a number of other multi-way tools on this site including PARAFAC2, Slicing (for exponential data such as low-res NMR), GEMANOVA for generalized multiplicative ANOVA, MILES for maximum likelihood fitting, conload for congruence and correlation loadings, eemscat for scatter handling of EEM data, clustering for multi-way clustering, CuBatch for batch data analysis, indafac for PARAFAC, PARALIND for constrained PARAFAC models, jackknifing for PARAFAC.
The N-way toolbox for MATLAB is freely available
Read the information on this page and download the files to your own computer. If you use the N-way toolbox for MATLAB we would appreciate a reference to the toolbox. This may for example be
C. A. Andersson and R. Bro
The N-way Toolbox for MATLAB
Chemometrics & Intelligent Laboratory Systems. 52 (1):1-4, 2000.
You can download a PDF-file of the paper here.
If you have any questions, suggestions or comments please feel free to mail us.
Download the N-way Toolbox
The N-way Toolbox for MATLAB (most recent version 3.60, Sept 2026)
Find the answer to common questions here
Question:
Is there a manual or tutorial for the N-way Toolbox?
Answer:
There is an on-line course on how to use the toolbox
Question:
When I fit the parafac model I get an error:
» [factors]=parafac(X,DimX,2);
??? Error using ==> gram
Too many input arguments.
Error in ==> C:\MATLABR11\toolbox\nway\dtld.m
On line 151 ==> [Bg,Cg,Ag]=gram(reshape(Gt(1,:),f,f),reshape(Gt(2,:),f,f),F);
Error in ==> C:\MATLABR11\toolbox\nway\parafac.m
On line 473 ==> [A,B,C]=dtld(X,DimX,Fac);
Answer:
You may have the PLS_toolbox as well. In that, there is also a function called GRAM. In order to avoid this error, you have to make sure that PARAFAC calls the N-way toolbox version of gram rather than the PLS_toolbox version of GRAM. One way of doing this, is to use pathtool.m for rearranging the order in which the directories are searched. Simply drag the path to the N-way toolbox so that it appears higher in the list than the PLS_toolbox does.
Question:
Centering and scaling of data is a bit strange. To center and scale column-wise I need to use “mode 1” for centering and “mode 2” for scaling.
Answer:
Yes, it seems like a strange convention, but it actually makes sense when one considers the way that higher-order arrays have to be preprocessed. The thing is that centering and scaling are applied in two completely different ways, but just happen to seem alike for two-way analysis. We are so used to two-way analysis, that it is very difficult to re-think the whole issue. Centering is performed across a mode (hence from one vector, the average of that vector is subtracted), whereas scaling is performed within a mode (all elements in one slab are multiplied by the same number). OK: it is not simple, but check this theoretical paper on centering and scaling.
Question:
When I type
>[Factors]=parafac(X,Fac,Options(3)=1)
I get an error message
Answer:
You can not use inputs like that in MATLAB. You have to input the vector Options directly. You can for example write
>Options(3) = 1
This will put zeros in Options(1:2) and the toolbox will then use defaults. Then you do
>[Factors]=parafac(X,Fac,Options)
Question: Regression coefficients
I have used your toolbox to compute a N-PLS model relating a three-way array X to a Y-vector. I have seen that the B coefficients are the regression coefficients relating the scores in the Y-space to scores in the X-space (inner relation). I would like to obtain the regression coefficients of the closed form of the N-PLS model, i.e. an array of coefficients relating X to Y directly (or relating slabs of X to Y). Could you please tell me how to obtain these regression coefficients in N-PLS modelling?
Answer
The regression coefficients are possible to obtain directly from the NPLS algorithm:
[Xfactors,Yfactors,Core,B,ypred,ssx,ssy,reg] = npls(X,y,Fac);
The parameter reg is the set of regression coefficients.