Hi All,
I am trying to get some JSL code working to save T² from the Principal Component platform, like how you can do it by calling <<Save DModX(n), where n is the number of PCs to use.
I know that the call << Save T Square will work with multivariate control chart, but it doesn't seem to work with the PCA or Multivariate platforms. I need to use the PCA platform to generate the T² formula because in the PCA platform, you can actually specify the number of PCs to use in the calculation, it's not the normal T² statistic, like the Mahalanobis distance squared. Even the call << T²(1, Save T Square) sent to the report window doesn't work.
1. Is it possible to use scripts to specify the number of PCs to use and save the T² formula to the data table? So far, I have not found an option for this.
2. If not, how to best calculate it? I know the calculation is defined here, but the formula that's saved to data table using the red hot-button seems a bit different.
According to the saved formula (manual save) T² = Vec Quadratic(S, X)= Diag(X*S*X`), where X is the standardized vector of data, X` is its transpose, and S is the inverse covariance matrix. This is the standard T², the square of the Mahalanobis distance.
However, according to the documentation for the ith T² value from the PCA platform, T_i² = [X_ci*P_a]*L-1*[P`_a*X`_ci], where X_ci is the ith standardized observation, P_a is a matrix containing the first "a" eigenvalues (i.e. possibly not all of them), and L-1 is a diagonal matrix containing the first A eigenvalues. In principle, this should be equal to Vec Quadratic(L-1, [X_ci*P_a]), except instead of using the inverse covariance matrix, S, it's using the inverse axa eigenvalue matrix of the first "a" PCs, and X is now X_ci*P_a]. Or so, it would appear.
It seems rather complicated and unnecessary to re-engineer this problem in order to save the n-principal component T² when JMP already calculates all this for you. I just want to automate the saving process, but I can't seem to get option 1 to work, which means option 2 is the next best bet. Even then, trying to recover the formula in order to make a New Column with a formula in it seems a bit much.
I'm attaching a modified data table of the Iris.jmp file that shows the saved T² formulas from the multivariate platform (and how T² = Mahal.Dist.²), and then T² from the PCA platform where the formula is determined using all 4 PCs and then only to PCs. As you can see by looking at the formulas, the S matrix in the Vec Quadratic(S,X) is different for the T²s calculated using 2 PCs vs 4 PCs.
If anyone has insight into how to script getting the T² with a different number of PCs or how to properly formulate the column formula to calculate the T², I would be grateful for that insight.
Thanks for your feedback and thoughts!,
DS