Principal Component Analysis

GX-TXT DEV112 P011-bis

Run PCA and read scores, loadings and the share of explained variance, with an example scree plot.

Prepare variables measured on the same observations

Generate a Session Standalone with Grouped Statistics Student Lab and enable Principal Component Analysis in Configuration → Modules. Open student.grouped.source in the tab Dataset and identify voltage_V and current_A. Each row identifies the same observation for all variables. The different units make the standardized comparison of the exercise meaningful.

Selection of Grouped Statistics Student Lab in Generate Session before the Session is created.
Selection of Grouped Statistics Student Lab in Generate Session before the Session is created.

Set data, scale and components

  1. In Analysis choose student.grouped.source as primary. In Numeric variables assign the two measurements. Use + Add for an additional variable and Remove to remove a row. Avoid duplicate or equivalently rescaled columns if you want to interpret distinct factors.
  2. Leave Data selection on None for the 18 rows. The lab also provides sel_001, defined on the X interval of sample 3–18. In Missing row policy, listwise_omit removes a row if at least one selected measurement is non-finite. error stops the run. In the exercise 16 rows remain with listwise_omit.
  3. Enable Subtract variable means and use standardize in Variable scaling. The module subtracts the means and divides by the sample standard deviations. With none keeps the scale of the measurements and requires compatible dimensions. If you turn off mean subtraction, the origin stays that of the variables and the result reflects the second moments about that origin. Apply this choice only if zero has the intended meaning.
  4. For Component selection uses count and Number of components 2. With variance_target set instead a fraction between 0 and 1 in Cumulative explained-variance target. The number retained is the minimum that reaches the threshold. Reset of the field restores the initial value.
  5. Write pca.count in Output Dataset ID prefix and leave the three plots on. Tick Run / recalculate now, check the plan and press Run enabled analyses.
Centered and standardized PCA on voltage and current, with two components.
Centered and standardized PCA on voltage and current, with two components.

Read variance, loadings, scores and transformations

  • .components contains eigenvalue, share of variability, cumulative share, singular value and selection flag. The first component explains about 99.8632% and the second 0.1368%. The high share reflects the strong agreement between the two standardized measurements.
  • .loadings keeps the variable weights per component. In the first component they are about 0.7071 for both. The sign of the whole eigenvector can flip together with the sign of the scores, leaving the solution unchanged.
  • .scores contains one row per valid observation, with source_row to trace back to the original row. The scores are coordinates in component space.
  • .scaling shows the observed means, the factors applied and the units, useful for reconstructing the transformation of new compatible data.
Original weights and units per variable in the loadings Dataset.
Original weights and units per variable in the loadings Dataset.
Coordinates per component with the identifier of the source row.
Coordinates per component with the identifier of the source row.

To try variance_target, replace current_A with constant_V. Press + Add, assign constant_V in the new row and remove the previous current row. Set sel_001, none for the scale, centering off, threshold 0.90 and plots off. In the confirmed result the first component explains 0.92930 of the uncentered spectral share, enough to retain one component. The metric is shown as Cumulative uncentered spectral proportion.

Uncentered configuration with two compatible variables in V and a cumulative threshold of 0.90.
Uncentered configuration with two compatible variables in V and a cumulative threshold of 0.90.

To customize the already published scree plot, select the variant of Explained variance ratio. In Presentation → Title and labels… set Variance share per component. Save and use Render → Rerender. The title changes and the two shares published in the Dataset remain available for comparison.

Scree plot with the initial title and two explained shares.
Scree plot with the initial title and two explained shares.
The scree plot after the title change and regeneration.
The scree plot after the title change and regeneration.

In Plots open scree for the variance per component, scores for the distribution of the observations and loadings for the contribution of the variables. The variants plot.dataset allow presentation changes. For a repetition without images turn off Create scree, score and loading graphs and choose a new prefix. If you try none with V and A the module rejects the dimensional incompatibility. With the policy error the example Dataset also brings out the presence of non-finite values.