Skip to content

Main content

Principal Component Analysis (PCA)

Compute centered, unstandardized sample-covariance PCA through the existing thin Jacobi SVD, with projected scores, sample explained variances and deterministic component signs; degenerate subspaces remain nonunique.

Loading tool…

Description

Compute centered, unstandardized sample-covariance PCA through the existing thin Jacobi SVD, with projected scores, sample explained variances and deterministic component signs; degenerate subspaces remain nonunique.

Principal component analysis finds orthogonal directions of variation in centered multivariate observations. Rows represent observations and columns features; scores locate observations along the components. Centering and standardizing are different operations, so feature units affect an unstandardized analysis.

Compute centered, unstandardized sample-covariance PCA through the existing thin Jacobi SVD, with projected scores, sample explained variances and deterministic component signs; degenerate subspaces remain nonunique.

When to use this tool

Use this tool to calculate principal component analysis under the units, normalization, and boundary conventions below.

How to use the tool and how it works

  1. Supply observations, componentCount in the field shapes below.
  2. Run the calculation. Correct format, shape, range, or undefined-statistic errors before interpreting a result.
  3. Read means, components, scores, explainedVariance, explainedVarianceRatio. Use the conventions below.

Scale data for numeric stability, subtract each column mean, and obtain components from the thin Jacobi singular-value decomposition. Make the largest-magnitude loading in each component nonnegative, project centered observations for scores, and use sample variances with denominator n−1 for explained variance.1

Delegated operations used for this result: singular value decomposition. Their calculation or parsing conventions apply to the corresponding result fields.2

Input fieldMeaning and unitsAccepted input
observationsObservationsRequired. Array of Array of Finite number.; minimum items 1; maximum items 20.; minimum items 2; maximum items 20.
componentCountComponent CountRequired. Safe integer; minimum 1; maximum 20.
Output fieldInterpretationReturned shape
meansFeature means aligned with input columns, in their original units.Required. Array of Finite number.; minimum items 1; maximum items 20.
componentsComponent loading vectors in component order, each aligned with the original feature columns.Required. Array of Array of Finite number.; minimum items 1; maximum items 20.; minimum items 1; maximum items 20.
scoresObservation-by-component coordinates in the original input scale.Required. Array of Array of Finite number.; minimum items 1; maximum items 20.; minimum items 2; maximum items 20.
explainedVarianceSample variance of each component, with denominator observation count minus one.Required. Array of Finite number; minimum 0.; minimum items 1; maximum items 20.
explainedVarianceRatioEach component variance divided by total centered sample variance; zero when total variance is zero.Required. Array of Finite number; minimum 0; maximum 1.; minimum items 1; maximum items 20.
json
{
  "input": {
    "observations": [
      [
        0,
        4
      ],
      [
        4,
        4
      ],
      [
        8,
        4
      ]
    ],
    "componentCount": 2
  },
  "output": {
    "means": [
      4,
      4
    ],
    "components": [
      [
        1,
        0
      ],
      [
        0,
        1
      ]
    ],
    "scores": [
      [
        -4,
        0
      ],
      [
        0,
        0
      ],
      [
        4,
        0
      ]
    ],
    "explainedVariance": [
      16,
      0
    ],
    "explainedVarianceRatio": [
      1,
      0
    ]
  }
}

Limitations and assumptions

  • Observations must form a rectangular matrix and componentCount cannot exceed min(rows,columns). Features are centered but not standardized. Constant data returns zero variance ratios; equal singular values leave the component subspace nonunique despite sign normalization.
  • The field tables state structural bounds; cross-field constraints and bounded search or output budgets also apply. Unknown keys are rejected where the object contract disallows them. Input errors are distinct from null fields and deliberate invalid controls in a successful output.

Alternative or Complementary methods

Choose the statistic according to the question and data conventions. Inspect the supplied series or matrix and the stated assumptions before comparing outputs from implementations with different defaults.

References

  1. Tool behavior and example: Principal Component Analysis Tool — tool.io

  2. Calculation or validation: matrix/singular-value-decomposition — tool.io

Similar or alternative tools