I found some SAS code on the internet that performed the 2 Sample Hotelling T2 calculation. I converted the code to JSL. I tested it against some sample data and it checked out ok. It is a bit clunking but it works. Take a look at the annotation in the JSL to see what needs to be set to work with your data.
Names Default To Here( 1 );
// Open the data table
dt = open("$SAMPLE_DATA/Prostate Cancer.jmp");
groupVar = "Status"; // Enter the grouping column name
groupList = {"CCD", "Nor"}; // Set the values for the 2 groups
startColumn = 660; // Set the starting column number for the data to be included
// Create the group 1 and group 2 matrices for analysis
gp1Rows = dt << get rows where( as column( groupVar) == groupList[1] );
group1 = dt[gp1Rows, startColumn :: N Cols( dt )];
gp1Rows = dt << get rows where( as column( groupVar ) == groupList[2] );
group2 = dt[gp1Rows, startColumn :: N Cols( dt )];
// Get the dimensions of the matricies
nRows1 = N Row( group1 );
nRows2 = N Row( group2 );
numCols = N Col( group1 );
// Create a filled vector for the analysis
j1 = J( nRows1, 1, 1 );
j2 = J( nRows2, 1, 1 );
// Create an identity matrix for each group
identity1 = Identity( nRows1 );
identity2 = Identity( nRows2 );
// Calculate the means for each of the columns by each group
MeanY1 = group1` * j1 / nRows1;
MeanY2 = group2` * j2 / nRows2;
// Create an output window to display the results in
nw = New Window("Hotelling T2", outlinebox("Hotelling 2 Sample T2 Analysis",spacerbox(size(1,15)),lub = vlistbox()));
// Add the means table to the output
obMean = Outline Box("Group Means",
mTB = Table Box(
string Col box("Groups", groupList),
number col box("# Rows", matrix(nRows1)||matrix(nRows2))
)
);
for(i=startColumn, i<=NCols(dt),i++,
mTB << append(number col box(column(dt,i)<<get name, MeanY1[i-startColumn+1] || MeanY2[i-startColumn+1]))
);
lub<<append(obMean);
lub<<append(spacerbox(size(1,15)));
// Create the Sample Variance-Covariance matrix for group 1
sampVarCovarGp1 = group1` * (identity1 - j1 * j1` / nRows1) * group1 / (nRows1 - 1.0);
// Add the matrix to the output window
obSVCG1 = Outline Box("Sample Variance-Covariance for Group = " || groupList[1],
SVCG1 = TableBox()
);
for(i=1,i<=ncols(sampVarCovarGp1),i++,
SVCG1 << append(numbercolbox("", sampVarCovarGp1[0,i]))
);
lub<<append(obsvcg1);
lub<<append(spacerbox(size(1,15)));
obSVCG1 << close;
// Create the Sample Variance-Covariance matrix for group 2
sampVarCovarGp2 = group2` * (identity2 - j2 * j2` / nRows2) * group2 / (nRows2 - 1.0);
// Add the matrix to the output window
obSVCG2 = Outline Box("Sample Variance-Covariance for Group = " || groupList[2],
SVCG2 = TableBox()
);
for(i=1,i<=ncols(sampVarCovarGp2),i++,
SVCG2 << append(numbercolbox("", sampVarCovarGp2[0,i]))
);
lub<<append(obsvcg2);
lub<<append(spacerbox(size(1,15)));
obSVCG2 << close;
// Create the Pooled Sample Variance-Covariance matrix
sampPool = ((nRows1 - 1.0) * sampVarCovarGp1 + (nRows2 - 1.0) * sampVarCovarGp2) / (nRows1 + nRows2 - 2.0);
// Add the matrix to the output window
obSampPool = Outline Box("Pooled Variance-Covariance Matrix",
sampPooltb = TableBox()
);
for(i=1,i<=ncols(sampPool),i++,
sampPooltb << append(numbercolbox("", sampPool[0,i]))
);
lub<<append(obSampPool);
lub<<append(spacerbox(size(1,15)));
obSampPool << close;
// Calculate the result statistics
t2 = (MeanY1 - MeanY2)` * Inv( sampPool * (1 / nRows1 + 1 / nRows2) ) * (MeanY1 - MeanY2);
f = (nRows1 + nRows2 - numCols - 1) * t2 / numCols / (nRows1 + nRows2 - 2);
degFreedomGp1 = numCols;
degFreedomGp2 = nRows1 + nRows2 - numCols - 1;
pValue = 1 - F Distribution( f, degFreedomGp1, degFreedomGp2 );
// Add the results to the display window
obFinal = Outline Box("Results",
tablebox(
stringcolbox("Group", groupList),
numbercolbox("DF", matrix(degFreedomGp1)||matrix(degFreedomGp2)),
numbercolbox("T2", matrix(t2)),
numbercolbox("F", matrix(f)),
pv=numbercolbox("pValue",matrix(pValue))
)
);
pv<<set format("pvalue");
lub<<append(obFinal);
Jim