View source: R/helmert_trans.R
| helmert_transform | R Documentation |
Transform n-dimension compositional data (all values sum to 1) into an (n-1)-dimensional Euclidean space using the Helmert matrix. This dimension reduction is the geometric basis for plotting points within the simplex.
helmert_transform(data, items = dplyr::everything(), append = FALSE)
data |
A data frame or matrix containing the compositional data. |
items |
< |
append |
(Optional) A logical value indicating whether the transformed data should be appended to the original data frame.
Default is |
A data frame containing the Helmert-transformed coordinates, named
x1, x2, ..., x(n-1), where n is the number of items. If append = TRUE,
these columns are added to the input data.
# Example 1: Transform a matrix (all columns)
comp_mat <- matrix(c(0.5, 0.3, 0.2,
0.4, 0.4, 0.2,
0.6, 0.2, 0.2),
ncol = 3, byrow = TRUE)
helmert_transform(comp_mat)
# Example 2: Transform specific columns in a data frame
df <- data.frame(
electorate = c("A", "B", "C"),
ALP = c(0.5, 0.4, 0.6),
LNP = c(0.3, 0.4, 0.2),
Other = c(0.2, 0.2, 0.2)
)
helmert_transform(df, items = c(ALP, LNP, Other))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.