Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Level III

Unable to save a variable number Eigenvector tables to a single data table after a PCA analysis



I've been trying to put together a script to run a PCA analysis and save the resulting eigenvectors.

The PCA include a 'by' which results in several independent PCA analysis. The number of which depends on the number of categories in the column (specimen_material_type) used to populate 'by' option

The script works great with one major exception: Only the eigenvectors table from the first category get saved to a data table despite using the "make combined data table" function.  


I would like to tweak the script so that it can accommodate any number of categories provided by the 'by: specimen_material-type' as it will vary from analysis.


dt = Data Table( "split by symbol" );
colList = dt << Get Column Names( numeric );
obj = dt << Principal Components(
	Y( Eval( colList ) ),
	Estimation Method( "Wide" ),
	"on Correlations",
	by( :specimen_material_type ),
	Summary Plots( Label variables( 0 ) ),
	Eigenvectors( 1 ),
	Arrow Lines( 0 ),
			{"Summary Plots"},
			"PCA Summary Plots",
			{Row Legend(
				Color( 1 ),
				Color Theme( "JMP Default" ),
				Marker( 0 ),
				Marker Theme( "" ),
				Continuous Scale( 0 ),
				Reverse Scale( 0 ),
				Excluded Rows( 0 )
obj << Save Principal Components( 3 );
Report( obj[1] )[Outline Box( "Eigenvectors" )][Table Box( 1 )] << Make Combined Data Table;

Any suggestions would be greatly appreciated.


Thanks a lot




Re: Unable to save a variable number Eigenvector tables to a single data table after a PCA analysis

Looks like you are very close. Does the code below work for you?


dt = Open("$SAMPLE_DATA/Big");

pca = dt << Principal Components(Y( :height, :weight ), Eigenvectors( 1 ), By(:sex));
dtev = Report(pca[1])[OutlineBox("Eigenvectors")][TableBox(1)] << makeCombinedDataTable;
dtev << setName("Eigenvexctors with By Group");

As you know already 'MakeCombinedDataTable' shouldn't care about the number of levels in the 'By' group (in the case above, just two).

Level III

Re: Unable to save a variable number Eigenvector tables to a single data table after a PCA analysis

Hi Ian,


Thanks a lot for the guidance. Your code works well but for some reason if only works with a small number variables assigned to Y. If I increase the number of variables, at some point it becomes incapable of grouping the various Eigenvectors tables.

I suspect the reason might be  that for the number of eigen vectors reported for each 'By' categories varies slightly when I start increasing the number of variable with  65 vs 64 vectors ( I have only 2 category in my proof of concept table). As progressively decrease the number of variable, there is a point where the number of vectors becomes the same at which point, the eigenvector tables becomes combined as expected.


Is there a way to control the number of vectors that are being reported? I don't need to report all the eigen vectors, just up to 3 or 4.  


Alternatively, finding a way to save each eigenvector table separately and concatenating them afterward would also work. However, I'm not sure how to loop through each 'By' categories as they will vary in name and number. 


Any suggestions would be appreciated.



Article Labels

    There are no labels assigned to this post.