Ncontributors function

Find the number of unique groups contributing to aggregates

Find the number of unique groups contributing to aggregates

Assuming aggregates are calculated via a dummy matrix by z = t(x) %*% y, the the number of unique contributing groups, according to a grouping variable, are found for each aggregate. The missing group category is not counted.

Ncontributors(x, groups)

Arguments

  • x: A (sparse) dummy matrix
  • groups: Vector of group categories

Returns

Vector of numbers of unique groups

Examples

library(SSBtools) z <- SSBtoolsData("sprt_emp_withEU") z$age[z$age == "Y15-29"] <- "young" z$age[z$age == "Y30-64"] <- "old" z$groups <- c("A", "A", "B", "A", "B", "C") a <- ModelMatrix(z, formula = ~age*eu + geo + year, crossTable = TRUE) cbind(as.data.frame(a$crossTable), nGroups = Ncontributors(a$modelMatrix, z$groups)) cbind(as.data.frame(a$crossTable), nYears = Ncontributors(a$modelMatrix, z$year)) cbind(as.data.frame(a$crossTable), nUnique_ths_per = Ncontributors(a$modelMatrix, z$ths_per))

See Also

ModelMatrix

Author(s)

Øyvind Langsrud