-
Notifications
You must be signed in to change notification settings - Fork 2
/
xresid.jl
30 lines (27 loc) · 875 Bytes
/
xresid.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
xresid(object, X; nlv = nothing)
xresid!(object, X::Matrix; nlv = nothing)
Residual matrix from a bilinear model (e.g. PCA).
* `object` : The fitted model.
* `X` : New X-data to be approximated from the model.
Must be in the same scale as the X-data used to fit
the model `object`, i.e. before centering
and eventual scaling.
Keyword arguments:
* `nlv` : Nb. components (PCs or LVs) to consider.
If `nothing`, it is the maximum nb. of components.
Compute the residual matrix:
* E = `X` - X_fit
where X_fit is the fitted X returned by function
`xfit`. See `xfit` for examples.
```
"""
function xresid(object, X; nlv = nothing)
xresid!(object, copy(ensure_mat(X)); nlv)
end
function xresid!(object, X::Matrix; nlv = nothing)
a = nco(object.T)
isnothing(nlv) ? nlv = a : nlv = min(nlv, a)
X .-= xfit(object, X; nlv)
X
end