The function above doesn't work correct! When you predict you should scale using the original data, not the data you're tring to predict ('new.data' in your case).
One simple example. Let assume that you want to get prediction for just one observation (i.e. one row). What would be the prediction?
> scale(matrix(1:4, nrow = 1), scale = FALSE)
[,1] [,2] [,3] [,4]
[1,] 0 0 0 0
So, the function returns zeros..
One way to fix the problem:
predict.ica = function(new.data, ica.model) {
new.data <- scale(as.matrix(new.data), center = ica.model$center, scale = FALSE)
Q = ica.model$Q
Y = tcrossprod(new.data, Q)
Y %*% ica.model$R
}
ica.model = icafast(data, nc=10)
ica.model$center = colMeans(data)
predict.ica(new.data, ica.model)
A covariance matrix has ${n \choose 2} + n = \frac{n(n+1)}{2}$ free elements. The constraints for the spectral decomposition are:
- The eigenvalues are positive
- The eigenvectors are orthogonal
- The eigenvectors are unit length.
I recently asked a question that had to do with this. @amoeba had a good comment that helped visualize these constraints and proved why the number of free elements in $\Psi$ was ${n \choose 2}$, and the number of free elements in $\Lambda^2$ was $n$.
Regarding the ordering of the eigenvalues, that may or may not be important to you. The spectral decomposition is only unique up to re-orderings of your $\Lambda^2$ diagonal matrix. If your task is to estimate the parameters of this matrix, each of these re-orderings will have corresponding estimates. In this case the model will not be identifiable.
However, if you are just theorizing about the covariance matrix, people sometimes just restrict their attention to one ordering of the eigenvalues, without losing any generality. Proving something is true for one ordering will usually guarantee truth for the other orderings.
Edit to address comment:
1,2 and 3 are constraints that every covariance matrix has, so it is as "free" as possible. Sampling from some distribution of $\Sigma$ is possible as long as long as the distribution exists, but it is also common to restrict the columns of $\Psi$ further, which is the same as fixing the ordering of your eigenvalues. What I mean is that sometimes they will restrict it to have $\psi_{i,j} = 0$ when $j > i$ and $\psi_{j,j} = 1$. In other words, it will be lower-diagonal with $1$s on the diagonal. The are other ways to restrict this space, but it would look something like this:
$$
\Psi =
\left[\begin{array}{cccc}
1 & 0 & 0 & 0 \\
\psi_{2,1} & 1 & 0 & 0 \\
\vdots & \vdots & \ddots & \vdots \\
\psi_{p,1} & \psi_{p,2} & \cdots & 1 \\
\vdots & \vdots & \ddots & \vdots \\
\psi_{n,1} & \cdots & \psi_{n,p-1} & \psi_{n,p}
\end{array} \right].
$$
Why is this representation unique? If you re-order the diagonal matrix $\Lambda^2$, then you have to re-order the columns of $\Psi$, but then the columns of $\Psi$ won't follow this pattern. Why do this? Well now your posterior is not multi-modal.
Best Answer
The covariance between an observation at time $t_i$ and time $t_j$ is $$ \frac{\sigma^2}{1-\phi^2}\phi^{|t_i-t_j|} $$ If the
delta
's are time gaps between the time points $t_1,t_2,\dots,t_5$, then each $t_i$ are given by cumulative sums of thedelta
's. In R do