# Datahat

## Contents

### Purpose

Calculates the model estimate and residuals of the data.

### Synopsis

- xhat = datahat(model);
- [xhat,resids] = datahat(model,
*data*); - [xhat,resids] = datahat(loadings,
*data*);

### Description

Given a standard model structure (model), DATAHAT computes the model estimate of the data (xhat). For example, if (model) is a PCA model of a matrix:

**X**_{cal}such that**X**_{cal}=**TP**^{T}+**E**, then**X**_{hat}=**TP**^{T}

that is:

**X**_{cal}=**TP**^{T}+**E**=**X**_{hat}+**E**.

If optional input (*data*) is supplied then DATAHAT computes the model estimate of (*data*) which will be output in (xhat). For the PCA model of matrix **X**_{cal}, and (*data*) is a data matrix **X**_{new} then:

**X**_{hat}=**X**_{new}**PP**^{T}=**T**_{new}**P**^{T}

and the output (resids) is a matrix with the corresponding residuals:

**E**=**X**_{new}-**X**_{new}**PP**^{T}=**X**_{new}(**I**-**PP**^{T})

If (*data*) is **X**_{cal} then:

**X**_{hat}=**TP**^{T}

and resids is:

**E**=**X**_{cal}(**I**-**PP**^{T}).

Note that preprocessing in (model) will be performed before the residuals are calculated. If data is not provided, only (xhat) of the calibration data is available.

Note that DATAHAT works with almost all standard model structures or a cell-array of loadings can be supplied in place of model (for use with multiway models only).

### See Also

analysis, npls, parafac, parafac2, qconcalc, residuallimit, tconcalc, tsqmtx, tsqqmtx, tucker, varcap, varcapy