Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- JMP User Community
- :
- Discussions
- :
- Unable to save a variable number Eigenvector tables to a single data table after...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

May 17, 2020 8:37 AM
(387 views)

Hello,

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 ),
SendToReport(
Dispatch(
{"Summary Plots"},
"PCA Summary Plots",
FrameBox,
{Row Legend(
test_article,
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

Sebastien

- Tags:
- eigenvectors
- pca

2 REPLIES 2

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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?

```
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
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).

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

Sebastien

Article Labels

There are no labels assigned to this post.