Principal Components
Example 1
Summary: Opens a data table, performs Principal Components analysis with sparse estimation method and 2 components, generates summary plots, and sends the results to a report.
Code:
// Principal Components
// Open data table
dt = Open("data_table.jmp");
// Principal Components
Principal Components(
Y(
:ABDOMINAL PAIN, :ABNORMAL VISION,
:ALOPECIA, :AMBLYOPIA, :ANEMIA,
:ANGINA PECTORIS, :ANOREXIA,
:ANXIETY, :ASTHENIA, :ASTHMA,
:BACK PAIN, :BRONCHITIS,
:CHEST PAIN,
:CHEST PAIN SUBSTERNAL, :CHILLS,
:CONSTIPATION, :COUGH INCREASED,
:DEAFNESS, :DEPRESSION, :DIARRHEA,
:DIZZINESS, :DRY MOUTH,
:DUODENAL ULCER, :DYSPEPSIA,
:DYSURIA, :ECCHYMOSIS, :EDEMA,
:EPISTAXIS, :ERUCTATION,
:ESOPHAGITIS, :EYE DISORDER,
:EYE HEMORRHAGE, :FACE EDEMA,
:FEVER, :FLATULENCE,
:FLU SYNDROME, :GENERALIZED EDEMA,
:HEADACHE, :HYPERTONIA,
:HYPERURICEMIA,
:INCREASED URINARY FREQ,
:INFECTION, :KERATOCONJUNCTIVITIS,
:LACRIMATION DISORDER,
:LYMPHADENOPATHY, :MELENA,
:MIGRAINE, :NAUSEA, :NECK PAIN,
:NERVOUSNESS, :NEUROPATHY, :PAIN,
:PERIODONTAL ABSCESS,
:PERIPHERAL EDEMA, :PHARYNGITIS,
:PHLEBITIS, :POLYURIA, :PRURITUS,
:RASH, :REACTION UNEVALUABLE,
:RECTAL BLEEDING, :RHINITIS,
:SGOT INCREASED, :SINUSITIS,
:SOMNOLENCE, :STOMACH ULCER,
:TACHYCARDIA, :TENOSYNOVITIS,
:TINNITUS,
:URINARY TRACT INFECTIO,
:URINARY URGENCY,
:VESTIBULAR DISORDER,
:VITREOUS DISORDER,
:VOICE ALTERATION, :VOMITING
),
Estimation Method( "Sparse" ),
Number of Components( 2 ),
"on Correlations",
Summary Plots( Label variables( 0 ) ),
SendToReport(
Dispatch( {"Summary Plots"},
"PCA Summary Plots", FrameBox,
{Frame Size( 46, 36 )}
),
Dispatch( {"Summary Plots"},
"PCA Summary Plots",
FrameBox( 2 ),
{Frame Size( 49, 36 )}
)
)
);
Code Explanation:
- Open data table.
- Run Principal Components analysis.
- Select multiple Y variables.
- Use Sparse estimation method.
- Set number of components to 2.
- Enable correlation matrix.
- Generate summary plots.
- Do not label variables in plots.
- Adjust first frame size.
- Adjust second frame size.
Example 2
Summary: Performs a Principal Components analysis on a dataset, reducing the number of variables and visualizing the results in two summary plots.
Code:
// Principal Components: Variable Reduction
// Open data table
dt = Open("data_table.jmp");
// Principal Components: Variable Reduction
Principal Components(
Y(
:"Age (years)"n, :"Weight (lbs)"n,
:"Height (inches)"n,
:"Neck circumference (cm)"n,
:"Chest circumference (cm)"n,
:"Abdomen circumference (cm)"n,
:"Hip circumference (cm)"n,
:"Thigh circumference (cm)"n,
:"Knee circumference (cm)"n,
:"Ankle circumference (cm)"n,
:
"Biceps (extended) circumference (cm)"n,
:"Forearm circumference (cm)"n,
:"Wrist circumference (cm)"n
),
Estimation Method( "Row-wise" ),
on Correlations,
Cluster Variables,
SendToReport(
Dispatch( {"Summary Plots"},
"PCA Summary Plots", FrameBox,
{Frame Size( 51, 37 )}
),
Dispatch( {"Summary Plots"},
"PCA Summary Plots",
FrameBox( 2 ),
{Frame Size( 55, 37 )}
)
)
);
Code Explanation:
- Open data table.
- Define principal components.
- Specify variables for analysis.
- Set estimation method.
- Include correlations.
- Cluster variables.
- Send report settings.
- Adjust summary plot size.
- Adjust second summary plot size.
- Execute principal component analysis.
Example 3
Summary: Opens a data table, performs principal component analysis (PCA) on selected variables, and displays the results in a report.
Code:
// Principal Components
// Open data table
dt = Open("data_table.jmp");
// Principal Components
Principal Components(
Y(
:AA, :CO, :DL, :F9, :FL, :NW, :UA,
:US, :WN
),
Estimation Method( "Default" ),
"on Correlations"
);
Code Explanation:
- Open data table.
- Define variable
dt. - Call
Principal Componentsfunction. - Specify
Yvariables. - Set estimation method.
- Enable correlation display.
Example 4
Summary: Loads a data table, performs Principal Components analysis with default estimation method and correlations, calculates the first eigenvalue, and generates a loading plot.
Code:
// Loading plot
// Open data table
dt = Open("data_table.jmp");
// Loading plot
Principal Components(
Y(
:Fuel, :Steam Flow, :Steam Temp,
:MW, :Cool Temp, :Pressure
),
Estimation Method( "Default" ),
"on Correlations",
Eigenvalues( 1 ),
Summary Plots( 0 ),
Loading Plot( 4 )
);
Code Explanation:
- Open data table.
- Load Principal Components analysis.
- Specify variables for analysis.
- Use default estimation method.
- Display correlations.
- Calculate first eigenvalue.
- Disable summary plots.
- Generate loading plot.
- Set plot detail level to 4.
Example 5
Summary: Performs a principal components analysis (PCA) on the Thickness variables in an appliance data table, using a row-wise estimation method and displaying eigenvalues. The results are sent to a report with two summary plots.
Code:
// Principal Components
// Open data table
dt = Open("data_table.jmp");
// Principal Components
Principal Components(
Y(
:Thickness 01, :Thickness 02,
:Thickness 03, :Thickness 04,
:Thickness 05, :Thickness 06,
:Thickness 07, :Thickness 08,
:Thickness 09, :Thickness 10,
:Thickness 11, :Thickness 12
),
Estimation Method( "Row-wise" ),
on Covariances,
Eigenvalues( 1 ),
Arrow Lines( 1 ),
SendToReport(
Dispatch( {"Summary Plots"},
"PCA Summary Plots", FrameBox,
{Frame Size( 200, 200 )}
),
Dispatch( {"Summary Plots"},
"PCA Summary Plots",
FrameBox( 2 ),
{Frame Size( 200, 200 )}
)
)
);
Code Explanation:
- Open table.
- Perform principal components analysis.
- Specify response variables.
- Use row-wise estimation method.
- Analyze covariances.
- Display eigenvalues.
- Show arrow lines.
- Adjust summary plot size.
- Adjust second summary plot size.
- Generate report.
Example 6
Summary: Performs a principal components analysis on an appliance dataset, using row-wise variance estimation and scatterplot matrix visualization to identify key factors.
Code:
Open("data_table.jmp");
Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Variance Estimation( "Row-wise" ),
"on Correlations",
Summary Plots( 0 ),
Scatterplot Matrix( 4 ),
Select component( 2, 1 ),
SendToReport( Dispatch( {"Scatterplot Matrix"}, "403", ScaleBox, {Label Row( Inside Ticks( 1 ) )} ) )
);
Code Explanation:
- Open data table;
- Perform principal components analysis.
- Set variables for analysis.
- Use row-wise variance estimation.
- Analyze correlations.
- Disable summary plots.
- Create scatterplot matrix.
- Select first two components.
- Modify report settings.
- Adjust label row ticks.
Example 7
Summary: Runs a Principal Components analysis on the Sepal length, Sepal width, Petal length, and Petal width variables from an open data table, with default estimation method and outlier analysis on 4 components.
Code:
Open("data_table.jmp");
Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Default" ),
"on Correlations",
Outlier Analysis( Number of Components( 4 ) ),
SendToReport(
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox, {Frame Size( 41, 38 )} ),
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox( 2 ), {Frame Size( 49, 38 )} ),
Dispatch( {"Outlier Analysis", "T² for 4 Principal Components"}, "PCA Outlier Analysis", FrameBox,
{Grid Line Order( 1 ), Reference Line Order( 2 ), Add Pin Annotation(
Seg( Marker Seg( 1 ) ),
Index( 141 ),
Index Row( 141 ),
UniqueID( 629240157 ),
FoundPt( {462, 552} ),
Origin( {141.596244131455, 12.4} ),
Offset( {142, 94} ),
Tag Line( 1 ),
Font( "Segoe UI", 9, "Plain" )
)}
),
Dispatch( {"Outlier Analysis", "T² for 4 Principal Components"}, "PCA Outlier Analysis", FrameBox( 2 ),
{DispatchSeg( CustomStreamSeg( 1 ), {Font( "Segoe UI", 9, "Plain" )} )}
)
)
);
Code Explanation:
- Open data table;
- Run Principal Components analysis.
- Set variables for analysis.
- Use default estimation method.
- Analyze correlations.
- Perform outlier analysis on 4 components.
- Adjust summary plot frame size.
- Adjust second summary plot frame size.
- Add pin annotation to outlier plot.
- Customize font for outlier plot labels.
Example 8
Summary: Runs a Principal Component Analysis (PCA) on selected columns of an appliance data table, utilizing correlations for estimation and enabling outlier analysis with 4 components.
Code:
dt = Open("data_table.jmp");
Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Default" ),
"on Correlations",
Outlier Analysis( Number of Components( 4 ), Contribution Proportion Plot for Selected Samples( {101} ) ),
SendToReport(
Dispatch( {}, "Summary Plots", OutlineBox, {Close( 1 )} ),
Dispatch( {"Outlier Analysis", "T² for 4 Principal Components"}, "PCA Outlier Analysis", FrameBox,
{Grid Line Order( 1 ), Reference Line Order( 2 ), Add Pin Annotation(
Seg( Marker Seg( 1 ) ),
Index( 100 ),
Index Row( 100 ),
UniqueID( 835428724 ),
FoundPt( {359, 202} ),
Origin( {102.159624413146, 8.80833333333333} ),
Tag Line( 1 )
)}
)
)
);
Code Explanation:
- Open data table;
- Perform PCA on selected columns.
- Use correlations for estimation.
- Enable outlier analysis with 4 components.
- Create contribution proportion plot for sample 101.
- Close summary plots outline box.
- Access PCA outlier analysis frame.
- Set grid line order to 1.
- Set reference line order to 2.
- Add pin annotation to specific point.
Example 9
Summary: Runs Principal Components analysis on a data table to identify key factors and correlations, generating summary plots and conducting outlier analysis.
Code:
Open("data_table.jmp");
Principal Components(
Y(
:ABDOMINAL PAIN, :ABNORMAL VISION, :ALOPECIA, :AMBLYOPIA, :ANEMIA, :ANGINA PECTORIS, :ANOREXIA, :ANXIETY, :ASTHENIA, :ASTHMA,
:BACK PAIN, :BRONCHITIS, :CHEST PAIN, :CHEST PAIN SUBSTERNAL, :CHILLS, :CONSTIPATION, :COUGH INCREASED, :DEAFNESS, :DEPRESSION,
:DIARRHEA, :DIZZINESS, :DRY MOUTH, :DUODENAL ULCER, :DYSPEPSIA, :DYSURIA, :ECCHYMOSIS, :EDEMA, :EPISTAXIS, :ERUCTATION,
:ESOPHAGITIS, :EYE DISORDER, :EYE HEMORRHAGE, :FACE EDEMA, :FEVER, :FLATULENCE, :FLU SYNDROME, :GENERALIZED EDEMA, :HEADACHE,
:HYPERTONIA, :HYPERURICEMIA, :INCREASED URINARY FREQ, :INFECTION, :KERATOCONJUNCTIVITIS, :LACRIMATION DISORDER, :LYMPHADENOPATHY,
:MELENA, :MIGRAINE, :NAUSEA, :NECK PAIN, :NERVOUSNESS, :NEUROPATHY, :PAIN, :PERIODONTAL ABSCESS, :PERIPHERAL EDEMA, :PHARYNGITIS,
:PHLEBITIS, :POLYURIA, :PRURITUS, :RASH, :REACTION UNEVALUABLE, :RECTAL BLEEDING, :RHINITIS, :SGOT INCREASED, :SINUSITIS,
:SOMNOLENCE, :STOMACH ULCER, :TACHYCARDIA, :TENOSYNOVITIS, :TINNITUS, :URINARY TRACT INFECTIO, :URINARY URGENCY,
:VESTIBULAR DISORDER, :VITREOUS DISORDER, :VOICE ALTERATION, :VOMITING
),
Estimation Method( "REML" ),
"on Correlations",
Summary Plots( Label variables( 0 ) ),
Outlier Analysis( Contribution Proportions Heat Map( 1 ) ),
SendToReport(
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox, {Frame Size( 46, 36 )} ),
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox( 2 ), {Frame Size( 49, 36 )} )
)
);
Code Explanation:
- Open data_table data
- Perform Principal Components analysis.
- Set response variables.
- Use REML estimation method.
- Enable correlations display.
- Generate summary plots.
- Disable variable labels in summary plots.
- Conduct outlier analysis.
- Create heat map for contribution proportions.
- Resize PCA summary plots frames.
Example 10
Summary: Runs principal components analysis on a data table to extract key factors and visualize results in a report.
Code:
Names Default To Here( 1 );
dt = Open("data_table.jmp");
obj = Principal Components( Y( :Ether, :Chloroform, :Benzene, :Carbon Tetrachloride, :Hexane ) );
Code Explanation:
- Set default names.
- Open data table.
- Perform principal components analysis.
Example 11
Summary: Runs principal components analysis (PCA) on a dataset with 12 variables, using row-wise estimation method and correlations to generate a 3D score plot and biplot.
Code:
dt = Open("data_table.jmp");
obj = Principal Components(
Y(
:Name( "Age (years)" ), :Name( "Weight (lbs)" ), :Name( "Height (inches)" ), :Name( "Neck circumference (cm)" ),
:Name( "Chest circumference (cm)" ), :Name( "Abdomen circumference (cm)" ), :Name( "Hip circumference (cm)" ),
:Name( "Thigh circumference (cm)" ), :Name( "Knee circumference (cm)" ), :Name( "Ankle circumference (cm)" ),
:Name( "Biceps (extended) circumference (cm)" ), :Name( "Forearm circumference (cm)" ), :Name( "Wrist circumference (cm)" )
),
Estimation Method( "Row-wise" ),
on Correlations,
Correlations( 1 ),
Summary Plots( 0 ),
Name( "3D Score Plot" )(1),
Biplot( 2 ),
SendToReport(
Dispatch( {}, "Principal Components: on Correlations", OutlineBox, {Set Title( "Correlations, Biplot, 3D Score Plot" )} ),
Dispatch( {"BiPlot"}, "PCA BiPlot", FrameBox, {Frame Size( 50, 35 )} )
)
);
Code Explanation:
- Open table.
- Perform principal components analysis.
- Specify variables for analysis.
- Use row-wise estimation method.
- Include correlations.
- Set correlations to 1.
- Disable summary plots.
- Enable 3D score plot.
- Enable biplot with 2 components.
- Customize report title and frame size.
Example 12
Summary: Runs Principal Components analysis to extract insights from a dataset, utilizing row-wise estimation and correlations, with adjustable summary plot sizes.
Code:
dt under test = Open("data_table.jmp");
obj = Principal Components(
Y(
:Name( "Age (years)" ), :Name( "Weight (lbs)" ), :Name( "Height (inches)" ), :Name( "Neck circumference (cm)" ),
:Name( "Chest circumference (cm)" ), :Name( "Abdomen circumference (cm)" ), :Name( "Hip circumference (cm)" ),
:Name( "Thigh circumference (cm)" ), :Name( "Knee circumference (cm)" ), :Name( "Ankle circumference (cm)" ),
:Name( "Biceps (extended) circumference (cm)" ), :Name( "Forearm circumference (cm)" ), :Name( "Wrist circumference (cm)" )
),
Estimation Method( "Row-wise" ),
on Correlations,
Cluster Variables,
SendToReport(
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox, {Frame Size( 51, 37 )} ),
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox( 2 ), {Frame Size( 55, 37 )} )
)
);
Code Explanation:
- Open data table;
- Run Principal Components analysis.
- Specify variables for analysis.
- Use row-wise estimation method.
- Include correlations in output.
- Cluster variables option selected.
- Adjust first summary plot size.
- Adjust second summary plot size.
Example 13
Summary: Performs a principal components analysis (PCA) to extract underlying patterns in appliance reliability data, generating summary plots and squared cosines of variables.
Code:
Open( “$SAMPLE_DATA/data_table.jmp” );
obj = Principal Components(
Y( :"Population (1000)"n ),
Z( :Life Expectancy Ranking ),
Estimation Method( "Row-wise" ),
Standardize( "Standardized" ),
Eigenvalues( 1 ),
Bartlett Test( 1 ),
Summary Plots( Label variables( 0 ) ),
Squared Cosines of Variables( Plot of Squared Cosines of Variables( Overview( 1 ), "Side by side" ) )
);
obj << Redo Analysis;
Code Explanation:
- Open data table.
- Run principal components analysis.
- Set Y variable.
- Set Z variable.
- Use row-wise estimation.
- Standardize data.
- Calculate eigenvalues.
- Perform Bartlett test.
- Generate summary plots.
- Create squared cosines plot.
Example 14
Summary: Runs a Principal Components analysis to identify key factors in an appliance's reliability, utilizing REML estimation method and clustering variables for visual insights.
Code:
dt under test = Open("data_table.jmp");
obj = Principal Components(
Y( :Name( "Sales($M)" ), :Name( "Profit($M)" ), :Name( "#employees" ), :Name( "Assets($Mil.)" ), :Name( "Stockholder's Eq($Mil.)" ) ),
Estimation Method( "REML" ),
on Correlations,
Cluster Variables,
SendToReport(
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox, {Frame Size( 53, 39 )} ),
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox( 2 ), {Frame Size( 56, 39 )} ),
Dispatch( {"Variable Clustering"}, "Cluster Summary", OutlineBox,
{Set Title( "Cluster Summary - look for header labels on multiple lines, wrapping should occur" )}
)
)
);
Code Explanation:
- Open data table;
- Run Principal Components analysis.
- Set Y variables: Sales, Profit, Employees, Assets, Stockholders' Equity.
- Use REML estimation method.
- Analyze correlations.
- Cluster variables.
- Resize first PCA plot.
- Resize second PCA plot.
- Customize cluster summary title.
- Display reports.
Example 15
Summary: Runs Principal Components analysis on a filtered dataset to identify patterns and correlations, utilizing row-wise estimation method and local data filter.
Code:
dt = Open("data_table.jmp");
obj = Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Row-wise" ),
on Correlations,
Local Data Filter(
Add Filter( columns( :Sepal length ), Where( :Sepal length >= 5.0 & :Sepal length <= 6.5 ) ),
Mode( Select( 0 ), Show( 1 ), Include( 1 ) )
),
);
obj << Automatic Recalc( 0 );
dt << Select Where( :Species == "setosa" );
dt << Exclude();
rpt = Report( obj );
Code Explanation:
- Open data table;
- Create Principal Components analysis.
- Set variables for analysis.
- Use row-wise estimation method.
- Enable correlation matrix.
- Add local data filter.
- Filter Sepal length between 5.0 and 6.5.
- Set filter mode to select.
- Exclude rows where Species is setosa.
- Generate report from analysis.
Example 16
Summary: Runs Principal Components analysis on a dataset with local data filtering and automatic recalculation, generating reports for selected subsets of data.
Code:
dt = Open("data_table.jmp");
obj = Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Row-wise" ),
on Correlations,
Local Data Filter(
Add Filter( columns( :Sepal length ), Where( :Sepal length >= 5.0 & :Sepal length <= 6.5 ) ),
Mode( Select( 0 ), Show( 1 ), Include( 1 ) )
),
);
obj << Automatic Recalc( 1 );
dt << Select Where( :Species == "setosa" );
dt << Exclude();
rpt = Report( obj );
Close( dt, NoSave );
dt = Open("data_table.jmp");
obj = Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Row-wise" ),
on Correlations,
Local Data Filter(
Add Filter( columns( :Sepal length ), Where( :Sepal length >= 5.0 & :Sepal length <= 6.5 ) ),
Mode( Select( 0 ), Show( 1 ), Include( 1 ) )
),
);
obj << Automatic Recalc( 0 );
dt << Select Where( :Species == "setosa" );
dt << Exclude();
rpt = Report( obj );
Code Explanation:
- Open data table;
- Perform Principal Components analysis.
- Set estimation method to row-wise.
- Use correlations for analysis.
- Add local data filter on Sepal length.
- Set filter range to 5.0 to 6.5.
- Configure filter mode to select 0, show 1, include 1.
- Enable automatic recalculation.
- Select rows where Species is setosa.
- Exclude selected rows.
- Generate report from analysis.
- Close dataset without saving.
- Reopen data_table dataset
- Repeat Principal Components analysis.
- Disable automatic recalculation.
- Select rows where Species is setosa.
- Exclude selected rows.
- Generate report from analysis.
Example 17
Summary: Performs principal component analysis (PCA) on a data table to extract correlations and certified statistics for rows with Ether > 0 and < 0, utilizing the Principal Components platform in JMP.
Code:
dt = Open("data_table.jmp");
princomp = dt << Principal Components(
Y( :Name( "1-Octanol" ), :Ether, :Chloroform, :Benzene, :Carbon Tetrachloride ),
Estimation Method( "Row-wise" ),
on Correlations,
Correlations( 1 )
);
princomp << Automatic Recalc( 1 );
dt << Select where( :ether > 0 );
dt << Hide and Exclude( 1 );
sumStats1 = Report( princomp )["Correlations"][Matrix Box( 1 )] << get;
certStats1 = [1 0.639186964594469 0.544422420958056 0.601176645931733 0.495033263329161,
0.639186964594469 1 0.0590715881839129 0.293093401595568 0.337730686192189,
0.544422420958056 0.0590715881839129 1 0.91879136420179 0.846990757537019,
0.601176645931733 0.293093401595568 0.91879136420179 1 0.911341391651443,
0.495033263329161 0.337730686192189 0.846990757537019 0.911341391651443 1];
dt << Clear Row States;
dt << Select Where( :ether < 0 );
dt << Hide and Exclude;
sumStats2 = Report( princomp )["Correlations"][Matrix Box( 1 )] << get;
certStats2 = [1 0.889871330007042 0.501449346239283 0.62353476665854 0.553076202438458,
0.889871330007042 1 0.410122009781931 0.528569390988602 0.448983371517192,
0.501449346239283 0.410122009781931 1 0.936922763201392 0.91663777643923,
0.62353476665854 0.528569390988602 0.936922763201392 1 0.96147666420353,
0.553076202438458 0.448983371517192 0.91663777643923 0.96147666420353 1];
Code Explanation:
- Open table.
- Perform principal component analysis.
- Enable automatic recalculation.
- Select rows where Ether > 0.
- Hide and exclude selected rows.
- Retrieve correlation matrix.
- Define certified statistics for Ether > 0.
- Clear row states.
- Select rows where Ether < 0.
- Hide and exclude selected rows.
Example 18
Summary: Runs Principal Components analysis on a dataset to extract insights from anthropometric measurements, utilizing row-wise estimation and enabling correlations, biplot, and 3D score plot.
Code:
dt under test = Open("data_table.jmp");
obj = Principal Components(
Y(
:Name( "Age (years)" ), :Name( "Weight (lbs)" ), :Name( "Height (inches)" ), :Name( "Neck circumference (cm)" ),
:Name( "Chest circumference (cm)" ), :Name( "Abdomen circumference (cm)" ), :Name( "Hip circumference (cm)" ),
:Name( "Thigh circumference (cm)" ), :Name( "Knee circumference (cm)" ), :Name( "Ankle circumference (cm)" ),
:Name( "Biceps (extended) circumference (cm)" ), :Name( "Forearm circumference (cm)" ), :Name( "Wrist circumference (cm)" )
),
Estimation Method( "Row-wise" ),
on Correlations,
Correlations( 1 ),
Summary Plots( 0 ),
Name( "3D Score Plot" )(1),
Biplot( 2 ),
SendToReport(
Dispatch( {}, "Principal Components: on Correlations", OutlineBox, {Set Title( "Correlations, Biplot, 3D Score Plot" )} ),
Dispatch( {"Principal Components: on Correlations", "Biplot"}, FrameBox( 2 ), {Frame Size( 50, 35 )} )
)
);
Code Explanation:
- Open data table;
- Run Principal Components analysis.
- Set Y variables for analysis.
- Use Row-wise estimation method.
- Enable correlations.
- Set correlation threshold to 1.
- Disable summary plots.
- Enable 3D Score Plot.
- Enable Biplot.
- Customize report title and size.
Example 19
Summary: Runs Principal Components analysis to extract insights from appliance data, utilizing row-wise estimation method and correlations.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :height ), Estimation Method( "Row-wise" ), on Correlations, );
rpt = Report( obj );
Code Explanation:
- Open data table;
- Create Principal Components analysis.
- Set height as Y variable.
- Use Row-wise estimation method.
- Include correlations.
- Generate report object.
Example 20
Summary: Runs the principal component analysis (PCA) of a dataset to extract the most important features, using sparse estimation method and specifying height as the response variable.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :height ), Estimation Method( "Sparse" ), Number of Components( 1 ) );
Code Explanation:
- Open data table.
- Create principal components object.
- Specify height as response.
- Use sparse estimation method.
- Set number of components to 1.
Example 21
Summary: Performs principal component analysis on a dataset to extract three key components using the sparse estimation method.
Code:
Open("data_table.jmp");
obj = Principal Components( Y( :p1, :p2, :p3 ), Estimation Method( "sparse" ), Number of Components( 3 ) );
Code Explanation:
- Open data table.
- Perform principal component analysis.
- Specify response variables.
- Use sparse estimation method.
- Set number of components to 3.
Example 22
Summary: Performs a life distribution analysis using Weibull distribution to analyze appliance data, generating summary plots and comparing squared cosines of variables.
Code:
dt = Open("data_table.jmp");
obj1 = dt << Principal Components(
Y( :NPN1, :PNP1, :PNP2, :NPN2, :PNP3, :IVP1, :PNP4 ),
Estimation Method( "Default" ),
"on Correlations",
Formatted Loading Matrix( 1 ),
Squared Cosines of Variables( 1 ),
SendToReport(
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox, {Frame Size( 49, 38 )} ),
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox( 2 ), {Frame Size( 52, 38 )} )
)
);
obj2 = dt << Principal Components(
Y( :NPN1, :PNP1, :PNP2, :NPN2, :PNP3, :IVP1, :PNP4 ),
Estimation Method( "Default" ),
"on Correlations",
Squared Cosines of Variables( 1 ),
Formatted Loading Matrix( 1 ),
SendToReport(
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox, {Frame Size( 49, 38 )} ),
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox( 2 ), {Frame Size( 52, 38 )} )
)
);
rpt1 = obj1 << Report;
rpt2 = obj2 << Report;
actForLo1 = rpt1[Outline Box( "Formatted Loading Matrix" )][Matrix Box( 1 )] << Get;
actForLo2 = rpt2[Outline Box( "Formatted Loading Matrix" )][Matrix Box( 1 )] << Get;
actPlot1 = rpt1[Outline Box( "Plot of Squared Cosines of Variables" )] << Get Picture;
actPlot2 = rpt2[Outline Box( "Plot of Squared Cosines of Variables" )] << Get Picture;
myLog = Log Capture( ut pictureCompare( actPlot1, actPlot2 ) );
Code Explanation:
- Open data table;
- Perform PCA on specified columns.
- Configure PCA settings.
- Generate summary plots.
- Repeat PCA analysis.
- Extract formatted loading matrix.
- Extract squared cosines plot.
- Compare squared cosines plots.
- Capture comparison results.
- Save log of comparison.
Example 23
Summary: Performs a principal components analysis (PCA) on a data table, generating multiple reports with partial contribution and squared cosines of variables, and extracting journals from each report.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Y( :OZONE, :CO, :SO2, :NO, :PM10, :Lead ),
Estimation Method( "Default" ),
"on Correlations",
Partial Contribution of Variables( 1 )
);
rpt1 = obj << Report;
actJournal1 = rpt1 << Get Journal;
obj << Partial Contribution of Variables( 0 );
obj << Partial Contribution of Variables( 1 );
rpt2 = obj << Report;
actJournal2 = rpt2 << Get Journal;
obj << Squared Cosines of Variables( 1 );
obj << Squared Cosines of Variables( 0 );
obj << Squared Cosines of Variables( 1 );
rpt3 = obj << Report;
actJournal3 = rpt3 << Get Journal;
obj2 = dt << Principal Components(
Y( :OZONE, :CO, :SO2, :NO, :PM10, :Lead ),
Estimation Method( "Default" ),
"on Correlations",
Partial Contribution of Variables( 1 ),
Squared Cosines of Variables( 1 )
);
rpt4 = obj2 << Report;
actJournal4 = rpt4 << Get Journal;
Code Explanation:
- Open data table;
- Perform principal components analysis.
- Generate first report.
- Extract journal from report.
- Toggle partial contribution option.
- Regenerate report.
- Extract second journal.
- Toggle squared cosines option.
- Regenerate report.
- Extract third journal.
Example 24
Summary: Performs Principal Component Analysis on a data table to identify key components and detect outliers, generating a report with summary plots.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Y( :Mass, :Fore, :Bicep, :Chest, :Neck, :Shoulder, :Waist, :Height, :Calf, :Thigh, :Head ),
Estimation Method( "Default" ),
"on Correlations"
);
obj << Outlier Analysis;
rpt = obj << Report();
summary = rpt[Outline Box( "Principal Components: on Correlations" )] << Get Journal();
Code Explanation:
- Open data table.
- Run Principal Component Analysis.
- Use correlation matrix.
- Perform outlier analysis.
- Retrieve analysis report.
- Extract principal components summary.
Example 25
Summary: Analyze appliance data using Principal Component Analysis (PCA) with sparse and wide estimation methods, generating reports and extracting summaries.
Code:
dt = Open("data_table.jmp");
obj1 = dt << Principal Components( Y( :POP, :Max deg. F Jan, :OZONE, :CO ), Estimation Method( "Sparse" ), Number of Components( 2 ) );
rpt1 = obj1 << Report();
summary = rpt1[Outline Box( "Principal Components" )] << Get Journal();
obj2 = dt << Principal Components( Y( :POP, :Max deg. F Jan, :OZONE, :CO ), Estimation Method( "Wide" ) );
rpt2 = obj2 << Report();
summary = rpt2[Outline Box( "Principal Components" )] << Get Journal();
Code Explanation:
- Open table.
- Fit sparse PCA.
- Generate report.
- Extract summary.
- Fit wide PCA.
- Generate report.
- Extract summary.
Example 26
Summary: Analyze appliance reliability data using Principal Component Analysis (PCA) on both covariances and correlations, generating summary plots for each.
Code:
dt1 = Open("data_table.jmp");
obj1 = dt1 << Principal Components( Y( 2 :: 30 ), Variance Estimation( "Wide" ), "on Covariances" );
rpt1 = obj1 << Report();
obj2 = dt1 << Principal Components( Y( 2 :: 30 ), Variance Estimation( "Wide" ), "on Correlations" );
rpt2 = obj2 << Report();
jrn1sum = rpt1[Outline Box( "Summary Plots" )] << Get Journal();
jrn2sum = rpt2[Outline Box( "Summary Plots" )] << Get Journal();
If( JMP Product Name() == "Pro",
obj3 = dt1 << Principal Components( Y( 2 :: 30 ), Variance Estimation( "Sparse" ), Number of Components( 4 ), "on Covariances" );
obj4 = dt1 << Principal Components( Y( 2 :: 30 ), Variance Estimation( "Sparse" ), Number of Components( 4 ), "on Correlations" );
rpt3 = obj3 << Report();
rpt4 = obj4 << Report();
jrn3sum = rpt3[Outline Box( "Summary Plots" )] << Get Journal();
jrn4sum = rpt4[Outline Box( "Summary Plots" )] << Get Journal();
);
Code Explanation:
- Open data table;
- Perform PCA on covariances.
- Create report for PCA on covariances.
- Perform PCA on correlations.
- Create report for PCA on correlations.
- Extract summary plots journal from PCA on covariances.
- Extract summary plots journal from PCA on correlations.
- Check if JMP product is Pro.
- Perform sparse PCA on covariances.
- Perform sparse PCA on correlations.
Example 27
Summary: Runs the principal component analysis (PCA) of a dataset, deleting the OZONE column and generating scriptable objects for further processing.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :POP, :OZONE, :CO, :SO2, :NO2 ), Variance Estimation( "Default" ), "on Correlations" );
dt << delete columns( "OZONE" );
scrobj = obj << Get Scriptable Object;
Code Explanation:
- Open table.
- Perform PCA.
- Delete OZONE column.
- Get scriptable object.
Example 28
Summary: Analyze appliance data by performing principal component analysis, removing columns 3 to 7, and capturing cluster variables.
Code:
dt = Open("data_table.jmp");
pca = dt << Principal Components( Y( :Ether, :Chloroform, :Benzene, :Carbon Tetrachloride, :Hexane ) );
dt << Delete Columns( 3 :: 7 );
Log Capture( pca << Cluster Variables );
Code Explanation:
- Open data table;
- Perform principal component analysis.
- Remove columns 3 to 7.
- Log capture cluster variables output.
Example 29
Summary: Analyze appliance reliability data using principal component analysis, generating summary plots and extracting a report object.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Y( :height, :weight ),
Variance Estimation( "Default" ),
"on Correlations",
SendToReport(
Dispatch( {"Summary Plots"}, "1", ScaleBox, {Label Row( Inside Ticks( 1 ) )} ),
Dispatch( {"Summary Plots"}, "2", ScaleBox, {Label Row( Inside Ticks( 1 ) )} )
)
);
rpt = obj << report;
jrn = rpt << Get Journal;
ticks_exp = {Inside Ticks( 1 ), Inside Ticks( 1 ), Inside Ticks( 1 ), Inside Ticks( 1 ), Inside Ticks( 0 ), Inside Ticks( 0 )};
Code Explanation:
- Open data table.
- Perform principal component analysis.
- Set variance estimation method.
- Use correlations for analysis.
- Customize summary plots.
- Extract report object.
- Retrieve journal from report.
- Define tick marks for labels.
Example 30
Summary: Analyze appliance reliability data by performing principal component analysis on LBI and LBS variables, deleting rows 1-29, and conducting outlier analysis on component 1.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :LBI, :LBS ), Variance Estimation( "Default" ), "on Correlations" );
dt << delete rows( 1 :: 29 );
obj << outlier analysis( 1 );
Code Explanation:
- Open data table;
- Create principal component analysis object.
- Analyze LBI and LBS variables.
- Use default variance estimation.
- Base analysis on correlations.
- Delete first 29 rows from dataset.
- Perform outlier analysis on component 1.
Example 31
Summary: Runs a principal component analysis (PCA) on the appliance data to identify key factors and visualize correlations, with outlier analysis and contribution heat maps.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Y( 2 :: N Col( dt ) ),
Variance Estimation( "Wide" ),
Number of Components( 2 ),
"on Correlations",
Outlier Analysis( Number of Components( 2 ), Contribution Heat Map( 1 ), Contribution Proportions Heat Map( 1 ) )
);
rpt = obj << report;
Code Explanation:
- Open data table;
- Perform principal component analysis.
- Set response variables range.
- Use wide variance estimation.
- Specify number of components.
- Analyze correlations.
- Conduct outlier analysis.
- Set outlier analysis components.
- Enable contribution heat map.
- Enable contribution proportions heat map.
Example 32
Summary: Performs Principal Component Analysis (PCA) to identify patterns in the Sepal length, Sepal width, Petal length, and Petal width variables from a data table, with outlier analysis and contribution heat maps.
Code:
dt = Open("data_table.jmp");
obj = Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Variance Estimation( "Default" ),
"on Correlations",
Outlier Analysis(
1,
Number of Components( 2 ),
Set α Level( 0.1 ),
Contribution Heat Map( 1 ),
Contribution Proportions Heat Map( 1 ),
Normalized DModX Plot( 1 ),
Contribution Plots for Selected Samples( {16, 34, 42, 61} )
)
);
obj << Save Script to Report;
rpt = obj << report;
text_act = Try( rpt[Text Box( 1 )] << Get Text );
text_exp =
"Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( \!"Row-wise\!" ),
Standardize( \!"Standardized\!" ),
Outlier Analysis(
1,
Number of Components( 2 ),
Set α Level( 0.1 ),
Contribution Heat Map( 1 ),
Contribution Proportions Heat Map( 1 ),
Normalized DModX Plot( 1 ),
Contribution Plots for Selected Samples( {16, 34, 42, 61} )
)
)";
Code Explanation:
- Open data table;
- Perform Principal Component Analysis.
- Analyze correlations.
- Conduct outlier analysis.
- Use 2 components for outliers.
- Set α level to 0.1.
- Enable contribution heat map.
- Enable contribution proportions heat map.
- Enable normalized DModX plot.
- Generate contribution plots for specific samples.
Example 33
Summary: Performs Principal Component Analysis (PCA) on a data table to visualize relationships between variables, generating biplots, loading plots, and scatterplot matrices.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Variance Estimation( "Default" ),
"on Correlations",
Biplot( 2 ),
Scatterplot Matrix( 3 ),
Loading Plot( 2 )
);
rpt = obj << report;
obj << Biplot( 2, Label variables( 0 ) );
obj << Loading Plot( 2, Label variables( 0 ) );
obj << Scatterplot Matrix( 3, Label variables( 0 ) );
obj << Biplot( Label variables( 1 ) );
obj << Loading Plot( Label variables( 1 ) );
obj << Scatterplot Matrix( Label variables( 1 ) );
Code Explanation:
- Open data table;
- Perform PCA analysis.
- Use correlations for variance estimation.
- Create biplot with 2 components.
- Generate scatterplot matrix with 3 components.
- Produce loading plot with 2 components.
- Retrieve PCA report.
- Update biplot to not label variables.
- Update loading plot to not label variables.
- Update scatterplot matrix to not label variables.
- Update biplot to label variables.
- Update loading plot to label variables.
- Update scatterplot matrix to label variables.
Example 34
Summary: Performs Principal Component Analysis (PCA) on intensities to extract meaningful components, utilizing row-wise variance estimation and correlation-based analysis.
Code:
data = Open("data_table.jmp");
obj = data << Principal Components( Y( Column Group( "Intensities" ) ), Variance Estimation( "Row-wise" ), "on Correlations" );
obj << Save DMODX( 15 );
obj << Save DMODX( 27 );
obj << Save DMODX( 100 );
obj << Save DMODX( 1 );
obj << Save DMODX( 0 );
mymat = data << Get As Matrix();
Code Explanation:
- Open data table;
- Perform PCA on intensities.
- Use row-wise variance estimation.
- Base analysis on correlations.
- Save DMODX for component 15.
- Save DMODX for component 27.
- Save DMODX for component 100.
- Save DMODX for component 1.
- Save DMODX for component 0.
- Retrieve data as matrix.
Example 35
Summary: Runs the principal component analysis (PCA) of appliance data to extract meaningful insights, defining expected values for Principal Component 1 and 2, and saving the first two components.
Code:
data = Open("data_table.jmp");
obj = data << Principal Components( Y( :ls, :ha, :dt ), Variance Estimation( "Wide" ), "on Correlations" );
GetPrinComp1Exp = [-1.231799651, -1.889587812, -1.589739752, -1.117547105, -0.840710102, 0.4132510795, 0.1548555807, 0.8364033347,
0.7231268034, -0.57903298, 1.145119381, 2.3802722188, -0.257007399, 0.266991695, 0.2136793205, 1.3717253868];
GetPrinComp2Exp = [-0.061600286, 1.5026828618, -1.568999353, -0.116351984, 1.0202367043, 0.248407965, -0.098002428, -1.130309797,
0.5088371309, -1.192747906, -1.109704567, 0.1416042873, 1.1601978549, -0.149420549, -0.784690422, 1.6298604863];
GroupedCol = obj << Save Principal Components( 2 );
groupcol1 = Column( "Prin1" );
GetPrinComp1Act = groupcol1 << Get As Matrix;
groupcol2 = Column( "Prin2" );
GetPrinComp2Act = groupcol2 << Get As Matrix;
Code Explanation:
- Open data table;
- Perform principal component analysis.
- Define expected values for Principal Component 1.
- Define expected values for Principal Component 2.
- Save the first two principal components.
- Retrieve column "Prin1".
- Convert "Prin1" to matrix.
- Retrieve column "Prin2".
- Convert "Prin2" to matrix.
Example 36
Summary: Performs a life distribution analysis using principal component analysis (PCA) to extract predicted values for appliance reliability, utilizing the Weibull distribution and JMP scripting language.
Code:
data = Open("data_table.jmp");
obj = data << Principal Components( Y( :ls, :ha, :dt ), Variance Estimation( "Wide" ), "on Correlations" );
GetPred1Exp = [1.1415886635, 0.5307489019, 0.8355018855, 1.2452669491, 1.48232604, 2.6221372435, 2.3929013108, 3.0192414727, 2.8987726342,
1.743067689, 3.2975055097, 4.3977852538, 2.0073253288, 2.4946331757, 2.4536251607, 3.4713727811];
GetPred2Exp = [0.1780960543, 0.3499363368, -0.079597029, 0.1805532078, 0.3755006598, 0.3770200293, 0.3014438002, 0.2110218595, 0.4445741033,
0.0702839767, 0.242758109, 0.5437790318, 0.4505450902, 0.3042007912, 0.204657467, 0.6717265125];
GetPred3Exp = [41.483367922, -11.77763906, 72.089707963, 45.253249543, 22.321003669, 68.014673097, 71.368861136, 111.68619926, 67.908108074,
83.696625764, 117.61438773, 111.80206451, 30.977943271, 75.010312247, 89.946303947, 53.13483092];
GroupedCol = obj << Save Predicteds( 2 );
groupcol1 = Column( "Predicted ls" );
GetPred1Act = groupcol1 << Get As Matrix;
groupcol2 = Column( "Predicted ha" );
GetPred2Act = groupcol2 << Get As Matrix;
groupcol3 = Column( "Predicted dt" );
GetPred3Act = groupcol3 << Get As Matrix;
Code Explanation:
- Open data table;
- Perform principal component analysis.
- Define expected predictions for GetPred1.
- Define expected predictions for GetPred2.
- Define expected predictions for GetPred3.
- Save predicted values from PCA.
- Extract "Predicted ls" column.
- Convert "Predicted ls" to matrix.
- Extract "Predicted ha" column.
- Convert "Predicted ha" to matrix.
Example 37
Summary: Performs a principal components analysis on an appliance data table, analyzing correlations and generating a report.
Code:
dtb = Open("data_table.jmp");
dtb[3, 9] = .;
dtb[8, 12] = .;
dtb[5, 14] = .;
obj = dtb << Principal Components(
Y(
:v1, :v2, :v3, :v4, :v5, :v6, :v7, :v8, :v9, :v10, :v11, :v12, :v13, :v14, :v15, :v16, :v17, :v18, :v19, :v20, :v21, :v22, :v23,
:v24, :v25, :v26, :v27
),
Estimation Method( "Default" ),
"on Correlations"
);
rpt = obj << report;
Code Explanation:
- Open data table;
- Set cell [3, 9] to missing.
- Set cell [8, 12] to missing.
- Set cell [5, 14] to missing.
- Perform principal components analysis.
- Specify variables for analysis.
- Use default estimation method.
- Analyze correlations.
- Generate report object.
- Assign report to variable.
Example 38
Summary: Performs principal component analysis (PCA) on the appliance data table, extracting a single component using randomized SVD method and generating various plots for visualization.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Y( :height ),
Estimation Method( "Randomized SVD" ),
Number of Components( 1 ),
Standardize( "Standardized" ),
Formatted Loading Matrix( 1 ),
Scree Plot( 1 ),
Score Ellipses( 1 ),
Summary Plots( Label variables( 0 ) ),
Loading Matrix( Plot of Loading Matrix( Overview( 1 ), "Side by side" ) ),
Squared Cosines of Variables( Plot of Squared Cosines of Variables( Overview( 1 ), "Side by side" ) ),
Partial Contribution of Variables( Plot of Partial Contribution of Variables( Overview( 1 ), "Side by side" ) )
);
Code Explanation:
- Open data table.
- Perform principal component analysis.
- Use height as response variable.
- Apply randomized SVD method.
- Set number of components to 1.
- Standardize data.
- Include formatted loading matrix.
- Generate scree plot.
- Display score ellipses.
- Create summary plots without labels.
Example 39
Summary: Performs a principal components analysis (PCA) to identify relationships between OZONE, CO, SO2, NO, and PM10 variables in the provided data table, with standardized variables and partial contribution plots.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :OZONE, :CO, :SO2, :NO, :PM10 ), Standardize( "Standardized" ) );
obj << Partial Contribution of Variables( Plot of Partial Contribution of Variables( Overview( 3 ), "Side by side" ) );
Code Explanation:
- Open data table;
- Perform principal components analysis.
- Analyze variables OZONE, CO, SO2, NO, PM10.
- Standardize variables.
- Display partial contribution plot.
- Set overview to 3.
- Arrange plots side by side.
Example 40
Summary: Runs Principal Components analysis to extract meaningful relationships between OZONE, CO, SO2, NO, and PM10 variables in a data table, with individual partial contributions saved for the top 3 components.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :OZONE, :CO, :SO2, :NO, :PM10 ), "on Covariances" );
obj << Save Individual Partial Contributions( 3 );
Code Explanation:
- Open data table;
- Perform Principal Components analysis.
- Specify OZONE, CO, SO2, NO, PM10 variables.
- Use covariances for analysis.
- Save individual partial contributions.
- Set number of components to 3.
Example 41
Summary: Runs the principal component analysis (PCA) of a data table to extract key variables and relationships, utilizing covariances for analysis.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :OZONE, :CO, :SO2, :NO, :PM10 ), "on Covariances" );
obj << Save Individual Squared Cosines( 3 );
Code Explanation:
- Open data table;
- Create principal component analysis object.
- Specify variables for analysis.
- Use covariances for analysis.
- Save individual squared cosines.
Example 42
Summary: Performs principal component analysis (PCA) to extract insights from variables OZONE, CO, SO2, NO, and PM10 in a standardized data set, generating a squared cosines plot with horizontal orientation.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :OZONE, :CO, :SO2, :NO, :PM10 ), Standardize( "Standardized" ) );
obj << Squared Cosines of Variables( Plot of Squared Cosines of Variables( Overview( 3 ), "Stacked", "Horizontal" ) );
Code Explanation:
- Open data table;
- Create principal component analysis.
- Analyze variables OZONE, CO, SO2, NO, PM10.
- Standardize data using "Standardized" method.
- Generate squared cosines plot.
- Display overview with 3 components.
- Use stacked layout for plot.
- Orient plot horizontally.
Example 43
Summary: Runs Principal Components analysis to extract the first eigenvalue and perform a Bartlett test on correlations, generating a report object with summary plots.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Y( :v1, :v2, :v3, :v4 ),
Estimation Method( "Default" ),
"on Correlations",
Eigenvalues( 1 ),
Bartlett Test( 1 ),
);
rpt = obj << Report();
Code Explanation:
- Open data table;
- Run Principal Components analysis.
- Specify variables v1, v2, v3, v4.
- Use default estimation method.
- Analyze correlations.
- Extract first eigenvalue.
- Perform Bartlett test.
- Generate report object.
Example 44
Summary: Runs the principal component analysis (PCA) on a subset of columns in an appliance data table, saving the results with imputation.
Code:
dt = Open("data_table.jmp");
:Al[1 :: 5] = .;
obj1 = dt << Principal Components( Y( 2 :: 16 ) );
obj1 << Save Principal Components with Imputation( 2 );
Code Explanation:
- Open data table;
- Set Al columns 1-5 to missing.
- Perform PCA on columns 2-16.
- Save principal components with imputation.
Example 45
Summary: Runs principal components analysis on a dataset to extract two key components, generating a loading plot and biplot for visual inspection.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( 1 :: 5 ) );
obj << Loading Plot( 2 );
obj << Biplot( 2 );
Code Explanation:
- Open data table;
- Perform principal components analysis.
- Generate loading plot for two components.
- Create biplot for two components.
Example 46
Summary: Performs a principal components analysis on the appliance data, generating a report with loading plots and biplots for 2 variables.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( 1 :: 5 ), Loading Plot( 2 ), Biplot( 2 ) );
obj << {Loading Plot( 0 ), Biplot( 0 )};
rpt = obj << report;
Code Explanation:
- Open data_table data
- Run principal components analysis.
- Set loading plot to 2 variables.
- Set biplot to 2 variables.
- Disable loading plot.
- Disable biplot.
- Generate report object.
Example 47
Summary: Performs a principal components analysis (PCA) on selected variables from an appliance data table, generating summary plots and biplots for visualization.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Y( :OZONE, :CO, :SO2, :NO, :PM10 ),
"on Correlations",
Arrow Lines( 1 ),
Biplot( 2 ),
Loading Plot( 2 ),
);
rpt = obj << report;
obj << Label variables( 0 );
labelCheck = rpt[Outline Box( "Summary Plots" )][CheckBoxBox( 1 )] << get;
biplotLabel = rpt[Outline Box( "Biplot" )][CheckBoxBox( 1 )] << get;
loadingLabel = rpt[Outline Box( "Loading Plot" )][CheckBoxBox( 1 )] << get;
Code Explanation:
- Open table.
- Perform principal components analysis.
- Select variables for analysis.
- Enable correlations display.
- Set arrow lines thickness.
- Generate biplot.
- Create loading plot.
- Retrieve report object.
- Disable variable labels.
- Check summary plots label status.
- Check biplot label status.
- Check loading plot label status.
Example 48
Summary: Analyze a dataset to identify principal components and visualize summary plots, specifically focusing on setosa species data.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Where( :Species == "setosa" ), Y( :Sepal Length, :Sepal Width, :Petal Length, :Petal Width ) );
obj << Save Principal Components( 2 );
obj << Data Table Window;
dt1 = Current Data Table();
Code Explanation:
- Open data table;
- Select rows where Species is setosa.
- Perform Principal Component Analysis.
- Specify variables for analysis.
- Save first two principal components.
- Display data table window.
- Retrieve current data table.
Example 49
Summary: Performs a life distribution analysis using Weibull distribution to analyze appliance data, performing principal component analysis (PCA) on selected columns and generating loading plots and biplots.
Code:
dt = Open("data_table.jmp");
:Al[1 :: 5] = .;
obj1 = dt << Principal Components( Y( 2 :: 16 ) );
obj1 << Save Principal Components with Imputation( 2 );
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( 1 :: 5 ) );
obj << Loading Plot( 2 );
obj << Biplot( 2 );
Code Explanation:
- Open data table;
- Set first 5 Al values to missing.
- Perform PCA on columns 2-16.
- Save PCA with imputation for 2 components.
- Open data table;
- Perform PCA on columns 1-5.
- Create loading plot for 2 components.
- Create biplot for 2 components.
Example 50
Summary: Performs a life distribution analysis using Principal Components and pairwise estimation method to analyze correlations in an appliance data table.
Code:
dt1 = Open("data_table.jmp");
dt1:v1[1] = .;
mv = dt1 << Principal Components(
Y(
:v1, :v2, :v3, :v4, :v5, :v6, :v7, :v8, :v9, :v10, :v11, :v12, :v13, :v14, :v15, :v16, :v17, :v18, :v19, :v20, :v21, :v22, :v23,
:v24, :v25, :v26, :v27
),
Estimation Method( "Pairwise" ),
"on Correlations",
);
mv << Impute Missing Data( 1 );
Close( dt1, No Save );
dt2 = Current Data Table();
v1One = Column( dt2, 1 )[1];
Code Explanation:
- Open data table;
- Set first value of v1 to missing.
- Perform Principal Components analysis.
- Use pairwise estimation method.
- Analyze correlations.
- Impute missing data.
- Close original table without saving.
- Retrieve current data table.
- Assign first value of first column to v1One.
Example 51
Summary: Performs a life distribution analysis using Principal Components to identify patterns in appliance data, with pairwise estimation and missing data imputation.
Code:
dt1 = Open("data_table.jmp");
dt1:v1[1] = .;
mv = dt1 << Principal Components(
Y(
:v1, :v2, :v3, :v4, :v5, :v6, :v7, :v8, :v9, :v10, :v11, :v12, :v13, :v14, :v15, :v16, :v17, :v18, :v19, :v20, :v21, :v22, :v23,
:v24, :v25, :v26, :v27
),
Estimation Method( "Pairwise" ),
"on Correlations",
);
mv << Impute Missing Data( 1 );
Code Explanation:
- Open data table;
- Set first value of v1 to missing.
- Run Principal Components analysis.
- Select variables v1 to v27 for analysis.
- Use pairwise estimation method.
- Analyze correlations.
- Impute missing data.
Example 52
Summary: Creates a Principal Components report from a data table, standardizing variables 'name' and 'sex', and generating summary plots.
Code:
dt2 = Open("data_table.jmp");
obj2 = dt2 << Principal Components( Y( :name, :sex ), Standardize( "Standardized" ) );
rpt2 = Report( obj2 );
jrn2 = rpt2 << get journal;
Code Explanation:
- Open data table;
- Create Principal Components object.
- Specify Y variables: name, sex.
- Standardize data.
- Generate report object.
- Extract journal from report.
Example 53
Summary: Creates and saves two principal components (PCs) from a JMP data table, using standardized variables and eigenvectors.
Code:
dt = Open("data_table.jmp");
obj1 = dt << Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width, :Species ),
Standardize( "Standardized" ),
Eigenvectors( 1 )
);
obj1 << save principal components( 2 );
obj2 = dt << Principal Components(
Y( :Species, :Sepal length, :Sepal width, :Petal length, :Petal width ),
Standardize( "Standardized" ),
Eigenvectors( 1 )
);
obj2 << save principal components( 2 );
Code Explanation:
- Open data table;
- Create PCA object 1.
- Include all variables in PCA.
- Standardize data.
- Set eigenvectors to 1.
- Save first two principal components.
- Create PCA object 2.
- Include Species in PCA.
- Standardize data.
- Set eigenvectors to 1.
- Save first two principal components.
Example 54
Summary: Analyze a dataset using Principal Component Analysis (PCA) to extract meaningful patterns and relationships, generating reports for both sparse and row-wise estimation methods.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components(
Estimation Method( "Sparse" ),
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Number of Components( 4 ),
Eigenvalues( 1 )
);
rpt = obj << report;
obj2 = dt << Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Row-wise" ),
"on Correlations",
Eigenvalues( 1 )
);
rpt2 = obj2 << report;
Code Explanation:
- Open data table;
- Run Sparse PCA analysis.
- Specify variables for analysis.
- Set number of components.
- Request eigenvalues.
- Generate report for Sparse PCA.
- Run Row-wise PCA analysis.
- Specify variables for analysis.
- Use correlations for estimation.
- Request eigenvalues and generate report.
Example 55
Summary: Runs the principal component analysis (PCA) of a dataset to extract two components using the sparse estimation method.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :Name( "pop- m" ), :POP ), Estimation Method( "Sparse" ), Number of Components( 2 ) );
Code Explanation:
- Open table.
- Create principal components object.
- Specify response variables.
- Choose sparse estimation method.
- Set number of components.
Example 56
Summary: Runs the principal component analysis (PCA) of a data table to extract key features and relationships, utilizing row-wise estimation method.
Code:
dt = Open("data_table.jmp");
obj = dt << Principal Components( Y( :age, :height, :weight ), Estimation Method( "Row-wise" ) );
Code Explanation:
- Open table.
- Fit principal components.
Principal Components using Scatterplot 3D
Example 1
Summary: Creates a 3D scatter plot with principal components analysis, biplot rays, and normal contour ellipsoids to visualize relationships between Amplitude, x, and y variables in a data table.
Code:
dt = Open("data_table.jmp");
Scatterplot 3D(
Y( :Amplitude, :x, :y ),
Principal Components( 1 ),
Biplot Rays( 1 ),
Normal Contour Ellipsoids( 1 ),
Frame3D( Set Grab Handles( 0 ), Set Rotation( -60.8796255350304, -1.27222187258541e-14, 38 ) ),
SendToReport(
Dispatch( {}, "1", ScaleBox,
{Scale( "Log" ), Format( "Custom", Formula( value / 0.001 ), 12 ), Min( 0.001 ), Max( 2.06629384326619 ), Inc( 1 ),
Minor Ticks( 1 )}
),
Dispatch( {}, "2", ScaleBox, {Scale( "Power" ), Format( "Custom", Formula( Char( value ) || "''''" ), 12 ), Minor Ticks( 1 )} ),
Dispatch( {}, "3", ScaleBox,
{Scale( "Power" ), Format(
"Custom",
Formula(
Random Reset( 1 );
Round( Random SEV( value ), 3 );
),
12
), Minor Ticks( 1 )}
)
)
);
Code Explanation:
- Open data_table data
- Create 3D scatter plot.
- Use Amplitude, x, y for Y-axis.
- Apply principal components analysis.
- Enable biplot rays.
- Show normal contour ellipsoids.
- Configure 3D frame settings.
- Set grab handles to off.
- Rotate 3D view.
- Customize axis scales and formats.
Example 2
Summary: Creates a 3D scatter plot to visualize relationships between Height, Calf, and Thigh variables, with Waist used for weight and Head variable coloring, utilizing JMP's Scatterplot 3D platform.
Code:
Open("data_table.jmp");
Scatterplot 3D(
Y( :Height, :Calf, :Thigh ),
Weight( :Waist ),
Coloring( :Head ),
Principal Components( 1 ),
Biplot Rays( 0 ),
Sized Points( 1 ),
Legend( 5 ),
Frame3D( Legend( 1 ), ),
SendToReport( Dispatch( {}, "100", ScaleBox, {Legend Model( 5, Properties( 0, {gradient( {Color Theme( "Spectral" )} )} ) )} ) )
);
Code Explanation:
- Open data table.
- Create 3D scatter plot.
- Set Y variables: Height, Calf, Thigh.
- Use Waist for weight.
- Color by Head variable.
- Enable principal components.
- Disable biplot rays.
- Use sized points.
- Set legend to position 5.
- Adjust frame and legend appearance.
Example 3
Summary: Creates and compares a 3D scatterplot report with principal components, biplot rays, and normal contour ellipsoids, incorporating missing value codes and redoing analysis.
Code:
dt = Open("data_table.jmp");
obj = Scatterplot 3D(
Y( :Amplitude, :x, :y ),
Principal Components( 1 ),
Biplot Rays( 1 ),
Normal Contour Ellipsoids( 1 ),
Frame3D( Set Grab Handles( 0 ), Set Rotation( -54, -3.18055468146352e-15, 38 ) )
);
rpt1 = obj << Report;
expr1 = rpt1 << Get Journal;
:Y << Set Property( "Missing Value Codes", 4 );
obj2 = obj << Redo Analysis;
rpt2 = obj2 << Report;
expr2 = rpt2 << Get Journal;
ans = Equal( expr2, expr1 );
Code Explanation:
- Open data table.
- Create 3D scatterplot.
- Configure plot settings.
- Generate initial report.
- Extract initial journal.
- Set missing value code.
- Redo analysis.
- Generate updated report.
- Extract updated journal.
- Compare journals for equality.
Example 4
Summary: Creates a 3D scatterplot to visualize relationships between four variables: ABRASION, MODULUS, ELONG, and HARDNESS.
Code:
dt = Open("data_table.jmp");
obj = Scatterplot 3D(
Y( :Pred Formula ABRASION, :Pred Formula MODULUS, :Pred Formula ELONG, :Pred Formula HARDNESS ),
Principal Components( 1 ),
Biplot Rays( 1 ),
Show Ray Labels( 1 ),
Frame3D( Set Grab Handles( 0 ), Set Rotation( -54, 0, 38 ) )
);
Code Explanation:
- Open data table;
- Create Scatterplot 3D.
- Set Y variables.
- Enable Principal Components.
- Enable Biplot Rays.
- Show Ray Labels.
- Configure Frame3D.
- Disable Grab Handles.
- Set Rotation angles.
- Finalize plot setup.
Example 5
Summary: Creates two 3D scatterplots from a data table, with the first plot colored by Age and the second using principal components, and configures frame settings for both plots.
Code:
cert_levels = {levels( "Age" ), levels( "Age" )};
dt = Open("data_table.jmp");
obj = Scatterplot 3D(
Y( :RunPulse, :RstPulse, :MaxPulse ),
Coloring( :Age ),
Frame3D( Legend( 1 ), Set Grab Handles( 0 ), Set Rotation( -54, 0, 38 ), Set Marker Scale( 4.92625 ) )
);
rpt = obj << report;
Close( dt, nosave );
dt = Open("data_table.jmp");
obj = Scatterplot 3D(
Y( :Pred Formula ABRASION, :Pred Formula MODULUS, :Pred Formula ELONG, :Pred Formula HARDNESS ),
Principal Components( 1 ),
Biplot Rays( 1 ),
Show Ray Labels( 1 ),
Frame3D( Set Grab Handles( 0 ), Set Rotation( -54, 0, 38 ) )
);
Code Explanation:
- Define cert_levels.
- Open data table;
- Create 3D scatterplot.
- Color by Age.
- Configure 3D frame settings.
- Generate report.
- Close data_table.jmp without saving.
- Open data table;
- Create 3D scatterplot.
- Use principal components.
Principal Components using Set Values
Example 1
Summary: Performs a principal components analysis (PCA) on a data table, setting age values to 99 and configuring report settings.
Code:
dt = Open("data_table.jmp");
:"Age (years)" << Set Values( {99, 99, 99} );
obj = Principal Components(
Y(
:Name( "Age (years)" ), :Name( "Weight (lbs)" ), :Name( "Height (inches)" ), :Name( "Neck circumference (cm)" ),
:Name( "Chest circumference (cm)" ), :Name( "Abdomen circumference (cm)" ), :Name( "Hip circumference (cm)" ),
:Name( "Thigh circumference (cm)" ), :Name( "Knee circumference (cm)" ), :Name( "Ankle circumference (cm)" ),
:Name( "Biceps (extended) circumference (cm)" ), :Name( "Forearm circumference (cm)" ), :Name( "Wrist circumference (cm)" )
),
Estimation Method( "Row-wise" ),
"on Correlations",
Eigenvectors( 1 ),
Scree Plot( 1 ),
Arrow Lines( 1 ),
SendToReport(
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox, {Frame Size( 49, 37 )} ),
Dispatch( {"Summary Plots"}, "PCA Summary Plots", FrameBox( 2 ), {Frame Size( 52, 37 )} )
)
);
rpt1 = obj << Report;
expr1 = (rpt1 << get journal());
:"Age (years)" << Set Property( "Missing Value Codes", 99 );
obj2 = obj << Redo Analysis;
rpt2 = obj2 << Report;
expr2 = (rpt2 << get journal());
ans = Equal( expr1, expr2 );
Code Explanation:
- Open data table.
- Set age values to 99.
- Perform principal components analysis.
- Configure PCA settings.
- Generate scree plot.
- Add arrow lines.
- Adjust report size.
- Retrieve first report.
- Save first journal.
- Set missing value code for age.
- Redo PCA analysis.
- Retrieve second report.
- Save second journal.
- Compare two journals.
Example 2
Summary: Runs data manipulation and analysis tasks, including retrieving values, setting missing values, updating tables, and performing Principal Components analysis with score plots.
Code:
dt = Open("data_table.jmp");
newval = dt:Long Jump << get values;
newval[17] = .;
dt:Long Jump << Set Values( newval );
newval = dt:"400m" << get values;
newval[10] = .;
dt:"400m" << Set Values( newval );
obj = dt << Principal Components( Y( 4 :: 13 ) );
obj << Score Plot( 2 );
obj << Score Plot with Imputation( 2 );
Code Explanation:
- Open data table;
- Retrieve Long Jump values.
- Set missing value in Long Jump.
- Update Long Jump values.
- Retrieve 400m values.
- Set missing value in 400m.
- Update 400m values.
- Perform Principal Components analysis.
- Create Score Plot.
- Create Score Plot with Imputation.
Principal Components using Log Capture
Example 1
Summary: Executes four Principal Component Analysis (PCA) methods: Sparse, Wide, Default, and Row-wise, on a specified data table, generating eigenvalues for each method.
Code:
dt = Open("data_table.jmp");
Log Capture(
res = New Window( "PCAs",
H List Box(
obj = dt << Principal Components(
Y( 5 :: 130 ),
Title( "Sparse" ),
Summary Plots( 0 ),
Estimation Method( "Sparse" ),
Number of Components( 100 ),
Eigenvalues
);
obj = dt << Principal Components(
Y( 5 :: 130 ),
Title( "Wide" ),
Summary Plots( 0 ),
Estimation Method( "Wide" ),
Number of Components( 100 ),
Eigenvalues
);
obj = dt << Principal Components(
Y( 5 :: 130 ),
Title( "Default" ),
Summary Plots( 0 ),
Estimation Method( "Default" ),
Number of Components( 100 ),
Eigenvalues
);
obj = dt << Principal Components(
Y( 5 :: 130 ),
Title( "Row-wise" ),
Summary Plots( 0 ),
Estimation Method( "Row-wise" ),
Number of Components( 100 ),
Eigenvalues
);
obj = dt << Principal Components(
Y( 5 :: 130 ),
Title( "ML" ),
Summary Plots( 0 ),
Estimation Method( "ML" ),
Number of Components( 100 ),
Eigenvalues
);
)
)
);
Log Capture(
myEigFun = Function( {method},
{actEig, actEigCumP},
actEig = res[Outline Box( method )][Outline Box( "Eigenvalues" )][Number Col Box( 2 )] << Get as Matrix();
actEigCumP = res[Outline Box( method )][Outline Box( "Eigenvalues" )][Number Col Box( 4 )] << Get as Matrix();
actEig = actEig[1 :: 86];
actEigCumP = actEigCumP[1 :: 86];
myEigMat = actEig || actEigCumP;
)
);
EigMatSparse = myEigFun( "Sparse" );
EigMatWide = myEigFun( "Wide" );
EigMatDef = myEigFun( "Default" );
EigMatRow = myEigFun( "Row-wise" );
Code Explanation:
- Open data table.
- Create new window for PCA results.
- Perform Sparse PCA analysis.
- Perform Wide PCA analysis.
- Perform Default PCA analysis.
- Perform Row-wise PCA analysis.
- Define function to extract eigenvalues.
- Extract eigenvalues for Sparse PCA.
- Extract eigenvalues for Wide PCA.
- Extract eigenvalues for Default PCA.
Example 2
Summary: Executes two Principal Component Analysis (PCA) models on a data table, with sparse and row-wise estimation methods, and extracts eigenvalues from the reports.
Code:
dt_i = Open("data_table.jmp");
dt_i[0, 3] = dt_i[0, 2] / 2;
dt_i[0, 4] = 0;
Log Capture(
obj1 = dt_i << Principal Components(
Y( 1 :: 4 ),
Estimation Method( "Sparse" ),
Number of Components( 3 ),
"on Correlations",
Eigenvectors( 1 ),
Eigenvalues( 1 )
)
);
rpt1 = obj1 << Report();
actEig1 = rpt1[Outline Box( "Eigenvalues" )][Number Col Box( 2 )] << Get As Matrix;
Log Capture(
obj2 = dt_i << Principal Components(
Y( 1 :: 4 ),
Estimation Method( "Row-wise" ),
"on Correlations",
Eigenvectors( 1 ),
Eigenvalues( 1 )
)
);
rpt2 = obj2 << Report();
actEig2 = rpt2[Outline Box( "Eigenvalues" )][Number Col Box( 2 )] << Get As Matrix;
Code Explanation:
- Open data table;
- Modify first row's third column.
- Set first row's fourth column to zero.
- Log capture for sparse PCA.
- Perform sparse PCA on dataset.
- Retrieve PCA report.
- Extract eigenvalues from report.
- Log capture for row-wise PCA.
- Perform row-wise PCA on dataset.
- Retrieve PCA report.
- Extract eigenvalues from report.
Example 3
Summary: Performs principal component analysis (PCA) on a data table, specifying sparse estimation and extracting eigenvalues and cumulative percentages.
Code:
dt = Open("data_table.jmp");
Log Capture(
obj = dt << Principal Components(
Y( :Box, :Name( "# Defects" ), Box Size, :Avg defects ),
Estimation Method( "Sparse" ),
Number of Components( 3 ),
Eigenvalues( 1 )
)
);
rpt = obj << Report();
actEig = rpt[Outline Box( "Eigenvalues" )][Number Col Box( 2 )] << Get As Matrix;
actLastEig = actEig[2];
actCumPer = rpt[Outline Box( "Eigenvalues" )][Number Col Box( 4 )] << Get As Matrix;
actLastCumPer = actCumPer[N Row( actCumPer )];
Code Explanation:
- Open data table;
- Perform principal component analysis.
- Specify variables for analysis.
- Use sparse estimation method.
- Set number of components to 3.
- Request eigenvalues calculation.
- Capture log of analysis results.
- Extract report from analysis object.
- Retrieve eigenvalues from report.
- Extract last eigenvalue and cumulative percentage.
Example 4
Summary: Runs principal components analysis to extract cumulative percentage values from eigenvalues, utilizing sparse estimation method and generating a report.
Code:
dt = Open("data_table.jmp");
Log Capture(
obj = dt << Principal Components(
Y( :Box, :Name( "# Defects" ), :Box Size, :Avg defects ),
Estimation Method( "Sparse" ),
Number of Components( 10 ),
Eigenvalues( 1 )
)
);
rpt = obj << Report();
actCumPer = rpt[Outline Box( "Eigenvalues" )][Number Col Box( 4 )] << Get As Matrix;
actLastCumPer = actCumPer[N Row( actCumPer )];
Code Explanation:
- Open data table;
- Log capture starts.
- Perform principal components analysis.
- Set Y variables: Box, # Defects, Box Size, Avg defects.
- Use sparse estimation method.
- Set number of components to 10.
- Include eigenvalues.
- Generate report from analysis.
- Extract cumulative percentage from eigenvalues.
- Retrieve last cumulative percentage value.
Example 5
Summary: Runs data table manipulation by setting specific cells to missing values and performing principal component analysis with variance estimation on correlations.
Code:
dt_balt = Open("data_table.jmp");
dt_balt[5, 5] = .;
dt_balt[6, 5] = .;
dt_balt[9, 1] = .;
dt_balt[12, 3] = .;
dt_balt[6, 10] = .;
dt_balt[6, 15] = .;
dt_balt[12, 15] = .;
dt_balt[4, 25] = .;
dt_balt[13, 25] = .;
warn = Log Capture(
obj = dt_balt << Principal Components(
Y(
:v1, :v2, :v3, :v4, :v5, :v6, :v7, :v8, :v9, :v10, :v11, :v12, :v13, :v14, :v15, :v16, :v17, :v18, :v19, :v20, :v21, :v22, :v23,
:v24, :v25, :v26, :v27
),
Variance Estimation( "Default" ),
"on Correlations",
Eigenvalues( 1 )
)
);
rpt = obj << report;
Code Explanation:
- Open data table;
- Set cell [5,5] to missing.
- Set cell [6,5] to missing.
- Set cell [9,1] to missing.
- Set cell [12,3] to missing.
- Set cell [6,10] to missing.
- Set cell [6,15] to missing.
- Set cell [12,15] to missing.
- Set cell [4,25] to missing.
- Set cell [13,25] to missing.
Principal Components using If
Example 1
Summary: Runs Principal Components analysis with sparse estimation method on a specified range of columns, generating a report with eigenvalues.
Code:
If( Contains( JMP Product Name(), "Pro" ),
dt = Open("data_table.jmp");
obj = dt << Principal Components( Estimation Method( "Sparse" ), Y( 2 :: 16 ), Number of Components( 5 ), Eigenvalues( 1 ) );
rpt = obj << Report();
numcomps = 5;
actEig = rpt[Outline Box( "Eigenvalues" )][Number Col Box( 2 )] << Get As Matrix;
Close( dt, Nosave );
);
Code Explanation:
- Check if JMP Pro.
- Open data table;
- Run Principal Components analysis.
- Set estimation method to Sparse.
- Specify columns 2 to 16 as Y variables.
- Request 5 components.
- Include eigenvalues in output.
- Retrieve report object.
- Extract eigenvalues matrix.
- Close dataset without saving.
Example 2
Summary: Calculates and visualizes sparse principal components on a data table, generating reports and extracting eigenvalues for analysis.
Code:
If( Contains( JMP Product Name(), "Pro" ),
dt = Open("data_table.jmp");
New Window( "Sparse SVD on data_table",
V List Box(
obj1 = dt << Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Sparse" ),
Number of Components( 4 ),
Eigenvalues( 1 )
);
obj2 = dt << Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Sparse" ),
Number of Components( 4 ),
Eigenvalues( 1 )
);
obj3 = dt << Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Sparse" ),
Number of Components( 4 ),
Eigenvalues( 1 )
);
)
);
rpt1 = obj1 << Report();
rpt2 = obj2 << Report();
rpt3 = obj3 << Report();
eval1 = rpt1[Outline Box( "Eigenvalues" )][Number Col Box( "Eigenvalue" )] << Get As Matrix;
eval2 = rpt2[Outline Box( "Eigenvalues" )][Number Col Box( "Eigenvalue" )] << Get As Matrix;
eval3 = rpt3[Outline Box( "Eigenvalues" )][Number Col Box( "Eigenvalue" )] << Get As Matrix;
Close( dt, Nosave );
);
Code Explanation:
- Check if JMP is Pro.
- Open data table;
- Create new window titled "Sparse SVD on data_table".
- Add vertical list box to window.
- Perform Sparse PCA on data_table data.
- Repeat PCA for three times.
- Generate report for each PCA.
- Extract eigenvalues from each report.
- Convert eigenvalues to matrices.
- Close dataset without saving.
Example 3
Summary: Process of performing Principal Component Analysis (PCA) on a data table with varying weight options and captures report text, suitable for JMP Pro users.
Code:
If( Contains( JMP Product Name(), "Pro" ),
dt = Open("data_table.jmp");
dt << New Column( "weight", Numeric, Continuous, Formula( Random Uniform( .05, 1 ) ) );
Log Capture(
obj = dt << Principal Components(
Y( :Name( "1-Octanol" ), :Ether, :Chloroform, :Benzene, :Carbon Tetrachloride, :Hexane ),
Weight( :weight ),
Variance Estimation( "Wide" ),
"on Correlations"
)
);
rpt = obj << report;
text_act = Try( rpt[Text Box( 1 )] << Get Text );
Log Capture(
obj = dt << Principal Components(
Y( :Name( "1-Octanol" ), :Ether, :Chloroform, :Benzene, :Carbon Tetrachloride, :Hexane ),
Weight( :weight ),
Variance Estimation( "Sparse" ),
Number of Components( 3 ),
"on Correlations"
)
);
rpt = obj << report;
text_act = Try( rpt[Text Box( 1 )] << Get Text );
dt << New Column( "freq", Numeric, Continuous, Formula( Random Integer( 1, 3 ) ) );
Log Capture(
obj = dt << Principal Components(
Y( :Name( "1-Octanol" ), :Ether, :Chloroform, :Benzene, :Carbon Tetrachloride, :Hexane ),
Weight( :freq ),
Variance Estimation( "Sparse" ),
Number of Components( 3 ),
"on Correlations"
)
);
rpt = obj << report;
text_act = Try( rpt[Text Box( 1 )] << Get Text );
Log Capture(
obj = dt << Principal Components(
Y( :Name( "1-Octanol" ), :Ether, :Chloroform, :Benzene, :Carbon Tetrachloride, :Hexane ),
Weight( :freq ),
Variance Estimation( "Sparse" ),
Number of Components( 3 ),
"on Correlations"
)
);
rpt = obj << report;
text_act = Try( rpt[Text Box( 1 )] << Get Text );
Close( dt, nosave );
);
Code Explanation:
- Check if JMP is Pro version.
- Open data table.
- Add "weight" column with random values.
- Perform PCA on selected columns with wide variance estimation.
- Capture PCA report text.
- Perform PCA again with sparse variance estimation and 3 components.
- Capture PCA report text.
- Add "freq" column with random integer values.
- Perform PCA using "freq" as weight.
- Capture PCA report text.
- Perform PCA again with same settings.
- Capture PCA report text.
- Close data table without saving.
Principal Components using Collapse Whitespace
Summary: Runs Principal Components analysis on a data table, capturing log output and comparing it to expected warnings.
Code:
dt = Open("data_table.jmp");
actWarn = Collapse Whitespace(
Log Capture(
dt << Principal Components(
Y( Column Group( "Proteins" ) ),
Variance Estimation( "REML" ),
"on Correlations",
Summary Plots( Label variables( 0 ) )
)
)
);
expWarn = "With 667 columns, we recommend switching to a 'Wide' method. OK?";
actWarn = Collapse Whitespace(
Log Capture(
dt << Principal Components(
Y( Column Group( "Proteins" ) ),
Variance Estimation( "Truncated SVD" ),
Number of Components( 10 ),
"on Correlations",
Summary Plots( Label variables( 0 ) )
)
)
);
expWarn = "";
Code Explanation:
- Open data table;
- Run Principal Components analysis.
- Capture log output.
- Compare log to expected warning.
- Set expected warning to empty.
- Run Principal Components analysis again.
- Capture log output.
- Compare log to expected warning.
- Set expected warning to empty.
- End script.
Principal Components using By
Summary: Performs the principal components analysis on a data table, grouping by sex and generating reports for male and female groups.
Code:
txt1 = "F";
txt2 = "M";
dt = Open("data_table.jmp");
obj = dt << principal components( Y( :height, :weight, :age ), By( :sex ) );
rp1 = Report( obj[1] );
rp2 = Report( obj[2] );
check = Contains( txt2, Expr( title( "sex=M" ) ) ) & Contains( txt1, Expr( title( "sex=F" ) ) );
Code Explanation:
- Assign "F" to txt1.
- Assign "M" to txt2.
- Open data table;
- Perform principal components analysis.
- Set Y variables: height, weight, age.
- Group by sex.
- Create report for sex=M.
- Create report for sex=F.
- Check if title contains "sex=M".
- Check if title contains "sex=F".
Principal Components using Delete Rows
Summary: Prepares data and principal components analysis, capturing the log of the process and retrieving a report.
Code:
dt = Open("data_table.jmp");
dt << Delete Rows( 10 :: N Row( dt ) );
dt[6, 3 :: 6] = .;
dt[8, 5 :: 9] = .;
myLog = Log Capture( obj = dt << Principal Components( Y( 2 :: N Col( dt ) ), Score Plot( 2 ), Score Plot with Imputation( 2 ) ) );
rpt = obj << Report;
Code Explanation:
- Open data table;
- Delete rows 10 to end.
- Set cells [6,3] to [6,6] to missing.
- Set cells [8,5] to [8,9] to missing.
- Capture log of principal components analysis.
- Perform principal components analysis on columns 2 to end.
- Create score plot for first two components.
- Create score plot with imputation for first two components.
- Retrieve report from analysis object.
- Assign report to variable rpt.
Principal Components using New Column
Summary: Fits a standard least squares model with multiple effects and generating a profiler plot, utilizing principal component analysis (PCA) to extract eigenvalues from selected columns.
Code:
dt = Open("data_table.jmp");
dt << New Column( "Freq", Set Values( [0 1 1 1 1 1 1 2 0 . 2 1 1 2 -1 2]` ) );
pc1 = dt << principal components( Y( :v1, :v2, :v3, :v4 ), Freq( :Freq ), Eigenvalues( 1 ), Bartlett Test( 1 ) );
eg1 = Report( pc1 )["Eigenvalues"][Table Box( 1 )] << get as matrix;
dt << Select Where( :Freq == 0 | :Freq == -1 | Is Missing( :Freq ) );
dt << Exclude;
dt << Invert Row Selection;
dtsub = dt << Subset( Selected Rows( 1 ) );
pc3 = dtsub << principal components( Y( :v1, :v2, :v3, :v4 ), Freq( :Freq ), Eigenvalues( 1 ), Bartlett Test( 1 ) );
eg3 = Report( pc3 )["Eigenvalues"][Table Box( 1 )] << get as matrix;
Code Explanation:
- Open data table;
- Add new column "Freq".
- Set values for "Freq" column.
- Run principal component analysis on selected columns.
- Extract eigenvalues from first PCA.
- Select rows where "Freq" is 0, -1, or missing.
- Exclude selected rows.
- Invert row selection.
- Create subset of remaining rows.
- Run principal component analysis on subset.
Principal Components using N Row
Summary: Performs the principal components analysis (PCA) of a data table, capturing log output and collapsing whitespace to identify dropped columns.
Code:
dt = Open("data_table.jmp");
dt[2 :: N Row( dt ), 3] = .;
actWarn = Collapse Whitespace(
Log Capture( dt << Principal Components( Y( :Na, :Br, :Ce, :Co, :Cr, :Cs ), Z( :Al, :Mn ), Loading Matrix( 1 ) ) )
);
expWarn = "One or more columns were dropped because they were non-numeric or constant (no variation). {:Mn}";
Code Explanation:
- Open data table.
- Set selected rows' column 3 to missing.
- Capture log output.
- Perform principal components analysis.
- Specify Y variables: Na, Br, Ce, Co, Cr, Cs.
- Specify Z variable: Al, Mn.
- Request loading matrix.
- Collapse whitespace in log.
- Store captured log in actWarn.
- Define expected warning message in expWarn.
Principal Components using Lock Data Table
Summary: Performs the principal components analysis on a locked data table, capturing log output and removing whitespace to generate expected warning messages.
Code:
dt = Open("data_table.jmp");
dt << Lock Data Table( 1 );
obj = dt << Principal Components( Y( :height, :weight ), Estimation Method( "Row-wise" ), "on Correlations", Arrow Lines( 1 ) );
actWarn = Collapse Whitespace( Log Capture( obj << Save Principal Components( 2 ) ) );
expWarn =
"Cannot make new column in locked data table in access or evaluation of 'Save Principal Components' , Save Principal Components( 2 ) ";
Code Explanation:
- Open data table;
- Lock data table.
- Run principal components analysis.
- Save first two principal components.
- Capture log output.
- Remove whitespace from log.
- Define expected warning message.
Principal Components using For
Example 1
Summary: Generates a principal component analysis (PCA) report for continuous variables in a specified data table, utilizing row-wise estimation and correlation analysis.
Code:
dt = Open("data_table.jmp");
For( i = 1, i <= 4, i++, dt[i, i] = . );
mat = dt << Get as Matrix;
mat = mat[5 :: N Row( mat ), 0];
obj = Principal Components(
Y( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Estimation Method( "Row-wise" ),
"on Correlations"
);
rpt = obj << report;
Code Explanation:
- Open data table;
- Loop through columns 1-4.
- Set diagonal elements to missing.
- Convert data table to matrix.
- Remove first four rows from matrix.
- Perform principal component analysis.
- Specify variables for PCA.
- Use row-wise estimation method.
- Analyze correlations.
- Generate PCA report.
Example 2
Summary: Process of setting every second value to missing in a specified data table, followed by principal components analysis and imputation of missing data.
Code:
dt = Open("data_table.jmp");
For( i = 2, i <= N Cols( dt ), i++,
Column( dt, i )[2 * i :: 2 * (i + 1)] = .
);
obj = dt << Principal Components(
Y( :Al, :Mn, :Na, :Br, :Ce, :Co, :Cr, :Cs, :Eu, :Fe, :Hf, :La, :Sc, :Sm, :U ),
Estimation Method( "Pairwise" ),
"on Correlations"
);
obj << Impute Missing Data;
Code Explanation:
- Open data table.
- Loop through columns starting from 2.
- Set every second value to missing.
- Perform principal components analysis.
- Select specified columns for analysis.
- Use pairwise estimation method.
- Analyze correlations.
- Impute missing data in results.
Example 3
Summary: Process of preparing a data table for Principal Components analysis by setting every second value to missing, performing PCA with pairwise estimation method, and saving imputation formula.
Code:
dt = Open("data_table.jmp");
For( i = N Cols( dt ), i >= 2, i--,
Column( dt, i )[2 * (i - 1) :: 2 * i] = .
);
obj = dt << Principal Components(
Y( :Al, :Mn, :Na, :Br, :Ce, :Co, :Cr, :Cs, :Eu, :Fe, :Hf, :La, :Sc, :Sm, :U ),
Estimation Method( "Pairwise" ),
"on Correlations"
);
obj << Save Imputed Formula;
_mat = (dt << get as matrix( {17 :: N Cols( dt )} ));
obj << Impute Missing Data;
dt1 = Current Data Table();
_mat1 = (dt1 << get as matrix( {1 :: N Cols( dt1 )} ));
Code Explanation:
- Open data table;
- Loop through columns.
- Set every second value to missing.
- Perform Principal Components analysis.
- Use pairwise estimation method.
- Analyze correlations.
- Save imputation formula.
- Extract data matrix.
- Impute missing data.
- Get updated data matrix.
Example 4
Summary: Process of performing Principal Component Analysis (PCA) on selected variables in a data table, imputing missing values, and saving the imputation formula.
Code:
dt = Open("data_table.jmp");
For( i = 2, i <= N Cols( dt ), i++,
Column( dt, i )[2 * i :: 2 * (i + 1)] = .
);
obj = dt << Principal Components(
Y( :Al, :Mn, :Na, :Br, :Ce, :Co, :Cr, :Cs, :Eu, :Fe, :Hf, :La, :Sc, :Sm, :U ),
Estimation Method( "Pairwise" ),
"on Correlations"
);
obj << Impute Missing Data;
dt = Open("data_table.jmp");
For( i = N Cols( dt ), i >= 2, i--,
Column( dt, i )[2 * (i - 1) :: 2 * i] = .
);
obj = dt << Principal Components(
Y( :Al, :Mn, :Na, :Br, :Ce, :Co, :Cr, :Cs, :Eu, :Fe, :Hf, :La, :Sc, :Sm, :U ),
Estimation Method( "Pairwise" ),
"on Correlations"
);
obj << Save Imputed Formula;
_mat = (dt << get as matrix( {17 :: N Cols( dt )} ));
obj << Impute Missing Data;
dt1 = Current Data Table();
_mat1 = (dt1 << get as matrix( {1 :: N Cols( dt1 )} ));
Code Explanation:
- Open data table;
- Loop through columns 2 to end.
- Set every second value to missing.
- Perform PCA on selected variables.
- Impute missing data.
- Reopen data_table dataset
- Loop through columns end to 2.
- Set every second value to missing.
- Perform PCA on selected variables.
- Save imputation formula.
Principal Components using Select Rows
Summary: Runs a Principal Components analysis to extract insights from the Iris dataset, utilizing row-wise estimation and standardized variables.
Code:
dt = Open("data_table.jmp");
:Petal width[1] = .;
r = dt << Select Rows( [1, 2, 3, 4, 5] );
r << Exclude;
obj = dt << Principal Components(
Y( :Sepal length, :Sepal width, :Petal length ),
Z( :Petal width ),
Estimation Method( "Row-wise" ),
Standardize( "Standardized" ),
Loading Matrix( Plot of Loading Matrix( Overview( 3 ), "Side by side" ) ),
Partial Contribution of Variables( Plot of Partial Contribution of Variables( Overview( 3 ), "Side by side" ) )
);
rpt = Report( obj );
obj << Save Individual Partial Contributions( 3 );
UnexcludedPartCont1exp = UnexcludedPartCont2exp = UnexcludedPartCont3exp = 100;
UnexcludedPartCont1act = Sum( dt[1 :: 5, 6] );
UnexcludedPartCont2act = Sum( dt[1 :: 5, 7] );
UnexcludedPartCont3act = Sum( dt[1 :: 5, 8] );
Code Explanation:
- Open data table;
- Set Petal width missing for row 1.
- Select rows 1-5.
- Exclude selected rows.
- Run Principal Components analysis.
- Use Sepal length, width, Petal length as Y variables.
- Use Petal width as Z variable.
- Set Row-wise estimation method.
- Standardize variables.
- Generate loading matrix plot.