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

Results from factorAnalysis.faNFactors

Number of Observations Read103
Number of Observations Used103


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
VariableMeanStandard
Deviation
Communication Skills6.650491.76407
Problem Solving6.631071.59035
Learning Ability6.990291.33941
Judgment under Pressure6.737861.73183
Observational Skills6.932041.76158
Willingness to Confront Problems7.291261.52516
Interest in People6.708741.89235
Interpersonal Sensitivity6.621361.76077
Desire for Self-Improvement6.572821.72980
Appearance7.000001.79869
Dependability6.825241.91704
Physical Ability7.203881.55525
Integrity7.213591.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
CriterionDescriptionFactors
1Minimum Eigenvalue (Eigenvalue > 0.50)3
2Minimum Eigenvalue (Eigenvalue > 1.00)2
3Minimum Eigenvalue (Eigenvalue > 1.50)2
4Parallel Analysis (Alpha = 0.05, Seed = 1031, Sims = 20000)2
5Parallel Analysis (Alpha = 0.05, Seed = 1128, Sims = 20000)2
6Parallel Analysis (Alpha = 0.10, Seed = 1031, Sims = 20000)2
7Parallel Analysis (Alpha = 0.10, Seed = 1128, Sims = 20000)2
8Total Proportion (Threshold = 0.90)2
9Total Proportion (Threshold = 0.95)3
10Min Ave Squared Partial Corr (MAP2)2
11Min 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
 EigenvalueDifferenceProportionCumulative
16.2168134.7115860.72580.7258
21.5052270.9091060.17570.9015
30.5961200.2823130.06960.9711
40.3138070.0470220.03661.0078
50.2667850.1576100.03111.0389
60.1091750.0737770.01271.0517
70.0353980.0309760.00411.0558
80.0044220.0503350.00051.0563
9-0.0459130.021721-0.00541.0510
10-0.0676340.018736-0.00791.0431
11-0.0863700.025395-0.01011.0330
12-0.1117650.058945-0.01301.0199
13-0.170710 -0.01991.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)
ComponentSimulated
Crit Val
Observed
Eigenvalue
11.80136.5474*
21.57871.7727*
31.43191.0052
41.31280.7431
51.20820.6783
61.11520.4514
71.02990.3822
80.95050.2978
90.87210.2744
100.79850.2623
110.72270.2446
120.64760.1978
130.56480.1427
* Retained Dimension (Obs > Crit)


Output 10.2.6: Parallel Analysis

Parallel Analysis (Criterion 5)
ComponentSimulated
Crit Val
Observed
Eigenvalue
11.79766.5474;
21.57971.7727;
31.43081.0052
41.31270.7431
51.20920.6783
61.11550.4514
71.02940.3822
80.94920.2978
90.87250.2744
100.79800.2623
110.72340.2446
120.64780.1978
130.56430.1427
* Retained Dimension (Obs > Crit)


Output 10.2.7: Parallel Analysis

Parallel Analysis (Criterion 6)
ComponentSimulated
Crit Val
Observed
Eigenvalue
11.76146.5474;
21.55111.7727;
31.41061.0052
41.29430.7431
51.19290.6783
61.10070.4514
71.01660.3822
80.93660.2978
90.85910.2744
100.78440.2623
110.70920.2446
120.63300.1978
130.54950.1427
* Retained Dimension (Obs > Crit)


Output 10.2.8: Parallel Analysis

Parallel Analysis (Criterion 7)
ComponentSimulated
Crit Val
Observed
Eigenvalue
11.75906.5474;
21.55411.7727;
31.40931.0052
41.29420.7431
51.19350.6783
61.10120.4514
71.01550.3822
80.93570.2978
90.85950.2744
100.78420.2623
110.70910.2446
120.63330.1978
130.54880.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
SquaredFourth-
Powered
00.2290760.069057
10.0636550.011875
20.036328*0.003287*
30.0429700.004975
40.0571020.009267
50.0653260.014253
60.0833450.022845
70.1157060.037743
80.1534230.050831
90.2330630.120901
100.3091450.167278
110.5441630.416722
121.0000001.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
TaskSecondsPercent
Initializing0.021.94%
Parsing0.000.00%
Calculating Correlations0.011.27%
Determining Number of Factors0.000.02%
Miscellaneous1.0096.76%
Cleaning Up0.000.01%
Total1.03100.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

RowIdDescriptionValue
NREADNumber of Observations Read103
NUSEDNumber of Observations Used103


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

VariableMeanStdDev
Communication Skills6.650491.76407
Problem Solving6.631071.59035
Learning Ability6.990291.33941
Judgment under Pressure6.737861.73183
Observational Skills6.932041.76158
Willingness to Confront Problems7.291261.52516
Interest in People6.708741.89235
Interpersonal Sensitivity6.621361.76077
Desire for Self-Improvement6.572821.72980
Appearance7.000001.79869
Dependability6.825241.91704
Physical Ability7.203881.55525
Integrity7.213591.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

CriterionDescriptionNFactorsThresholdSimulationsSeedStatus
1Minimum Eigenvalue (Eigenvalue > 0.50)30.50__0
2Minimum Eigenvalue (Eigenvalue > 1.00)21.00__0
3Minimum Eigenvalue (Eigenvalue > 1.50)21.50__0
4Parallel Analysis (Alpha = 0.05, Seed = 1031, Sims = 20000)20.052000010311
5Parallel Analysis (Alpha = 0.05, Seed = 1128, Sims = 20000)20.052000011281
6Parallel Analysis (Alpha = 0.10, Seed = 1031, Sims = 20000)20.102000010311
7Parallel Analysis (Alpha = 0.10, Seed = 1128, Sims = 20000)20.102000011281
8Total Proportion (Threshold = 0.90)20.90__0
9Total Proportion (Threshold = 0.95)30.95__0
10Min Ave Squared Partial Corr (MAP2)2___0
11Min 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

NumberEigenvalueDifferenceProportionCumulative
16.2168134.7115860.72580.7258
21.5052270.9091060.17570.9015
30.5961200.2823130.06960.9711
40.3138070.0470220.03661.0078
50.2667850.1576100.03111.0389
60.1091750.0737770.01271.0517
70.0353980.0309760.00411.0558
80.0044220.0503350.00051.0563
9-0.0459130.021721-0.00541.0510
10-0.0676340.018736-0.00791.0431
11-0.0863700.025395-0.01011.0330
12-0.1117650.058945-0.01301.0199
13-0.170710_-0.01991.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

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


Output 10.2.16: Parallel Analysis

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


Output 10.2.17: Parallel Analysis

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


Output 10.2.18: Parallel Analysis

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


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

NCompAveParCor2OptAveParCor2AveParCor4OptAveParCor4
00.22907600.0690570
10.06365500.0118750
20.03632810.0032871
30.04297000.0049750
40.05710200.0092670
50.06532600.0142530
60.08334500.0228450
70.11570600.0377430
80.15342300.0508310
90.23306300.1209010
100.30914500.1672780
110.54416300.4167220
121.00000001.0000000


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

RowIdTaskTimeRelTime
INITInitializing0.021.94%
PARSEParsing0.000.00%
CORRCalculating Correlations0.011.27%
NFACTDetermining Number of Factors0.000.02%
MISCMiscellaneous1.0096.76%
CLEANUPCleaning Up0.000.01%
TOTALTotal1.03100.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

RowIdDescriptionValue
NREADNumber of Observations Read103
NUSEDNumber of Observations Used103


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

VariableMeanStdDev
Communication Skills6.650491.76407
Problem Solving6.631071.59035
Learning Ability6.990291.33941
Judgment under Pressure6.737861.73183
Observational Skills6.932041.76158
Willingness to Confront Problems7.291261.52516
Interest in People6.708741.89235
Interpersonal Sensitivity6.621361.76077
Desire for Self-Improvement6.572821.72980
Appearance7.000001.79869
Dependability6.825241.91704
Physical Ability7.203881.55525
Integrity7.213591.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

CriterionDescriptionNFactorsThresholdSimulationsSeedStatus
1Minimum Eigenvalue (Eigenvalue > 0.50)30.50__0
2Minimum Eigenvalue (Eigenvalue > 1.00)21.00__0
3Minimum Eigenvalue (Eigenvalue > 1.50)21.50__0
4Parallel Analysis (Alpha = 0.05, Seed = 1031, Sims = 20000)20.052000010311
5Parallel Analysis (Alpha = 0.05, Seed = 1128, Sims = 20000)20.052000011281
6Parallel Analysis (Alpha = 0.10, Seed = 1031, Sims = 20000)20.102000010311
7Parallel Analysis (Alpha = 0.10, Seed = 1128, Sims = 20000)20.102000011281
8Total Proportion (Threshold = 0.90)20.90__0
9Total Proportion (Threshold = 0.95)30.95__0
10Min Ave Squared Partial Corr (MAP2)2___0
11Min 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

NumberEigenvalueDifferenceProportionCumulative
16.2168134.7115860.72580.7258
21.5052270.9091060.17570.9015
30.5961200.2823130.06960.9711
40.3138070.0470220.03661.0078
50.2667850.1576100.03111.0389
60.1091750.0737770.01271.0517
70.0353980.0309760.00411.0558
80.0044220.0503350.00051.0563
9-0.0459130.021721-0.00541.0510
10-0.0676340.018736-0.00791.0431
11-0.0863700.025395-0.01011.0330
12-0.1117650.058945-0.01301.0199
13-0.170710_-0.01991.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

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


Output 10.2.26: Parallel Analysis

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


Output 10.2.27: Parallel Analysis

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


Output 10.2.28: Parallel Analysis

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


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

NCompAveParCor2OptAveParCor2AveParCor4OptAveParCor4
00.22907600.0690570
10.06365500.0118750
20.03632810.0032871
30.04297000.0049750
40.05710200.0092670
50.06532600.0142530
60.08334500.0228450
70.11570600.0377430
80.15342300.0508310
90.23306300.1209010
100.30914500.1672780
110.54416300.4167220
121.00000001.0000000


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

RowIdTaskTimeRelTime
INITInitializing0.021.94%
PARSEParsing0.000.00%
CORRCalculating Correlations0.011.27%
NFACTDetermining Number of Factors0.000.02%
MISCMiscellaneous1.0096.76%
CLEANUPCleaning Up0.000.01%
TOTALTotal1.03100.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

RowIdDescriptionValue
NREADNumber of Observations Read103
NUSEDNumber of Observations Used103


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

VariableMeanStdDev
Communication Skills6.650491.76407
Problem Solving6.631071.59035
Learning Ability6.990291.33941
Judgment under Pressure6.737861.73183
Observational Skills6.932041.76158
Willingness to Confront Problems7.291261.52516
Interest in People6.708741.89235
Interpersonal Sensitivity6.621361.76077
Desire for Self-Improvement6.572821.72980
Appearance7.000001.79869
Dependability6.825241.91704
Physical Ability7.203881.55525
Integrity7.213591.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

CriterionDescriptionNFactorsThresholdSimulationsSeedStatus
1Minimum Eigenvalue (Eigenvalue > 0.50)30.50__0
2Minimum Eigenvalue (Eigenvalue > 1.00)21.00__0
3Minimum Eigenvalue (Eigenvalue > 1.50)21.50__0
4Parallel Analysis (Alpha = 0.05, Seed = 1031, Sims = 20000)20.052000010311
5Parallel Analysis (Alpha = 0.05, Seed = 1128, Sims = 20000)20.052000011281
6Parallel Analysis (Alpha = 0.10, Seed = 1031, Sims = 20000)20.102000010311
7Parallel Analysis (Alpha = 0.10, Seed = 1128, Sims = 20000)20.102000011281
8Total Proportion (Threshold = 0.90)20.90__0
9Total Proportion (Threshold = 0.95)30.95__0
10Min Ave Squared Partial Corr (MAP2)2___0
11Min 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

NumberEigenvalueDifferenceProportionCumulative
16.2168134.7115860.72580.7258
21.5052270.9091060.17570.9015
30.5961200.2823130.06960.9711
40.3138070.0470220.03661.0078
50.2667850.1576100.03111.0389
60.1091750.0737770.01271.0517
70.0353980.0309760.00411.0558
80.0044220.0503350.00051.0563
9-0.0459130.021721-0.00541.0510
10-0.0676340.018736-0.00791.0431
11-0.0863700.025395-0.01011.0330
12-0.1117650.058945-0.01301.0199
13-0.170710_-0.01991.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

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


Output 10.2.36: Parallel Analysis

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


Output 10.2.37: Parallel Analysis

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


Output 10.2.38: Parallel Analysis

CriterionAlphaSimulationsComponentCritEigEigenvalueFlagEigenSeedStatus
40.052000011.80136.5474110311
40.052000021.57871.7727110311
40.052000031.43191.0052010311
40.052000041.31280.7431010311
40.052000051.20820.6783010311
40.052000061.11520.4514010311
40.052000071.02990.3822010311
40.052000080.95050.2978010311
40.052000090.87210.2744010311
40.0520000100.79850.2623010311
40.0520000110.72270.2446010311
40.0520000120.64760.1978010311
40.0520000130.56480.1427010311


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

NCompAveParCor2OptAveParCor2AveParCor4OptAveParCor4
00.22907600.0690570
10.06365500.0118750
20.03632810.0032871
30.04297000.0049750
40.05710200.0092670
50.06532600.0142530
60.08334500.0228450
70.11570600.0377430
80.15342300.0508310
90.23306300.1209010
100.30914500.1672780
110.54416300.4167220
121.00000001.0000000


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

RowIdTaskTimeRelTime
INITInitializing0.021.94%
PARSEParsing0.000.00%
CORRCalculating Correlations0.011.27%
NFACTDetermining Number of Factors0.000.02%
MISCMiscellaneous1.0096.76%
CLEANUPCleaning Up0.000.01%
TOTALTotal1.03100.00%


Last updated: September 17, 2026