PCA.COMPONENTS OpenBI
Principal components: each one's variance and its share.
Group: Many variables at once. OpenBI’s own: DAX has no function of this name.
Syntax
PCA.COMPONENTS ( <table>, <name1>, <expression1>, <name2>, <expression2> [, <name3>, <expression3>] … )
| Parameter | Type | Description |
|---|---|---|
table | Table | The rows to analyse: a table of the model or any table expression. |
name1 | Text | The first variable's name, a text in quotes. |
expression1 | Expression evaluated for each row | The first variable's number for each row. |
name2 | Text repeatable | The next variable's name; two or more variables in all. |
expression2 | Expression repeatable, evaluated for each row | The next variable's number for each row. |
Returns
Table. A row a component, the strongest first: Component (1, 2 …), Name (PC1, PC2 …), Eigenvalue, Std deviation, Share (the part of the total variation it carries) and Cumulative share.
Remarks
- Principal components are new variables, each a weighted sum of the old ones, that take up as much of the variation as they can in turn. Cumulative share says how many of them tell most of the story.
- Pick the columns you want with
SELECTCOLUMNS, as the examples do. - Every variable is first put on one scale: how many standard deviations each row lies above or below that variable's mean. Liters and kroner then weigh alike, and a change of units changes nothing. The analysis is then of the correlations, as R's prcomp with scale = TRUE.
- The eigenvalues add up to the number of variables. A component with an eigenvalue above 1 carries more than a single variable would.
- A row where any variable is blank is left out. A variable must be a number on every row (text is an error, even text that reads as a number), and one that is the same on every row is an error too.
- Each variable is a name in quotes followed by its expression; two variables may not share a name.
PCA.COMPONENTS,PCA.LOADINGSandPCA.SCORESwith the same table and variables describe the same components.
Compared with DAX
An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.
Examples
Six beers, three variables
Strength, bitterness and price rise together, so one component takes up 92 % of the variation.
EVALUATE
VAR Beers =
DATATABLE (
"Beer", STRING, "Strength", DOUBLE, "Bitterness", INTEGER, "Price", INTEGER,
{
{ "Lettøl", 2.5, 15, 30 }, { "Pils", 4.7, 25, 38 }, { "Lager", 5.0, 22, 40 },
{ "Pale ale", 5.5, 40, 55 }, { "IPA", 6.5, 65, 64 }, { "Stout", 7.0, 45, 70 }
}
)
RETURN
SELECTCOLUMNS (
PCA.COMPONENTS ( Beers, "Strength", [Strength], "Bitterness", [Bitterness], "Price", [Price] ),
"Name", [Name], "Eigenvalue", [Eigenvalue], "Share", [Share],
"Cumulative share", [Cumulative share]
)
| Name | Eigenvalue | Share | Cumulative share |
|---|---|---|---|
| PC1 | 2.76148998841619 | 0.920496662805398 | 0.920496662805398 |
| PC2 | 0.183463447220368 | 0.0611544824067893 | 0.981651145212187 |
| PC3 | 0.0550465643634384 | 0.0183488547878128 | 1 |
Countries by population, GDP and GDP per person
GDP per person is a measure, worked out for each country.
EVALUATE
SELECTCOLUMNS (
PCA.COMPONENTS ( Countries, "People", Countries[People], "GDP", Countries[GDP], "GDP per person", [GDP per person] ),
"Name", [Name], "Eigenvalue", [Eigenvalue], "Share", [Share], "Cumulative share", [Cumulative share]
)
| Name | Eigenvalue | Share | Cumulative share |
|---|---|---|---|
| PC1 | 1.59997980916019 | 0.533326603053396 | 0.533326603053396 |
| PC2 | 1.03391661203874 | 0.344638870679579 | 0.877965473732975 |
| PC3 | 0.366103578801074 | 0.122034526267025 | 1 |