I know how to do PCA but I am using formula's off a particular scientific paper and replicating them in MATLAB, and also having trouble understanding them. This is the paper. The notation I use is from the paper. My variables and matrix are different (they use 16x95, mine's only 8x10) but method is the same.
Here are the steps I'm following:
I have a 8x10 matrix. Each column is a variable $x_j$, 8 variables in total. Each row are the values from the trials, 10 trials in total. The mean and standard deviation of each variable are $\mu_j$ and $\sigma_j$. I understand this bit
$z_j$ are a set of standardized variables, defined by $z_j=(x_j-\mu_j)/\sigma_j$. This makes a matrix of the same dimensions. I understand this bit too
3.... don't worry about 3. in the paper it just explains something
Calculate the covariance matrix of the $z_j$ variables, ${C_i}_j$. This matrix is the covariance coefficient of each element to the other elements and is 8x8. I do this the easy way in MATLAB with cov() function I don't fully understand this but it's not the problem, I still understand what to do.
Calculate the 8 eigenvalue-eigenvector pairs. $\lambda_i , \mathbf e_i$ of the covariance matrix. Easy-peasy right, I just use eig() function in MATLAB which gives me two 8x8 matrices, one with 8 eigenvectors as the columns and one with 8 eigenvalues as the diagonal. But then the paper has this equation: "The eigenvectors can be expressed as: $\mathbf e_i = \sum_{j=1}^N \alpha_j^ix_j$ where $\alpha_j^i$ are "relative weights determined solely by the orthonormality constraint."
This is the part I don't understand. Firstly I don't understand what $\alpha_j^i$ is. It's defined by the term "relative weight." This leads me to believe it can be defined by finding the "weight" of each eigenvalue (and therefore eigenvector) wrt the other eigenvalues, or $\alpha_j^i=\lambda_i/\sum_{i=1}^N\lambda_i$, like finding the percentage but not multiplying by 100. Is that right? If so it means there will be 8 $\alpha_j^i$'s. Also, I know $\mathbf e_i$ from MATLAB (an 8x8 matrix) and I know $x_j$ from it being the original 8 non-standardized variables (in an 8x10 matrix). Can I calculate $\alpha_j^i$ by dividing the $\mathbf e_i$ matrix by the $x_j$ matrix? Will this make a whole new matrix of $\alpha_j^i$'s? And what about the fact the dimensions don't match, if I were to divide $\mathbf e_i$ and $x_j$ element-wise there would be two rows in $x_j$ unaccounted for? There's also a $\sum$ symbol in $\mathbf e_i = \sum_{j=1}^N \alpha_j^ix_j$. Does that mean I cumulatively sum $\alpha_j^i$ and $x_j$ to get $\mathbf e_i$? I'm not sure how I'd get the value(s) of $\alpha_j^i$ from the equation if that's the case. Just looking for help understanding that equation, specifically what $\alpha_j^i$ is, and if it's one value, 8 values in a vector, a whole matrix or whatever.
- Define a new set of variables $y_i$ from $y_i = (1/\lambda_i)\sum_{j=1}^N\alpha_jz_j$. not sure about this either as there are only 8 $\lambda_i$ but a whole 8x10 matrix of $z_j$. Also $\alpha_j$ doesn't have $_i$ superscript anymore and I'm not sure what that means. Again there is a $\sum$ in the equation. Do I have to add all the products of $z_j$ and $\alpha_j$ up or is it just an indexing thing?
Anyway there's more I don't understand but this question is big enough already. Eventually I'd calculate a single number called a normalcy index which describes how a new trial, with the same 8 variables, varies from the original 10. For this I'd use the $\alpha_j^i$ and $\lambda_i$ from those original 10 trials.
If your answer includs MATLAB code examples that's awesome but I appreciate any help at all. Also I don't have a license to use MATLAB code pca() in case you were going to suggest that.
Hope you can help
James