Factor Analysis Action Set
Using Multiple Criteria To Determine the Number of Factors
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts. A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
This example uses the jobratings data set that is described in the examples for the FACTOR procedure in SAS/STAT software. In the original data set, 103 police officers were rated by their supervisors on 14 scales (variables). In the current example one of these scales, the overall rating variable, is excluded.
To create the jobratings data table in your CAS session, you can modify the DATA step that is used to create the data set to create the data table in your CAS engine libref. For this example, it is assumed that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
As the first step in a common factor analysis, you want to determine the number of latent factors that are likely to explain the data. The following code performs this analysis:
proc cas;
factorAnalysis.faNFactors /
criteria={{status="inactive", threshold={0.5, 1, 1.5}, type="eigenvalue"},
{alpha={0.05, 0.1},
nSims={20000},
seed={1031, 1128},
type="parallel"},
{status="inactive", threshold={0.9, 0.95}, type="proportion"},
{status="inactive", type="map2"},
{status="inactive", type="map4"}},
nFactors="mean",
priors="asmc",
table="jobratings";
run;
When you use the faNFactors action, you must specify values for the table and criteria parameters. You specify the input data table to use for the analysis in the table parameter. You use the criteria parameter to specify one or more criteria that the action uses to determine the number of factors or components to retain. In this example, you specify several different types of criteria. For the minimum eigenvalue, cumulative proportion, and minimum average partial correlation criteria, the status parameter is set to "inactive". This means that the results for these criteria are displayed for informational purposes but not used to determine the final number of factors for the analysis. You use the priors parameter to specify adjusted squared multiple correlations for the prior communality estimates to be applied for the minimum eigenvalue and cumulative proportion criteria.
To determine the number of factors, you use a parallel analysis with 20,000 simulations. To assess the robustness of the analysis, you include two different thresholds for the parallel analysis and two different random number seeds. Because you specify two values for the alpha parameter and two values for the seed parameter, the action performs a total of four parallel analyses. You use the nFactors parameter to specify that the final number of factors for the overall analysis is the mean of the four parallel analysis criteria.
The output from this analysis is displayed in Output 10.2.1 through Output 10.2.10.
The "Number of Observations" table in Output 10.2.1 summarizes the number of observations that are read from the input data table and the number of observations that are used for the analysis. This table is displayed by default. For this analysis, these two numbers are the same. These numbers would be different if some observations were discarded from the analysis. The faNFactors action uses only complete cases for analysis, so a record is discarded if any field contains a missing value.
Output 10.2.1: Number of Observations
| Number of Observations Read | 103 |
|---|---|
| Number of Observations Used | 103 |
The "Simple Statistics" table in Output 10.2.2 summarizes the means and standard deviations of the variables that are included in the analysis. This table is displayed by default.
Output 10.2.2: Simple Statistics
| Simple Statistics | ||
|---|---|---|
| Variable | Mean | Standard Deviation |
| Communication Skills | 6.65049 | 1.76407 |
| Problem Solving | 6.63107 | 1.59035 |
| Learning Ability | 6.99029 | 1.33941 |
| Judgment under Pressure | 6.73786 | 1.73183 |
| Observational Skills | 6.93204 | 1.76158 |
| Willingness to Confront Problems | 7.29126 | 1.52516 |
| Interest in People | 6.70874 | 1.89235 |
| Interpersonal Sensitivity | 6.62136 | 1.76077 |
| Desire for Self-Improvement | 6.57282 | 1.72980 |
| Appearance | 7.00000 | 1.79869 |
| Dependability | 6.82524 | 1.91704 |
| Physical Ability | 7.20388 | 1.55525 |
| Integrity | 7.21359 | 1.84524 |
The primary output for the analysis is shown in the "Determination of Number of Factors" table in Output 10.2.3. This table is displayed by default. For most of the specified criteria, the results suggest that two latent factors should be retained to explain the data. The minimum eigenvalue criterion, with a threshold of 0.50, and the cumulative proportion criterion, with a threshold of 0.95, suggest the existence of a third latent variable. All four parallel analysis criteria suggest two latent factors, so the final number of latent factors that are suggested by the analysis is two.
You can use the following code to directly access this final result:
factorAnalysis_faNFactors result=r /
criteria={
{type='eigenvalue', threshold={0.50,1.00,1.50}, status='inactive'},
{type='parallel', alpha={0.05,0.10}, nSims={20000}, seed={1031,1128}},
{type='proportion', threshold={0.90,0.95}, status='inactive'},
{type='map2', status='inactive'},
{type='map4', status='inactive'}
},
nFactors='mean',
priors='asmc',
table='jobratings';
run;
print r.nFactorsByGroup;
run;
Output 10.2.3: Number of Factors
| Determination of Number of Factors | ||
|---|---|---|
| Criterion | Description | Factors |
| 1 | Minimum Eigenvalue (Eigenvalue > 0.50) | 3 |
| 2 | Minimum Eigenvalue (Eigenvalue > 1.00) | 2 |
| 3 | Minimum Eigenvalue (Eigenvalue > 1.50) | 2 |
| 4 | Parallel Analysis (Alpha = 0.05, Seed = 1031, Sims = 20000) | 2 |
| 5 | Parallel Analysis (Alpha = 0.05, Seed = 1128, Sims = 20000) | 2 |
| 6 | Parallel Analysis (Alpha = 0.10, Seed = 1031, Sims = 20000) | 2 |
| 7 | Parallel Analysis (Alpha = 0.10, Seed = 1128, Sims = 20000) | 2 |
| 8 | Total Proportion (Threshold = 0.90) | 2 |
| 9 | Total Proportion (Threshold = 0.95) | 3 |
| 10 | Min Ave Squared Partial Corr (MAP2) | 2 |
| 11 | Min Ave 4th-powered Partial Corr (MAP4) | 2 |
| Min = 2, Max = 2, Mean = 2, Median = 2 | ||
Additional information about the minimum eigenvalue and cumulative proportion criteria is presented in the "Eigenvalues of the Reduced Correlation Matrix" table in Output 10.2.4. This table is displayed by default. After the data correlation matrix is reduced by replacing its diagonal elements with the ASMC prior communality estimates, the largest eigenvalue of the resulting matrix is approximately 6.21, and the corresponding latent factor explains approximately 73% of the common variance of the input data. The second eigenvalue is approximately 1.50, and the latent factors that correspond to these first two eigenvalues explain approximately 90% of the common variance. A third eigenvalue has a value of approximately 0.60, and the latent factors that correspond to these three eigenvalues explain more than 97% of the common variance. From this table, it is clear that two latent factors are sufficient to explain up to 90% of the common variance in the input data, and that a third factor is needed to explain more than 95% of the common variance. Similarly, a minimum eigenvalue threshold of 1.50 or 1.00 produces an estimate of two latent factors, whereas a third latent factor is estimated if the minimum eigenvalue threshold is 0.50. (The fourth-largest eigenvalue for the reduced correlation matrix has a value of approximately 0.31.)
Output 10.2.4: Eigenvalues and Variance Explained
| Eigenvalues of the Reduced Correlation Matrix | ||||
|---|---|---|---|---|
| Eigenvalue | Difference | Proportion | Cumulative | |
| 1 | 6.216813 | 4.711586 | 0.7258 | 0.7258 |
| 2 | 1.505227 | 0.909106 | 0.1757 | 0.9015 |
| 3 | 0.596120 | 0.282313 | 0.0696 | 0.9711 |
| 4 | 0.313807 | 0.047022 | 0.0366 | 1.0078 |
| 5 | 0.266785 | 0.157610 | 0.0311 | 1.0389 |
| 6 | 0.109175 | 0.073777 | 0.0127 | 1.0517 |
| 7 | 0.035398 | 0.030976 | 0.0041 | 1.0558 |
| 8 | 0.004422 | 0.050335 | 0.0005 | 1.0563 |
| 9 | -0.045913 | 0.021721 | -0.0054 | 1.0510 |
| 10 | -0.067634 | 0.018736 | -0.0079 | 1.0431 |
| 11 | -0.086370 | 0.025395 | -0.0101 | 1.0330 |
| 12 | -0.111765 | 0.058945 | -0.0130 | 1.0199 |
| 13 | -0.170710 | -0.0199 | 1.0000 | |
The parallel analysis results are summarized in the "Parallel Analysis" tables in Output 10.2.5 through Output 10.2.8. A "Parallel Analysis" table is displayed by the faNFactors action any time you specify at least one parallel analysis criterion. For each of the four specified parallel analysis criteria, correlation matrices are simulated from a Wishart distribution. These simulations represent correlation matrices that might be realized for a data-generating process in which all variables are independently and identically distributed according to the standard normal distribution. The eigenvalues of the simulated correlation matrices are computed and rank-ordered, and the eigenvalues of the input data correlation matrix are compared to the distributions of the eigenvalues at each position (largest eigenvalue, second-largest eigenvalue, and so on). When an eigenvalue of the input data correlation matrix exceeds the eigenvalue at some critical point (for example, the 95th percentile), this is understood to indicate the presence of a latent factor in the data. In all four parallel analyses in this example, the largest and second-largest eigenvalues for the input data correlation matrix exceed the simulated critical values. Thus all four parallel analyses suggest that two latent factors should be retained.
Output 10.2.5: Parallel Analysis
| Parallel Analysis (Criterion 4) | ||
|---|---|---|
| Component | Simulated Crit Val | Observed Eigenvalue |
| 1 | 1.8013 | 6.5474* |
| 2 | 1.5787 | 1.7727* |
| 3 | 1.4319 | 1.0052 |
| 4 | 1.3128 | 0.7431 |
| 5 | 1.2082 | 0.6783 |
| 6 | 1.1152 | 0.4514 |
| 7 | 1.0299 | 0.3822 |
| 8 | 0.9505 | 0.2978 |
| 9 | 0.8721 | 0.2744 |
| 10 | 0.7985 | 0.2623 |
| 11 | 0.7227 | 0.2446 |
| 12 | 0.6476 | 0.1978 |
| 13 | 0.5648 | 0.1427 |
| * Retained Dimension (Obs > Crit) | ||
Output 10.2.6: Parallel Analysis
| Parallel Analysis (Criterion 5) | ||
|---|---|---|
| Component | Simulated Crit Val | Observed Eigenvalue |
| 1 | 1.7976 | 6.5474; |
| 2 | 1.5797 | 1.7727; |
| 3 | 1.4308 | 1.0052 |
| 4 | 1.3127 | 0.7431 |
| 5 | 1.2092 | 0.6783 |
| 6 | 1.1155 | 0.4514 |
| 7 | 1.0294 | 0.3822 |
| 8 | 0.9492 | 0.2978 |
| 9 | 0.8725 | 0.2744 |
| 10 | 0.7980 | 0.2623 |
| 11 | 0.7234 | 0.2446 |
| 12 | 0.6478 | 0.1978 |
| 13 | 0.5643 | 0.1427 |
| * Retained Dimension (Obs > Crit) | ||
Output 10.2.7: Parallel Analysis
| Parallel Analysis (Criterion 6) | ||
|---|---|---|
| Component | Simulated Crit Val | Observed Eigenvalue |
| 1 | 1.7614 | 6.5474; |
| 2 | 1.5511 | 1.7727; |
| 3 | 1.4106 | 1.0052 |
| 4 | 1.2943 | 0.7431 |
| 5 | 1.1929 | 0.6783 |
| 6 | 1.1007 | 0.4514 |
| 7 | 1.0166 | 0.3822 |
| 8 | 0.9366 | 0.2978 |
| 9 | 0.8591 | 0.2744 |
| 10 | 0.7844 | 0.2623 |
| 11 | 0.7092 | 0.2446 |
| 12 | 0.6330 | 0.1978 |
| 13 | 0.5495 | 0.1427 |
| * Retained Dimension (Obs > Crit) | ||
Output 10.2.8: Parallel Analysis
| Parallel Analysis (Criterion 7) | ||
|---|---|---|
| Component | Simulated Crit Val | Observed Eigenvalue |
| 1 | 1.7590 | 6.5474; |
| 2 | 1.5541 | 1.7727; |
| 3 | 1.4093 | 1.0052 |
| 4 | 1.2942 | 0.7431 |
| 5 | 1.1935 | 0.6783 |
| 6 | 1.1012 | 0.4514 |
| 7 | 1.0155 | 0.3822 |
| 8 | 0.9357 | 0.2978 |
| 9 | 0.8595 | 0.2744 |
| 10 | 0.7842 | 0.2623 |
| 11 | 0.7091 | 0.2446 |
| 12 | 0.6333 | 0.1978 |
| 13 | 0.5488 | 0.1427 |
| * Retained Dimension (Obs > Crit) | ||
The minimum average partial correlation analysis (MAP) results are summarized in the "Average Partial Correlations Controlling Principal Components" table in Output 10.2.9. This table is displayed by the faNFactors action any time you specify a minimum average partial correlation criterion. In this example, analyses are performed that use both squared (MAP2) and fourth-powered (MAP4) partial correlations. These two analyses are summarized in separate columns in the table. The number of latent factors that are estimated by a minimum average partial correlation analysis is the number of principal components that, when partialed out of the correlation matrix, produce the smallest average squared or fourth-powered partial correlations. As shown in Output 10.2.9, the minimum value is obtained for both the MAP2 and the MAP4 analysis when two principal components are partialed out.
Output 10.2.9: Minimum Average Partial Correlation Analysis
| Average Partial Correlations Controlling Principal Components | ||
|---|---|---|
| Number of Components | Squared | Fourth- Powered |
| 0 | 0.229076 | 0.069057 |
| 1 | 0.063655 | 0.011875 |
| 2 | 0.036328* | 0.003287* |
| 3 | 0.042970 | 0.004975 |
| 4 | 0.057102 | 0.009267 |
| 5 | 0.065326 | 0.014253 |
| 6 | 0.083345 | 0.022845 |
| 7 | 0.115706 | 0.037743 |
| 8 | 0.153423 | 0.050831 |
| 9 | 0.233063 | 0.120901 |
| 10 | 0.309145 | 0.167278 |
| 11 | 0.544163 | 0.416722 |
| 12 | 1.000000 | 1.000000 |
| * MAP = Minimum Values in Columns | ||
Finally, the faNFactors action displays the table shown in Output 10.2.10, which shows the amount of time (in seconds) that it took to perform the various tasks of the analysis.
Output 10.2.10: Analysis Timing
| Task Timing | ||
|---|---|---|
| Task | Seconds | Percent |
| Initializing | 0.02 | 1.94% |
| Parsing | 0.00 | 0.00% |
| Calculating Correlations | 0.01 | 1.27% |
| Determining Number of Factors | 0.00 | 0.02% |
| Miscellaneous | 1.00 | 96.76% |
| Cleaning Up | 0.00 | 0.01% |
| Total | 1.03 | 100.00% |
Using Multiple Criteria To Determine the Number of Factors
This section contains Lua code that creates the same jobratings table and performs the same analysis as shown in the CASL version of this example. For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
Because this example uses simulated data that are produced from DATA step code, you can submit the runCode action on your Lua client to create the simulated data in your CAS session.
This example uses the jobratings data set that is described in the examples for the FACTOR procedure in SAS/STAT software. In the original data set, 103 police officers were rated by their supervisors on 14 scales (variables). In the current example one of these scales, the overall rating variable, is excluded.
To run this example code, you must make the jobratings data accessible to the CAS server. One way to do this is to convert the jobratings data set from the PROC FACTOR documentation to a comma-separated-value (CSV) file and then load the CSV file into CAS.
As the first step in a common factor analysis, you want to determine the number of latent factors that are likely to explain the data. The following code performs this analysis:
s:loadactionset{actionset="factorAnalysis"}
s:factorAnalysis_faNFactors{
table='jobratings',
criteria={
{type='eigenvalue', threshold={0.50,1.00,1.50}, status='inactive'},
{type='parallel', alpha={0.05,0.10}, nSims={20000}, seed={1031,1128}},
{type='proportion', threshold={0.90,0.95}, status='inactive'},
{type='map2', status='inactive'},
{type='map4', status='inactive'}
},
nFactors='mean',
priors='asmc'
}
When you use the faNFactors action, you must specify values for the table and criteria parameters. You specify the input data table to use for the analysis in the table parameter. You use the criteria parameter to specify one or more criteria that the action uses to determine the number of factors or components to retain. In this example, you specify several different types of criteria. For the minimum eigenvalue, cumulative proportion, and minimum average partial correlation criteria, the status parameter is set to "inactive". This means that the results for these criteria are displayed for informational purposes but not used to determine the final number of factors for the analysis. You use the priors parameter to specify adjusted squared multiple correlations for the prior communality estimates to be applied for the minimum eigenvalue and cumulative proportion criteria.
To determine the number of factors, you use a parallel analysis with 20,000 simulations. To assess the robustness of the analysis, you include two different thresholds for the parallel analysis and two different random number seeds. Because you specify two values for the alpha parameter and two values for the seed parameter, the action performs a total of four parallel analyses. You use the nFactors parameter to specify that the final number of factors for the overall analysis is the mean of the four parallel analysis criteria.
The output from this analysis is displayed in Output 10.2.11 through Output 10.2.20.
The "Number of Observations" table in Output 10.2.11 summarizes the number of observations that are read from the input data table and the number of observations that are used for the analysis. This table is displayed by default. For this analysis, these two numbers are the same. These numbers would be different if some observations were discarded from the analysis. The faNFactors action uses only complete cases for analysis, so a record is discarded if any field contains a missing value.
Output 10.2.11: Number of Observations
| RowId | Description | Value |
|---|---|---|
| NREAD | Number of Observations Read | 103 |
| NUSED | Number of Observations Used | 103 |
The "Simple Statistics" table in Output 10.2.12 summarizes the means and standard deviations of the variables that are included in the analysis. This table is displayed by default.
Output 10.2.12: Simple Statistics
| Variable | Mean | StdDev |
|---|---|---|
| Communication Skills | 6.65049 | 1.76407 |
| Problem Solving | 6.63107 | 1.59035 |
| Learning Ability | 6.99029 | 1.33941 |
| Judgment under Pressure | 6.73786 | 1.73183 |
| Observational Skills | 6.93204 | 1.76158 |
| Willingness to Confront Problems | 7.29126 | 1.52516 |
| Interest in People | 6.70874 | 1.89235 |
| Interpersonal Sensitivity | 6.62136 | 1.76077 |
| Desire for Self-Improvement | 6.57282 | 1.72980 |
| Appearance | 7.00000 | 1.79869 |
| Dependability | 6.82524 | 1.91704 |
| Physical Ability | 7.20388 | 1.55525 |
| Integrity | 7.21359 | 1.84524 |
The primary output for the analysis is shown in the "Determination of Number of Factors" table in Output 10.2.13. This table is displayed by default. For most of the specified criteria, the results suggest that two latent factors should be retained to explain the data. The minimum eigenvalue criterion, with a threshold of 0.50, and the cumulative proportion criterion, with a threshold of 0.95, suggest the existence of a third latent variable. All four parallel analysis criteria suggest two latent factors, so the final number of latent factors that are suggested by the analysis is two.
You can access this final result by specifying the "nFactorsByGroup" key in the results dictionary that is produced by the faNFactors action.
Output 10.2.13: Number of Factors
| Criterion | Description | NFactors | Threshold | Simulations | Seed | Status |
|---|---|---|---|---|---|---|
| 1 | Minimum Eigenvalue (Eigenvalue > 0.50) | 3 | 0.50 | _ | _ | 0 |
| 2 | Minimum Eigenvalue (Eigenvalue > 1.00) | 2 | 1.00 | _ | _ | 0 |
| 3 | Minimum Eigenvalue (Eigenvalue > 1.50) | 2 | 1.50 | _ | _ | 0 |
| 4 | Parallel Analysis (Alpha = 0.05, Seed = 1031, Sims = 20000) | 2 | 0.05 | 20000 | 1031 | 1 |
| 5 | Parallel Analysis (Alpha = 0.05, Seed = 1128, Sims = 20000) | 2 | 0.05 | 20000 | 1128 | 1 |
| 6 | Parallel Analysis (Alpha = 0.10, Seed = 1031, Sims = 20000) | 2 | 0.10 | 20000 | 1031 | 1 |
| 7 | Parallel Analysis (Alpha = 0.10, Seed = 1128, Sims = 20000) | 2 | 0.10 | 20000 | 1128 | 1 |
| 8 | Total Proportion (Threshold = 0.90) | 2 | 0.90 | _ | _ | 0 |
| 9 | Total Proportion (Threshold = 0.95) | 3 | 0.95 | _ | _ | 0 |
| 10 | Min Ave Squared Partial Corr (MAP2) | 2 | _ | _ | _ | 0 |
| 11 | Min Ave 4th-powered Partial Corr (MAP4) | 2 | _ | _ | _ | 0 |
Additional information about the minimum eigenvalue and cumulative proportion criteria is presented in the "Eigenvalues of the Reduced Correlation Matrix" table in Output 10.2.14. This table is displayed by default. After the data correlation matrix is reduced by replacing its diagonal elements with the ASMC prior communality estimates, the largest eigenvalue of the resulting matrix is approximately 6.21, and the corresponding latent factor explains approximately 73% of the common variance of the input data. The second eigenvalue is approximately 1.50, and the latent factors that correspond to these first two eigenvalues explain approximately 90% of the common variance. A third eigenvalue has a value of approximately 0.60, and the latent factors that correspond to these three eigenvalues explain more than 97% of the common variance. From this table, it is clear that two latent factors are sufficient to explain up to 90% of the common variance in the input data, and that a third factor is needed to explain more than 95% of the common variance. Similarly, a minimum eigenvalue threshold of 1.50 or 1.00 produces an estimate of two latent factors, whereas a third latent factor is estimated if the minimum eigenvalue threshold is 0.50. (The fourth-largest eigenvalue for the reduced correlation matrix has a value of approximately 0.31.)
Output 10.2.14: Eigenvalues and Variance Explained
| Number | Eigenvalue | Difference | Proportion | Cumulative |
|---|---|---|---|---|
| 1 | 6.216813 | 4.711586 | 0.7258 | 0.7258 |
| 2 | 1.505227 | 0.909106 | 0.1757 | 0.9015 |
| 3 | 0.596120 | 0.282313 | 0.0696 | 0.9711 |
| 4 | 0.313807 | 0.047022 | 0.0366 | 1.0078 |
| 5 | 0.266785 | 0.157610 | 0.0311 | 1.0389 |
| 6 | 0.109175 | 0.073777 | 0.0127 | 1.0517 |
| 7 | 0.035398 | 0.030976 | 0.0041 | 1.0558 |
| 8 | 0.004422 | 0.050335 | 0.0005 | 1.0563 |
| 9 | -0.045913 | 0.021721 | -0.0054 | 1.0510 |
| 10 | -0.067634 | 0.018736 | -0.0079 | 1.0431 |
| 11 | -0.086370 | 0.025395 | -0.0101 | 1.0330 |
| 12 | -0.111765 | 0.058945 | -0.0130 | 1.0199 |
| 13 | -0.170710 | _ | -0.0199 | 1.0000 |
The parallel analysis results are summarized in the "Parallel Analysis" tables in Output 10.2.15 through Output 10.2.18. A "Parallel Analysis" table is displayed by the faNFactors action any time you specify at least one parallel analysis criterion. For each of the four specified parallel analysis criteria, correlation matrices are simulated from a Wishart distribution. These simulations represent correlation matrices that might be realized for a data-generating process in which all variables are independently and identically distributed according to the standard normal distribution. The eigenvalues of the simulated correlation matrices are computed and rank-ordered, and the eigenvalues of the input data correlation matrix are compared to the distributions of the eigenvalues at each position (largest eigenvalue, second-largest eigenvalue, and so on). When an eigenvalue of the input data correlation matrix exceeds the eigenvalue at some critical point (for example, the 95th percentile), this is understood to indicate the presence of a latent factor in the data. In all four parallel analyses in this example, the largest and second-largest eigenvalues for the input data correlation matrix exceed the simulated critical values. Thus all four parallel analyses suggest that two latent factors should be retained.
Output 10.2.15: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
Output 10.2.16: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
Output 10.2.17: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
Output 10.2.18: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
The minimum average partial correlation analysis (MAP) results are summarized in the "Average Partial Correlations Controlling Principal Components" table in Output 10.2.19. This table is displayed by the faNFactors action any time you specify a minimum average partial correlation criterion. In this example, analyses are performed that use both squared (MAP2) and fourth-powered (MAP4) partial correlations. These two analyses are summarized in separate columns in the table. The number of latent factors that are estimated by a minimum average partial correlation analysis is the number of principal components that, when partialed out of the correlation matrix, produce the smallest average squared or fourth-powered partial correlations. As shown in Output 10.2.19, the minimum value is obtained for both the MAP2 and the MAP4 analysis when two principal components are partialed out.
Output 10.2.19: Minimum Average Partial Correlation Analysis
| NComp | AveParCor2 | OptAveParCor2 | AveParCor4 | OptAveParCor4 |
|---|---|---|---|---|
| 0 | 0.229076 | 0 | 0.069057 | 0 |
| 1 | 0.063655 | 0 | 0.011875 | 0 |
| 2 | 0.036328 | 1 | 0.003287 | 1 |
| 3 | 0.042970 | 0 | 0.004975 | 0 |
| 4 | 0.057102 | 0 | 0.009267 | 0 |
| 5 | 0.065326 | 0 | 0.014253 | 0 |
| 6 | 0.083345 | 0 | 0.022845 | 0 |
| 7 | 0.115706 | 0 | 0.037743 | 0 |
| 8 | 0.153423 | 0 | 0.050831 | 0 |
| 9 | 0.233063 | 0 | 0.120901 | 0 |
| 10 | 0.309145 | 0 | 0.167278 | 0 |
| 11 | 0.544163 | 0 | 0.416722 | 0 |
| 12 | 1.000000 | 0 | 1.000000 | 0 |
Finally, the faNFactors action displays the table shown in Output 10.2.20, which shows the amount of time (in seconds) that it took to perform the various tasks of the analysis.
Output 10.2.20: Analysis Timing
| RowId | Task | Time | RelTime |
|---|---|---|---|
| INIT | Initializing | 0.02 | 1.94% |
| PARSE | Parsing | 0.00 | 0.00% |
| CORR | Calculating Correlations | 0.01 | 1.27% |
| NFACT | Determining Number of Factors | 0.00 | 0.02% |
| MISC | Miscellaneous | 1.00 | 96.76% |
| CLEANUP | Cleaning Up | 0.00 | 0.01% |
| TOTAL | Total | 1.03 | 100.00% |
Using Multiple Criteria To Determine the Number of Factors
This section contains Python code that creates the same jobratings table and performs the same analysis as shown in the CASL version of this example. For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
Because this example uses simulated data that are produced from DATA step code, you can submit the runCode action on your Python client to create the simulated data in your CAS session.
This example uses the jobratings data set that is described in the examples for the FACTOR procedure in SAS/STAT software. In the original data set, 103 police officers were rated by their supervisors on 14 scales (variables). In the current example one of these scales, the overall rating variable, is excluded.
To run this example code, you must make the jobratings data accessible to the CAS server. One way to do this is to convert the jobratings data set from the PROC FACTOR documentation to a comma-separated-value (CSV) file and then load the CSV file into CAS.
As the first step in a common factor analysis, you want to determine the number of latent factors that are likely to explain the data. The following code performs this analysis:
s.loadactionset(actionset='factorAnalysis')
s.factoranalysis.fanfactors(
criteria=[dict(status='inactive',
threshold=[0.5, 1, 1.5],
type='eigenvalue'),
dict(alpha=[0.05, 0.1],
nSims=[20000],
seed=[1031, 1128],
type='parallel'),
dict(status='inactive', threshold=[0.9, 0.95], type='proportion'),
dict(status='inactive', type='map2'),
dict(status='inactive', type='map4')],
nFactors='mean',
priors='asmc',
table='jobratings')
When you use the faNFactors action, you must specify values for the table and criteria parameters. You specify the input data table to use for the analysis in the table parameter. You use the criteria parameter to specify one or more criteria that the action uses to determine the number of factors or components to retain. In this example, you specify several different types of criteria. For the minimum eigenvalue, cumulative proportion, and minimum average partial correlation criteria, the status parameter is set to "inactive". This means that the results for these criteria are displayed for informational purposes but not used to determine the final number of factors for the analysis. You use the priors parameter to specify adjusted squared multiple correlations for the prior communality estimates to be applied for the minimum eigenvalue and cumulative proportion criteria.
To determine the number of factors, you use a parallel analysis with 20,000 simulations. To assess the robustness of the analysis, you include two different thresholds for the parallel analysis and two different random number seeds. Because you specify two values for the alpha parameter and two values for the seed parameter, the action performs a total of four parallel analyses. You use the nFactors parameter to specify that the final number of factors for the overall analysis is the mean of the four parallel analysis criteria.
The output from this analysis is displayed in Output 10.2.21 through Output 10.2.30.
The "Number of Observations" table in Output 10.2.21 summarizes the number of observations that are read from the input data table and the number of observations that are used for the analysis. This table is displayed by default. For this analysis, these two numbers are the same. These numbers would be different if some observations were discarded from the analysis. The faNFactors action uses only complete cases for analysis, so a record is discarded if any field contains a missing value.
Output 10.2.21: Number of Observations
| RowId | Description | Value |
|---|---|---|
| NREAD | Number of Observations Read | 103 |
| NUSED | Number of Observations Used | 103 |
The "Simple Statistics" table in Output 10.2.22 summarizes the means and standard deviations of the variables that are included in the analysis. This table is displayed by default.
Output 10.2.22: Simple Statistics
| Variable | Mean | StdDev |
|---|---|---|
| Communication Skills | 6.65049 | 1.76407 |
| Problem Solving | 6.63107 | 1.59035 |
| Learning Ability | 6.99029 | 1.33941 |
| Judgment under Pressure | 6.73786 | 1.73183 |
| Observational Skills | 6.93204 | 1.76158 |
| Willingness to Confront Problems | 7.29126 | 1.52516 |
| Interest in People | 6.70874 | 1.89235 |
| Interpersonal Sensitivity | 6.62136 | 1.76077 |
| Desire for Self-Improvement | 6.57282 | 1.72980 |
| Appearance | 7.00000 | 1.79869 |
| Dependability | 6.82524 | 1.91704 |
| Physical Ability | 7.20388 | 1.55525 |
| Integrity | 7.21359 | 1.84524 |
The primary output for the analysis is shown in the "Determination of Number of Factors" table in Output 10.2.23. This table is displayed by default. For most of the specified criteria, the results suggest that two latent factors should be retained to explain the data. The minimum eigenvalue criterion, with a threshold of 0.50, and the cumulative proportion criterion, with a threshold of 0.95, suggest the existence of a third latent variable. All four parallel analysis criteria suggest two latent factors, so the final number of latent factors that are suggested by the analysis is two.
You can access this final result by specifying the "nFactorsByGroup" key in the results dictionary that is produced by the faNFactors action.
Output 10.2.23: Number of Factors
| Criterion | Description | NFactors | Threshold | Simulations | Seed | Status |
|---|---|---|---|---|---|---|
| 1 | Minimum Eigenvalue (Eigenvalue > 0.50) | 3 | 0.50 | _ | _ | 0 |
| 2 | Minimum Eigenvalue (Eigenvalue > 1.00) | 2 | 1.00 | _ | _ | 0 |
| 3 | Minimum Eigenvalue (Eigenvalue > 1.50) | 2 | 1.50 | _ | _ | 0 |
| 4 | Parallel Analysis (Alpha = 0.05, Seed = 1031, Sims = 20000) | 2 | 0.05 | 20000 | 1031 | 1 |
| 5 | Parallel Analysis (Alpha = 0.05, Seed = 1128, Sims = 20000) | 2 | 0.05 | 20000 | 1128 | 1 |
| 6 | Parallel Analysis (Alpha = 0.10, Seed = 1031, Sims = 20000) | 2 | 0.10 | 20000 | 1031 | 1 |
| 7 | Parallel Analysis (Alpha = 0.10, Seed = 1128, Sims = 20000) | 2 | 0.10 | 20000 | 1128 | 1 |
| 8 | Total Proportion (Threshold = 0.90) | 2 | 0.90 | _ | _ | 0 |
| 9 | Total Proportion (Threshold = 0.95) | 3 | 0.95 | _ | _ | 0 |
| 10 | Min Ave Squared Partial Corr (MAP2) | 2 | _ | _ | _ | 0 |
| 11 | Min Ave 4th-powered Partial Corr (MAP4) | 2 | _ | _ | _ | 0 |
Additional information about the minimum eigenvalue and cumulative proportion criteria is presented in the "Eigenvalues of the Reduced Correlation Matrix" table in Output 10.2.24. This table is displayed by default. After the data correlation matrix is reduced by replacing its diagonal elements with the ASMC prior communality estimates, the largest eigenvalue of the resulting matrix is approximately 6.21, and the corresponding latent factor explains approximately 73% of the common variance of the input data. The second eigenvalue is approximately 1.50, and the latent factors that correspond to these first two eigenvalues explain approximately 90% of the common variance. A third eigenvalue has a value of approximately 0.60, and the latent factors that correspond to these three eigenvalues explain more than 97% of the common variance. From this table, it is clear that two latent factors are sufficient to explain up to 90% of the common variance in the input data, and that a third factor is needed to explain more than 95% of the common variance. Similarly, a minimum eigenvalue threshold of 1.50 or 1.00 produces an estimate of two latent factors, whereas a third latent factor is estimated if the minimum eigenvalue threshold is 0.50. (The fourth-largest eigenvalue for the reduced correlation matrix has a value of approximately 0.31.)
Output 10.2.24: Eigenvalues and Variance Explained
| Number | Eigenvalue | Difference | Proportion | Cumulative |
|---|---|---|---|---|
| 1 | 6.216813 | 4.711586 | 0.7258 | 0.7258 |
| 2 | 1.505227 | 0.909106 | 0.1757 | 0.9015 |
| 3 | 0.596120 | 0.282313 | 0.0696 | 0.9711 |
| 4 | 0.313807 | 0.047022 | 0.0366 | 1.0078 |
| 5 | 0.266785 | 0.157610 | 0.0311 | 1.0389 |
| 6 | 0.109175 | 0.073777 | 0.0127 | 1.0517 |
| 7 | 0.035398 | 0.030976 | 0.0041 | 1.0558 |
| 8 | 0.004422 | 0.050335 | 0.0005 | 1.0563 |
| 9 | -0.045913 | 0.021721 | -0.0054 | 1.0510 |
| 10 | -0.067634 | 0.018736 | -0.0079 | 1.0431 |
| 11 | -0.086370 | 0.025395 | -0.0101 | 1.0330 |
| 12 | -0.111765 | 0.058945 | -0.0130 | 1.0199 |
| 13 | -0.170710 | _ | -0.0199 | 1.0000 |
The parallel analysis results are summarized in the "Parallel Analysis" tables in Output 10.2.25 through Output 10.2.28. A "Parallel Analysis" table is displayed by the faNFactors action any time you specify at least one parallel analysis criterion. For each of the four specified parallel analysis criteria, correlation matrices are simulated from a Wishart distribution. These simulations represent correlation matrices that might be realized for a data-generating process in which all variables are independently and identically distributed according to the standard normal distribution. The eigenvalues of the simulated correlation matrices are computed and rank-ordered, and the eigenvalues of the input data correlation matrix are compared to the distributions of the eigenvalues at each position (largest eigenvalue, second-largest eigenvalue, and so on). When an eigenvalue of the input data correlation matrix exceeds the eigenvalue at some critical point (for example, the 95th percentile), this is understood to indicate the presence of a latent factor in the data. In all four parallel analyses in this example, the largest and second-largest eigenvalues for the input data correlation matrix exceed the simulated critical values. Thus all four parallel analyses suggest that two latent factors should be retained.
Output 10.2.25: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
Output 10.2.26: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
Output 10.2.27: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
Output 10.2.28: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
The minimum average partial correlation analysis (MAP) results are summarized in the "Average Partial Correlations Controlling Principal Components" table in Output 10.2.29. This table is displayed by the faNFactors action any time you specify a minimum average partial correlation criterion. In this example, analyses are performed that use both squared (MAP2) and fourth-powered (MAP4) partial correlations. These two analyses are summarized in separate columns in the table. The number of latent factors that are estimated by a minimum average partial correlation analysis is the number of principal components that, when partialed out of the correlation matrix, produce the smallest average squared or fourth-powered partial correlations. As shown in Output 10.2.29, the minimum value is obtained for both the MAP2 and the MAP4 analysis when two principal components are partialed out.
Output 10.2.29: Minimum Average Partial Correlation Analysis
| NComp | AveParCor2 | OptAveParCor2 | AveParCor4 | OptAveParCor4 |
|---|---|---|---|---|
| 0 | 0.229076 | 0 | 0.069057 | 0 |
| 1 | 0.063655 | 0 | 0.011875 | 0 |
| 2 | 0.036328 | 1 | 0.003287 | 1 |
| 3 | 0.042970 | 0 | 0.004975 | 0 |
| 4 | 0.057102 | 0 | 0.009267 | 0 |
| 5 | 0.065326 | 0 | 0.014253 | 0 |
| 6 | 0.083345 | 0 | 0.022845 | 0 |
| 7 | 0.115706 | 0 | 0.037743 | 0 |
| 8 | 0.153423 | 0 | 0.050831 | 0 |
| 9 | 0.233063 | 0 | 0.120901 | 0 |
| 10 | 0.309145 | 0 | 0.167278 | 0 |
| 11 | 0.544163 | 0 | 0.416722 | 0 |
| 12 | 1.000000 | 0 | 1.000000 | 0 |
Finally, the faNFactors action displays the table shown in Output 10.2.30, which shows the amount of time (in seconds) that it took to perform the various tasks of the analysis.
Output 10.2.30: Analysis Timing
| RowId | Task | Time | RelTime |
|---|---|---|---|
| INIT | Initializing | 0.02 | 1.94% |
| PARSE | Parsing | 0.00 | 0.00% |
| CORR | Calculating Correlations | 0.01 | 1.27% |
| NFACT | Determining Number of Factors | 0.00 | 0.02% |
| MISC | Miscellaneous | 1.00 | 96.76% |
| CLEANUP | Cleaning Up | 0.00 | 0.01% |
| TOTAL | Total | 1.03 | 100.00% |
Using Multiple Criteria To Determine the Number of Factors
This section contains R code that creates the same jobratings table and performs the same analysis as shown in the CASL version of this example. For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.
Because this example uses simulated data that are produced from DATA step code, you can submit the runCode action on your R client to create the simulated data in your CAS session.
This example uses the jobratings data set that is described in the examples for the FACTOR procedure in SAS/STAT software. In the original data set, 103 police officers were rated by their supervisors on 14 scales (variables). In the current example one of these scales, the overall rating variable, is excluded.
To run this example code, you must make the jobratings data accessible to the CAS server. One way to do this is to convert the jobratings data set from the PROC FACTOR documentation to a comma-separated-value (CSV) file and then load the CSV file into CAS.
As the first step in a common factor analysis, you want to determine the number of latent factors that are likely to explain the data. The following code performs this analysis:
m <- cas.builtins.loadActionSet(s, actionset='factorAnalysis')
cas.factorAnalysis.faNFactors(s,
criteria=list(list(status='inactive',
threshold=c(0.5, 1, 1.5),
type='eigenvalue'),
list(alpha=c(0.05, 0.1),
nSims=c(20000),
seed=c(1031, 1128),
type='parallel'),
list(status='inactive',
threshold=c(0.9, 0.95),
type='proportion'),
list(status='inactive', type='map2'),
list(status='inactive', type='map4')),
nFactors='mean',
priors='asmc',
table='jobratings')
When you use the faNFactors action, you must specify values for the table and criteria parameters. You specify the input data table to use for the analysis in the table parameter. You use the criteria parameter to specify one or more criteria that the action uses to determine the number of factors or components to retain. In this example, you specify several different types of criteria. For the minimum eigenvalue, cumulative proportion, and minimum average partial correlation criteria, the status parameter is set to "inactive". This means that the results for these criteria are displayed for informational purposes but not used to determine the final number of factors for the analysis. You use the priors parameter to specify adjusted squared multiple correlations for the prior communality estimates to be applied for the minimum eigenvalue and cumulative proportion criteria.
To determine the number of factors, you use a parallel analysis with 20,000 simulations. To assess the robustness of the analysis, you include two different thresholds for the parallel analysis and two different random number seeds. Because you specify two values for the alpha parameter and two values for the seed parameter, the action performs a total of four parallel analyses. You use the nFactors parameter to specify that the final number of factors for the overall analysis is the mean of the four parallel analysis criteria.
The output from this analysis is displayed in Output 10.2.31 through Output 10.2.40.
The "Number of Observations" table in Output 10.2.31 summarizes the number of observations that are read from the input data table and the number of observations that are used for the analysis. This table is displayed by default. For this analysis, these two numbers are the same. These numbers would be different if some observations were discarded from the analysis. The faNFactors action uses only complete cases for analysis, so a record is discarded if any field contains a missing value.
Output 10.2.31: Number of Observations
| RowId | Description | Value |
|---|---|---|
| NREAD | Number of Observations Read | 103 |
| NUSED | Number of Observations Used | 103 |
The "Simple Statistics" table in Output 10.2.32 summarizes the means and standard deviations of the variables that are included in the analysis. This table is displayed by default.
Output 10.2.32: Simple Statistics
| Variable | Mean | StdDev |
|---|---|---|
| Communication Skills | 6.65049 | 1.76407 |
| Problem Solving | 6.63107 | 1.59035 |
| Learning Ability | 6.99029 | 1.33941 |
| Judgment under Pressure | 6.73786 | 1.73183 |
| Observational Skills | 6.93204 | 1.76158 |
| Willingness to Confront Problems | 7.29126 | 1.52516 |
| Interest in People | 6.70874 | 1.89235 |
| Interpersonal Sensitivity | 6.62136 | 1.76077 |
| Desire for Self-Improvement | 6.57282 | 1.72980 |
| Appearance | 7.00000 | 1.79869 |
| Dependability | 6.82524 | 1.91704 |
| Physical Ability | 7.20388 | 1.55525 |
| Integrity | 7.21359 | 1.84524 |
The primary output for the analysis is shown in the "Determination of Number of Factors" table in Output 10.2.33. This table is displayed by default. For most of the specified criteria, the results suggest that two latent factors should be retained to explain the data. The minimum eigenvalue criterion, with a threshold of 0.50, and the cumulative proportion criterion, with a threshold of 0.95, suggest the existence of a third latent variable. All four parallel analysis criteria suggest two latent factors, so the final number of latent factors that are suggested by the analysis is two.
You can access this final result by specifying the "nFactorsByGroup" key in the results dictionary that is produced by the faNFactors action.
Output 10.2.33: Number of Factors
| Criterion | Description | NFactors | Threshold | Simulations | Seed | Status |
|---|---|---|---|---|---|---|
| 1 | Minimum Eigenvalue (Eigenvalue > 0.50) | 3 | 0.50 | _ | _ | 0 |
| 2 | Minimum Eigenvalue (Eigenvalue > 1.00) | 2 | 1.00 | _ | _ | 0 |
| 3 | Minimum Eigenvalue (Eigenvalue > 1.50) | 2 | 1.50 | _ | _ | 0 |
| 4 | Parallel Analysis (Alpha = 0.05, Seed = 1031, Sims = 20000) | 2 | 0.05 | 20000 | 1031 | 1 |
| 5 | Parallel Analysis (Alpha = 0.05, Seed = 1128, Sims = 20000) | 2 | 0.05 | 20000 | 1128 | 1 |
| 6 | Parallel Analysis (Alpha = 0.10, Seed = 1031, Sims = 20000) | 2 | 0.10 | 20000 | 1031 | 1 |
| 7 | Parallel Analysis (Alpha = 0.10, Seed = 1128, Sims = 20000) | 2 | 0.10 | 20000 | 1128 | 1 |
| 8 | Total Proportion (Threshold = 0.90) | 2 | 0.90 | _ | _ | 0 |
| 9 | Total Proportion (Threshold = 0.95) | 3 | 0.95 | _ | _ | 0 |
| 10 | Min Ave Squared Partial Corr (MAP2) | 2 | _ | _ | _ | 0 |
| 11 | Min Ave 4th-powered Partial Corr (MAP4) | 2 | _ | _ | _ | 0 |
Additional information about the minimum eigenvalue and cumulative proportion criteria is presented in the "Eigenvalues of the Reduced Correlation Matrix" table in Output 10.2.34. This table is displayed by default. After the data correlation matrix is reduced by replacing its diagonal elements with the ASMC prior communality estimates, the largest eigenvalue of the resulting matrix is approximately 6.21, and the corresponding latent factor explains approximately 73% of the common variance of the input data. The second eigenvalue is approximately 1.50, and the latent factors that correspond to these first two eigenvalues explain approximately 90% of the common variance. A third eigenvalue has a value of approximately 0.60, and the latent factors that correspond to these three eigenvalues explain more than 97% of the common variance. From this table, it is clear that two latent factors are sufficient to explain up to 90% of the common variance in the input data, and that a third factor is needed to explain more than 95% of the common variance. Similarly, a minimum eigenvalue threshold of 1.50 or 1.00 produces an estimate of two latent factors, whereas a third latent factor is estimated if the minimum eigenvalue threshold is 0.50. (The fourth-largest eigenvalue for the reduced correlation matrix has a value of approximately 0.31.)
Output 10.2.34: Eigenvalues and Variance Explained
| Number | Eigenvalue | Difference | Proportion | Cumulative |
|---|---|---|---|---|
| 1 | 6.216813 | 4.711586 | 0.7258 | 0.7258 |
| 2 | 1.505227 | 0.909106 | 0.1757 | 0.9015 |
| 3 | 0.596120 | 0.282313 | 0.0696 | 0.9711 |
| 4 | 0.313807 | 0.047022 | 0.0366 | 1.0078 |
| 5 | 0.266785 | 0.157610 | 0.0311 | 1.0389 |
| 6 | 0.109175 | 0.073777 | 0.0127 | 1.0517 |
| 7 | 0.035398 | 0.030976 | 0.0041 | 1.0558 |
| 8 | 0.004422 | 0.050335 | 0.0005 | 1.0563 |
| 9 | -0.045913 | 0.021721 | -0.0054 | 1.0510 |
| 10 | -0.067634 | 0.018736 | -0.0079 | 1.0431 |
| 11 | -0.086370 | 0.025395 | -0.0101 | 1.0330 |
| 12 | -0.111765 | 0.058945 | -0.0130 | 1.0199 |
| 13 | -0.170710 | _ | -0.0199 | 1.0000 |
The parallel analysis results are summarized in the "Parallel Analysis" tables in Output 10.2.35 through Output 10.2.38. A "Parallel Analysis" table is displayed by the faNFactors action any time you specify at least one parallel analysis criterion. For each of the four specified parallel analysis criteria, correlation matrices are simulated from a Wishart distribution. These simulations represent correlation matrices that might be realized for a data-generating process in which all variables are independently and identically distributed according to the standard normal distribution. The eigenvalues of the simulated correlation matrices are computed and rank-ordered, and the eigenvalues of the input data correlation matrix are compared to the distributions of the eigenvalues at each position (largest eigenvalue, second-largest eigenvalue, and so on). When an eigenvalue of the input data correlation matrix exceeds the eigenvalue at some critical point (for example, the 95th percentile), this is understood to indicate the presence of a latent factor in the data. In all four parallel analyses in this example, the largest and second-largest eigenvalues for the input data correlation matrix exceed the simulated critical values. Thus all four parallel analyses suggest that two latent factors should be retained.
Output 10.2.35: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
Output 10.2.36: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
Output 10.2.37: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
Output 10.2.38: Parallel Analysis
| Criterion | Alpha | Simulations | Component | CritEig | Eigenvalue | FlagEigen | Seed | Status |
|---|---|---|---|---|---|---|---|---|
| 4 | 0.05 | 20000 | 1 | 1.8013 | 6.5474 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 2 | 1.5787 | 1.7727 | 1 | 1031 | 1 |
| 4 | 0.05 | 20000 | 3 | 1.4319 | 1.0052 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 4 | 1.3128 | 0.7431 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 5 | 1.2082 | 0.6783 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 6 | 1.1152 | 0.4514 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 7 | 1.0299 | 0.3822 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 8 | 0.9505 | 0.2978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 9 | 0.8721 | 0.2744 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 10 | 0.7985 | 0.2623 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 11 | 0.7227 | 0.2446 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 12 | 0.6476 | 0.1978 | 0 | 1031 | 1 |
| 4 | 0.05 | 20000 | 13 | 0.5648 | 0.1427 | 0 | 1031 | 1 |
The minimum average partial correlation analysis (MAP) results are summarized in the "Average Partial Correlations Controlling Principal Components" table in Output 10.2.39. This table is displayed by the faNFactors action any time you specify a minimum average partial correlation criterion. In this example, analyses are performed that use both squared (MAP2) and fourth-powered (MAP4) partial correlations. These two analyses are summarized in separate columns in the table. The number of latent factors that are estimated by a minimum average partial correlation analysis is the number of principal components that, when partialed out of the correlation matrix, produce the smallest average squared or fourth-powered partial correlations. As shown in Output 10.2.39, the minimum value is obtained for both the MAP2 and the MAP4 analysis when two principal components are partialed out.
Output 10.2.39: Minimum Average Partial Correlation Analysis
| NComp | AveParCor2 | OptAveParCor2 | AveParCor4 | OptAveParCor4 |
|---|---|---|---|---|
| 0 | 0.229076 | 0 | 0.069057 | 0 |
| 1 | 0.063655 | 0 | 0.011875 | 0 |
| 2 | 0.036328 | 1 | 0.003287 | 1 |
| 3 | 0.042970 | 0 | 0.004975 | 0 |
| 4 | 0.057102 | 0 | 0.009267 | 0 |
| 5 | 0.065326 | 0 | 0.014253 | 0 |
| 6 | 0.083345 | 0 | 0.022845 | 0 |
| 7 | 0.115706 | 0 | 0.037743 | 0 |
| 8 | 0.153423 | 0 | 0.050831 | 0 |
| 9 | 0.233063 | 0 | 0.120901 | 0 |
| 10 | 0.309145 | 0 | 0.167278 | 0 |
| 11 | 0.544163 | 0 | 0.416722 | 0 |
| 12 | 1.000000 | 0 | 1.000000 | 0 |
Finally, the faNFactors action displays the table shown in Output 10.2.40, which shows the amount of time (in seconds) that it took to perform the various tasks of the analysis.
Output 10.2.40: Analysis Timing
| RowId | Task | Time | RelTime |
|---|---|---|---|
| INIT | Initializing | 0.02 | 1.94% |
| PARSE | Parsing | 0.00 | 0.00% |
| CORR | Calculating Correlations | 0.01 | 1.27% |
| NFACT | Determining Number of Factors | 0.00 | 0.02% |
| MISC | Miscellaneous | 1.00 | 96.76% |
| CLEANUP | Cleaning Up | 0.00 | 0.01% |
| TOTAL | Total | 1.03 | 100.00% |