Cluster Variables
Example 1
Summary: Opens a data table, defines cluster variables for clustering analysis, and sends the results to a report with standardized components.
Code:
// Cluster Variables
// Open data table
dt = Open("data_table.jmp");
// Cluster Variables
Cluster Variables(
Y(
:Al, :Mn, :Na, :Br, :Ce, :Co, :Cr,
:Cs, :Eu, :Fe, :Hf, :La, :Sc, :Sm,
:U
),
SendToReport(
Dispatch( {},
"Standardized Components",
OutlineBox,
{Close( 1 )}
)
)
);
Code Explanation:
- Open table.
- Define variables for clustering.
- Perform cluster analysis.
- Close standardized components report.
Example 2
Summary: Opens a data table and clusters selected variables, enabling interactive analysis of the relationships between Age, BMI, BP, Total Cholesterol, LDL, HDL, TCH, LTG, and Glucose.
Code:
// Cluster Variables
// Open data table
dt = Open("data_table.jmp");
// Cluster Variables
Cluster Variables(
Y(
:Age, :BMI, :BP,
:Total Cholesterol, :LDL, :HDL,
:TCH, :LTG, :Glucose
)
);
Code Explanation:
- Open data table;
- Cluster selected variables.
Example 3
Summary: Runs the clustering of chemical elements in a data table, disabling summary and component displays.
Code:
Open("data_table.jmp") << Cluster Variables(
Y( :Al, :Mn, :Na, :Br, :Ce, :Co, :Cr, :Cs, :Eu, :Fe, :Hf, :La, :Sc, :Sm, :U ),
Cluster Summary( 0 ),
Cluster Members( 0 ),
Cluster Components( 0 )
);
Code Explanation:
- Open data table;
- Start clustering variables.
- Select chemical elements for analysis.
- Disable cluster summary display.
- Disable cluster members display.
- Disable cluster components display.
Example 4
Summary: Runs the computation of sparse singular value decomposition (SVD) and residual matrix calculation, utilizing a custom function jslSVDTest.
Code:
Open("data_table.jmp");
obj = Cluster Variables( Y( :X1, :Y1, :X2, :Y2, :X3, :Y3, :X4, :Y4 ) );
Random Reset( 123456789 );
A = J( 5, 10, Random Integer( 0, 1 ) );
{U, S, V} = Sparse SVD( A, 5 );
Z = U * Diag( S ) * V` - A;
traceTrick = Trace( Z` * Z );
A = [1 1 0 0 0 0 0 0 0 0 0,
0 1 0 0 0 0 0 0 0 0 1,
0 0 1 0 1 0 0 0 0 0 0,
0 0 1 1 1 0 0 0 0 0 0,
1 0 0 0 0 1 0 0 0 0 0,
0 0 0 1 0 0 0 0 0 1 0,
1 0 0 0 0 0 1 0 0 0 0,
0 0 0 0 0 0 0 0 1 0 0,
0 0 0 0 0 1 0 1 0 0 0];
Asm = A[0, 1 :: 7];
jslSVDTest = Function( {thematrix, numSV},
{A, Ut, St, Vt, U, S, V, GHvsSparse},
thematrix = V Standardize( thematrix );
{Ut, St, Vt} = SVD( thematrix );
{U, S, V} = Sparse SVD( thematrix, numSV );
GHvsSparse = (St || (S |/ J( N Row( St ) - N Row( S ), 1, 0 )));
);
Code Explanation:
- Open data table;
- Perform cluster analysis.
- Set random seed.
- Create random matrix A.
- Compute sparse SVD of A.
- Calculate residual matrix Z.
- Compute trace of Z transpose times Z.
- Define matrix A.
- Extract submatrix Asm.
- Define function jslSVDTest.
Example 5
Summary: Analyze clustered variables by opening a data table and performing a cluster variables calculation, sending the results to a report.
Code:
Open("data_table.jmp");
obj = Cluster Variables( Y( :X1, :Y1, :X2, :Y2, :X3, :Y3, :X4, :Y4 ) );
Code Explanation:
- Open data table;
- Cluster variables analysis.
Example 6
Summary: Generates a cluster summary report from a data table, extracting key statistics and converting them to a matrix format.
Code:
dt = Open("data_table.jmp");
obj = Cluster Variables( Y( :BMI, :BP, :Total Cholesterol, :LDL, :HDL, :TCH, :LTG ) );
rpt = obj << report;
actSummary = rpt["Cluster Summary"][Table Box( 1 )] << get as matrix;
Code Explanation:
- Open data table;
- Create cluster variables object.
- Retrieve report from object.
- Extract cluster summary table.
- Convert table to matrix.
Cluster Variables using Data Table
Summary: Selects and filters data rows in a JMP Data Table, followed by cluster analysis with specific variables and conditions.
Code:
Open("data_table.jmp");
dt = Data Table("data_table");
dt << Clear Select << Select Rows( Index( 1, 35 ) ) << Hide and Exclude;
dt << Cluster Variables(
Y( :age, :height, :weight ),
Cluster Summary( 0 ),
Cluster Members( 0 ),
Cluster Components( 0 ),
Local Data Filter( Add Filter( columns( :height ), Where( :height >= 68 ) ) )
);
Code Explanation:
- Open data table;
- Assign data table to dt.
- Clear previous selections.
- Select rows 1 to 35.
- Hide and exclude selected rows.
- Perform cluster analysis.
- Set variables for clustering.
- Disable cluster summary.
- Disable cluster members.
- Disable cluster components.
- Add local data filter.
- Filter height column.
- Set filter condition: height >= 68.
Cluster Variables using Principal Components
Example 1
Summary: Runs a Principal Components analysis on the Iris dataset, filtering for setosa species and visualizing results in 3D Score Plot, Biplot, and Loading Plot.
Code:
dt = Open("data_table.jmp");
obj_cust = dt << Principal Components(
SendToByGroup( {:Species == "setosa"} ),
Y( :Sepal length, :Sepal width, :Petal length, :Petal width )
);
obj_cust << "3D Score Plot"n( 1 );
obj_cust << Arrow Lines( 0 );
obj_cust << Arrow Lines( 1 );
obj_cust << Bartlett Test( 1 );
obj_cust << Biplot( 3 );
obj_cust << Cluster Variables( Cluster Components( 1 ) );
obj_cust << Factor Analysis( "ML", "SMC", 2, "Varimax" );
obj_cust << Loading Plot( 4 );
obj_cust << Score Ellipses( 1 );
obj_cust << Score Ellipse Coverage( 0.75 );
obj_cust << Squared Cosines of Variables( Plot of Squared Cosines of Variables( Overview( 3 ), "Stacked", "Horizontal" ) );
obj = dt << Principal Components( SendToByGroup( {:Species == "setosa"} ), Y( :Sepal length, :Sepal width, :Petal length, :Petal width ) );
obj << Empty();
preset = obj_cust << New Preset;
obj << Apply Preset( preset );
Code Explanation:
- Open data table;
- Run Principal Components analysis.
- Filter for Species setosa.
- Select variables for analysis.
- Create 3D Score Plot.
- Disable Arrow Lines.
- Enable Arrow Lines.
- Perform Bartlett Test.
- Create Biplot.
- Cluster variables.
- Conduct Factor Analysis.
- Generate Loading Plot.
- Enable Score Ellipses.
- Set ellipse coverage to 0.75.
- Plot Squared Cosines of Variables.
- Run another Principal Components analysis.
- Clear previous results.
- Save analysis preset.
- Apply saved preset.
Example 2
Summary: Runs Principal Components analysis on a standardized data table, clustering variables using method 1.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :Sepal length, :Sepal width, :Petal length, :Petal width, :Species ), Standardize( "Standardized" ), );
obj << Cluster Variables( 1 );
Code Explanation:
- Open data table;
- Run Principal Components analysis.
- Standardize variables.
- Cluster variables using method 1.
Cluster Variables using Get Column Groups Names
Example 1
Summary: Runs cluster analysis on a data table, saving the resulting components and updating column groups.
Code:
dt = Open("data_table.jmp");
colGp1 = dt << Get Column Groups Names();
obj = dt << Cluster Variables( Y( 1 :: 5 ) );
obj << Save Cluster Components();
colGp2 = dt << Get Column Groups Names();
Code Explanation:
- Open data_table data
- Retrieve initial column groups.
- Perform cluster analysis on first five columns.
- Save cluster components.
- Retrieve updated column groups.
Example 2
Summary: Performs principal component analysis with variable clustering to generate a report, updating column groups accordingly.
Code:
dt = Open("data_table.jmp");
colGp1 = dt << Get Column Groups Names();
obj = dt << Principal Components( Y( 1 :: 5 ), Estimation Method( "Default" ), "on Correlations", Cluster Variables( 1 ) );
rpt = obj << Report();
scrobj = rpt[Outline Box( "Variable Clustering" )] << Get Scriptable Object();
scrobj << Save Cluster Components();
colGp2 = dt << Get Column Groups Names();
Code Explanation:
- Open data table;
- Retrieve initial column groups.
- Perform principal component analysis.
- Use correlations for estimation.
- Enable variable clustering.
- Generate report object.
- Access variable clustering outline.
- Get scriptable object for clustering.
- Save cluster components.
- Retrieve updated column groups.
Cluster Variables using If
Summary: Runs Principal Component analysis with REML variance estimation and local data filtering to analyze athletic performance data, generating a report with summary plots.
Code:
If( Contains( JMP Product Name(), "Pro" ),
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Y( :"100m"n, :Long Jump, :Shot Put, :High Jump, :"400m"n, :"100m hurdles"n, :Discus, :Pole Vault, :Javelin, :"1500m"n ),
Variance Estimation( "REML" ),
"on Covariances",
Summary Plots( Label variables( 0 ) ),
Cluster Variables( 1 ),
Local Data Filter(
Width( 208 ),
Add Filter( columns( :Country ), Where( :Country == "CAN" ), Display( :Country, N Items( 15 ) ) )
)
);
obj << Save Script to Report;
rpt = obj << report;
text_act = Try( rpt[Text Box( 1 )] << Get Text );
text_exp =
"Principal Components(
Y(
:\!"100m\!"n, :Long Jump, :Shot Put, :High Jump, :\!"400m\!"n, :\!"100m hurdles\!"n,
:Discus, :Pole Vault, :Javelin, :\!"1500m\!"n
),
Estimation Method( \!"REML\!" ),
Standardize( \!"Unscaled\!" ),
Cluster Variables( 1 ),
Local Data Filter(
Width( 208 ),
Add Filter(
columns( :Country ),
Where( :Country == \!"CAN\!" ),
Display( :Country, N Items( 15 ) )
)
)
)";
Close( dt, nosave );
);
Code Explanation:
- Check for JMP Pro version.
- Open data table;
- Perform Principal Component analysis.
- Use REML variance estimation.
- Analyze covariances.
- Generate summary plots.
- Cluster variables.
- Apply local data filter.
- Save script to report.
- Extract report text.