cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
mjz5448
Level III

How do I perform a 2-sample Hotelling's T-square test in JMP?

I'm trying to compare multiple different product specs or variables (k = between 2 different groups. I can't find a way to compare those multiple factors between the 2 groups easily in JMP right now using the 2-sample Hotelling's T-square test. I'd also like to know if JMP can then create the CIs if we reject the Hotelling's T2 test statistic and also review the profile plots? 

7 REPLIES 7
txnelson
Super User

Re: How do I perform a 2-sample Hotelling's T-square test in JMP?

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.

txnelson_0-1697086322772.png

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
mjz5448
Level III

Re: How do I perform a 2-sample Hotelling's T-square test in JMP?

Thank you for the response. I didn't think to try finding a solution using SAS.  Now that I think about it I may have SAS code for doing a multivariate comparison between 2 groups that may also work. That said, I was hoping someone knew if: analyze > fit model menu > Manova , could work multivariate comparison of just 2 groups instead of multiple ones? 

Blaedel
Level I

Re: How do I perform a 2-sample Hotelling's T-square test in JMP?

Dear Jim

 

Could I persuade you to post the SAS code as well? That would be most helpful.

 

Thanks

txnelson
Super User

Re: How do I perform a 2-sample Hotelling's T-square test in JMP?

Here is a link to a SAS example.  I believe this is the example I used, but I am not sure.

7.1.15 - The Two-Sample Hotelling's T-Square Test Statistic | STAT 505 (psu.edu)

Jim

Re: How do I perform a 2-sample Hotelling's T-square test in JMP?

From JMP Help:

tsqr.PNG

mjz5448
Level III

Re: How do I perform a 2-sample Hotelling's T-square test in JMP?

Thanks Mark. I saw that 1-sample T2 test option under the multivariate menu, but couldn't find anything for a 2-sample test - which is what I'm looking for to compare product specs between 2 groups. I think I may playing around w/ the MANOVA option but use 2 groups instead of the 3+ groups it usually calls for & see if I can get the correct outputs. 

mjz5448
Level III

Re: How do I perform a 2-sample Hotelling's T-square test in JMP?

For those that are interested - I THINK (someone may need to verify) you can use the MANOVA option to perform a 2-sample Hotelling's T2 analysis as follows: 

  • Analyze > Fit Model > select all of your response variables you are trying compare between your 2 groups & move them to "Y", select the column containing your labels for your 2 groups select "Add" under 'Construct Model Effects' > select "Manova" from the 'Personality' dropdown menu > Run > under 'Choose Response' menu, select "Identity" > Run. 
  • This should output your F-value and probability for your test. 
  • I'm not sure how to do the simultaneous or Bonferroni adjusted intervals from here. 

Recommended Articles