MaxContribution {GaussSuppression} | R Documentation |
Assuming aggregates are calculated via a dummy matrix by
z = t(x) %*% y
,
the n
largest contributors are found (value or index) for each aggregate.
MaxContribution(x, y, n = 1, decreasing = TRUE, index = FALSE, groups = NULL)
x |
A (sparse) dummy matrix |
y |
Vector of input values (contributors) |
n |
Number of contributors to be found |
decreasing |
Ordering parameter. Smallest contributors found when |
index |
Indices to |
groups |
When non-NULL, major contributions after aggregation within groups.
Cannot be combined with |
Matrix with lagest contributors in first column, second largest in second column and so on.
Øyvind Langsrud
library(SSBtools)
z <- SSBtoolsData("sprt_emp_withEU")
z$age[z$age == "Y15-29"] <- "young"
z$age[z$age == "Y30-64"] <- "old"
a <- ModelMatrix(z, formula = ~age + geo, crossTable = TRUE)
cbind(as.data.frame(a$crossTable), MaxContribution(a$modelMatrix, z$ths_per, 1))
cbind(a$crossTable, MaxContribution(a$modelMatrix, z$ths_per, 10))
cbind(a$crossTable, MaxContribution(a$modelMatrix, z$ths_per, 10, index = TRUE))
b <- ModelMatrix(z[, -4], crossTable = TRUE, inputInOutput = c(TRUE, FALSE, TRUE))
k <- cbind(b$crossTable, MaxContribution(b$modelMatrix, z$ths_per, 10))
gr18 <- paste0("g", 1:18) # Each row is a group
k18 <- cbind(b$crossTable, MaxContribution(b$modelMatrix, z$ths_per, 10, groups = gr18))
identical(k, k18) # TRUE
gr9 <- paste0("g", as.integer(10 * z$ths_per)%%10) # 9 groups from decimal
k9 <- cbind(b$crossTable, MaxContribution(b$modelMatrix, z$ths_per, 10, groups = gr9))
k18[c(4, 13, 17, 33), ]
k9[c(4, 13, 17, 33), ]