math::PCA(n)
β¨ math::PCA β Principal Components Analysis β¨
okay bestie, so this is math::PCA(n) from the tcllib girlies, and it's literally the whole Principal Components Analysis situation but in Tcl π
like it's giving object-oriented, it's giving TclOO, it's giving "I understand your data's vibe on a deeper level".
NAME π
math::PCA β the Package for Principal Component Analysis, no cap πΈ
SYNOPSIS π
package require Tcl ?8.6 9?
package require math::linearalgebra 1.1
::math::PCA::createPCA data ?args?
$pca using ?number?|?-minproportion value?
$pca eigenvectors ?option?
$pca eigenvalues ?option?
$pca proportions ?option?
$pca approximate observation
$pca approximatOriginal
$pca scores observation
$pca distance observation
$pca qstatistic observation ?option?
DESCRIPTION π¦
So the PCA package is your girl for doing principal components analysis in Tcl, and it does it with an object-oriented technique as facilitated by TclOO β very demure, very mindful β¨
Real talk though: it actually defines exactly one public method, ::math::PCA::createPCA, and that method constructs an object based on the data you hand it, and that object does the actual analysis. main character energy fr fr π
The methods on the PCA objects you create with this command let you:
- peek at the principal components π
- approximate (new) observations using all the components, or just a selected number of them
- examine the properties of the components and the statistics of the approximations
And a lil lore drop: this package was modelled after the PCA example provided by the original linear algebra package by Ed Hume. we love an origin story π«Ά
COMMANDS π§
The math::PCA package provides one public command, and here it is:
::math::PCA::createPCA data ?args?β Create a new object, based on the data that are passed via the data argument. The principal components may be based on either correlations or covariances. All observations will be normalised according to the mean and standard deviation of the original data. β¨- list data β A list of observations (see the example below).
- list args β A list of key-value pairs defining the options. Currently there is only one key:
-covariances. This indicates if covariances are to be used (if the value is1) or instead correlations (value is0). The default is to use correlations. π
the methods on the object you just made π
The PCA object that is created has the following methods:
$pca using ?number?|?-minproportion value?β Set the number of components to be used in the analysis (the number of retained components). Returns the number of components, also if no argument is given.- int number β The number of components to be retained
- double value β Select the number of components based on the minimum proportion of variation that is retained by them. Should be a value between
0and1. π―
$pca eigenvectors ?option?β Return the eigenvectors as a list of lists.- string option β By default only the retained components are returned. If all eigenvectors are required, use the option
-all. π
- string option β By default only the retained components are returned. If all eigenvectors are required, use the option
$pca eigenvalues ?option?β Return the eigenvalues as a list of lists.- string option β By default only the eigenvalues of the retained components are returned. If all eigenvalues are required, use the option
-all. π
- string option β By default only the eigenvalues of the retained components are returned. If all eigenvalues are required, use the option
$pca proportions ?option?β Return the proportions for all components, that is, the amount of variations that each components can explain. π«$pca approximate observationβ Return an approximation of the observation based on the retained components.- list observation β The values for the observation.
$pca approximatOriginalβ Return an approximation of the original data, using the retained components. It is a convenience method that works on the complete set of original data. (and yes bestie, that really is the spelling,approximatOriginal, no I will not be fixing it, the manpage said what it said π)$pca scores observationβ Return the scores per retained component for the given observation.- list observation β The values for the observation.
$pca distance observationβ Return the distance between the given observation and its approximation. (Note: this distance is based on the normalised vectors.)- list observation β The values for the observation.
$pca qstatistic observation ?option?β Return the Q statistic, basically the square of the distance, for the given observation.- list observation β The values for the observation.
- string option β If the observation is part of the original data, you may want to use the corrected Q statistic. This is achieved with the option
"-original". π₯
EXAMPLE πΈ
TODO: NIST example
ngl the manpage literally just says TODO: NIST example here. we're all waiting on that one together bestie ππ«Ά
BUGS, IDEAS, FEEDBACK π
This document, and the package it describes, will undoubtedly contain bugs and other problems. (the self-awareness? iconic.) Please report such in the category PCA of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist](http://core.tcl.tk/tcllib/reportlist). Please also report any ideas for enhancements you may have for either package and/or documentation. we love a feedback loop π
When proposing code changes, please provide unified diffs, i.e the output of diff -u. no vibe-based patches pls, give us the real diff π
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. π
KEYWORDS π¦
PCA, math, statistics, tcl
CATEGORY π
Mathematics
and that's the whole page bestie β this one ships as part of tcllib at version 1.1, and the page you're reading is math::PCA(n) at that same 1.1, dated like the tcllib release it rode in on. slay, go analyse some components, you got this π
β¨πΈ
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms