3- PARAFAC
A PARAFAC model is an n-linear model fitted on an n-way array. It is a decomposition method and do not require particular preliminary steps.

Several applications exist in the literature for this model, which can be used both as a curve resolution method as well as a regression method (the latter has not been implemented in this software yet).
For more information check the scientific overview, here.

Compute a PARAFAC model, an example

- Load the desired data set (e.g. Fluorescence). The Y is not necessary as regression is currently not available for PARAFAC.

- Select the menu 'Factor Analysis' -> 'PARAFAC'.
  The following window appears:

- Insert the desired number of factors in the marked field.
  With the Fluorescence data set the correct rank is known and it is equal to 4 (i.e. the chemical rank).
  Remember to press 'Enter' after having typed the new value or the selection will not be effective.
  NB. If, like in the above figure, two numbers are specified in the "N. of factor" field, the first number is the minimum number of extracted components, whereas the second represents the maximum. In other words, if one specifies '1,4', the models with 1, 2, 3 and 4 components will be calculated.

- The 'Preferences' -> 'Algorithm' menu can be used to choose which algorithm shall be used for the calculations (dGN/ALS, using/not using compression) and to have access to some of the options for fitting the model.
  Select 'Preferences' -> 'Algorithm' -> 'Options'; a new window is opened.
  NB the 'Preferences' -> 'Bootstrap' menu is activated only if the bootstrap validation is selected.

- The new window allows to specify the initialisation method (select 'swatld'), the convergence criteria (10-5 is enough in this case) and the maximum number of iterations (2000 is fine for this problem).
  For the moment, the 'advanced' options can be skipped.
  NB. The parameter's update and the gradient criteria are available only for the dGN algorithm.
  Furthermore, the 'Refining' option is active only when compression is used.

- Press on 'OK' to accept the modifications. The 'Options' figure will be closed and the program returns to the "PARAFAC Model" window. If the window is closed without clicking on 'OK', the changes are not saved.

- No preprocessing is necessary for the Fluorescence data set, so this part can be skipped.

- It is reasonable for spectral data to impose non-negativity in the spectral as well as in the sample modes (being ideally connected to a concentration a negative score is not reasonable, unless an offset is present).
  To set such constraints, press on the button 'Set constraints'. Choose non-negativity for all the modes in the new window (as shown in the figure) that opens and press 'OK'.

- Now CuBatch is ready to compute a 4 components PARAFAC model on the data with non-negativity constraints on all the modes. Press then 'Start'.

- A waitbar appears (note that the increase is given in terms of models and that here only one model is computed; thus, only one step is taken in the waitbar).
  After a few seconds, the waitbar and the "PARAFAC Model" window disappear and only the main CuBatch window remains.
  Note that both the 'Use model' and the 'Results' menus are now active.
  In the InfoBox are now visible some information on the computed PARAFAC model.
  Additional informations are displayed by clicking on the "Click her for more" right under the Model section.

Compute and full cross-validate a PARAFAC model

- To activate full-cross validation, check on the Validate button (marked in red) in the "PARAFAC Model" window; the validation options will be activated.
  NB Unless a test set was selected, the 'Test set' validation check-box is non active.

- Check the 'Leave one out' (marked in green) option, if not checked.

- Press 'Start'. A waitbar appears shows the increments (one increment = one model)

- After 1 or 2 minutes the waitbar disappears and the PARAFAC Model window is closed; only the main CuBatch window remains open
  In the InfoBox are now visible, beside those relative to the PARAFAC model, some information on the validation.
  The 'Results' menu is active, but its content is slightly different compared to when the model is only fit.
  The leave one out validation allows in fact for additional diagnostic tools such as IMP, RIP and Risk Plot (the latter available only when more than one model is computer.

Display results

Apply to a new set of data

Applying the model to new data is relatively simple and straightforward:

1. Click on the Use Model -> Projection menu
2. If more than one model is present the rank to be used is asked in a requester.
   As the subsequent warning says
   the choice affects the models present in memory: only the selected one is kept, the others are lost. Before proceeding, it may be a good idea to make sure that the results so far are saved (unless otherwise decided).
   In case the model is to be used later in the 'plant' mode this step is necessary, as only one model shall be present in such operational mode.
3. Select the file with the external set (in case if have none, you can create one by exporting one or two samples from the fluorescence data set).
4. After a few seconds a the calculations are completed and the explained variation plot appears.
   The InfoBox shows some basic information on the new data and on the applied model:
5. At this point the plots are available for the new set of data. See Display results

Some additional notes for on-line applications

It is possible to apply PARAFAC for batch process monitoring: in such case it is possible that the imported sample is not complete (that is to say: the last mode dimension is smaller than for the calibration/NOC data set). The user is then asked (only in the 'advanced' mode, the 'plant' user is not given access to this option) which fill-in mode is desired. 'Current variation' is the default.
After the computations are over the InfoBox shows also the fill-in method employed for this external set.
This option is not available unless the last mode is given name 'time' (case insensitive)

Bootstrap options
In case one wants to employ bootstrapping, after having checked the Validation button, the 'Bootstrap' check-box needs be selected.

The 'Preferences' -> 'Bootstrap' menu will then be active (in yellow) and on the "PARAFAC Model" window a new object asking for the number of bootstrap replicates appears (marked in red).

Two types of bootstrap are implemented, the naïve bootstrap and the residual bootstrap (see the literature for more details on the methods).

The 'Start' button does not become active until the number of replicates is defined.

After the model has been computed and validated the 'Results' menu is updated:
IMP and RIP are not available anymore while the Risk function can still be displayed.

Preprocessing
To preprocess the data click on the 'Preprocessing' button. The following window will appear:
Three types of scaling are available: using the Standard Deviation, using the Root Mean Squared value or using the Frobenius norm.
Note that the preprocessing is handled according to the nprocess function. For details on preprocessing of multiway array check the literature. In brief, remember that the centring is made 'across' the specified mode while the scaling is done 'within' a certain mode.
NB using nprocess it is not possible to achieve columnwise autoscale as the scaling is performed slabwise.

Advanced options
With the sole exception of the maximum number of iterations in initialisation (for iterative methods), the advanced options are available only when compression and/or dGN algorithm are used. For the meaning of the different options check PARAFACOptions and the literature. The same links can be followed for more specific informations on the standard options.