getPCA: Perform PCA on a COIN

Description Usage Arguments Details Value See Also Examples

View source: R/coin_PCA.R

Description

Performs Principle Component Analysis (PCA) on a specified data set and subset of indicators or aggregation groups. Returns weights corresponding to the first principal component, i.e the weights that maximise the variance explained by the linear combination of indicators.

Usage

1
2
3
4
5
6
7
8
9
getPCA(
  COIN,
  dset = "Raw",
  icodes = NULL,
  aglev = NULL,
  by_groups = TRUE,
  nowarnings = FALSE,
  out2 = "COIN"
)

Arguments

COIN

An input object. The function can handle either the COIN object, or a data frame. The data frame should have each column as an indicator, and an optional column "UnitCode" which specifies the code (or name) of each unit. Any other type of object will return an error.

dset

If input is a COIN object, this specifies which data set in .$Data to use.

icodes

An optional character vector of indicator codes to subset the indicator data. Usefully, can also refer to an aggregation group name, and data will be sub-setted accordingly. NOTE does not work with multiple aggregate group names.

aglev

The aggregation level to take indicator data from. Integer from 1 (indicator level) to N (top aggregation level, typically the index).

by_groups

If TRUE (default), performs PCA inside each aggregation group inside the specified level. If FALSE, performs a single PCA over all indicators/aggregates in the specified level.

nowarnings

If FALSE (default), will give warnings where missing data are found. Set to TRUE to suppress these warnings.

out2

If the input is a COIN object, this controls where to send the output. If "COIN", it sends the results to the COIN object, otherwise if "list", outputs to a separate list.

Details

Note that getPCA() is simply a quick wrapper for stats::prcomp() which makes PCA on COINs quicker. See COINr online documentation for more details and examples.

Value

If out2 = "COIN", results are appended to the COIN object. Specifically:

See Also

Examples

1
2
3
4
5
6
7
8
9
# build ASEM COIN
ASEM <- assemble(IndData = ASEMIndData, IndMeta = ASEMIndMeta,
AggMeta = ASEMAggMeta)
# get PCA results for pillar groups inside "Sust" (sustainability) sub-index
# (warnings about missing data are suppressed)
PCAres <- getPCA(ASEM, dset = "Raw", icodes = "Sust",
aglev = 1, nowarnings = TRUE, out2 = "list")
# summarise PCA results for Social pillar
summary(PCAres$PCAresults$Social$PCAres)

COINr documentation built on Nov. 30, 2021, 9:06 a.m.