| HierarchyCompute2 {SSBtools} | R Documentation |
Extended Hierarchical Computations
Description
Extended variant of HierarchyCompute with several column variables (not just "colFactor").
Parameter colVar splits the hierarchy variables in two groups and this variable overrides the difference between "rowFactor" and "colFactor".
Usage
HierarchyCompute2(
data,
hierarchies,
valueVar,
colVar,
rowSelect = NULL,
colSelect = NULL,
select = NULL,
output = "data.frame",
...
)
Arguments
data |
The input data frame |
hierarchies |
A named list with hierarchies |
valueVar |
Name of the variable(s) to be aggregated |
colVar |
Name of the column variable(s) |
rowSelect |
Data frame specifying variable combinations for output |
colSelect |
Data frame specifying variable combinations for output |
select |
Data frame specifying variable combinations for output |
output |
One of "data.frame" (default), "outputMatrix", "matrixComponents". |
... |
Further parameters sent to |
Details
Within this function, HierarchyCompute is called two times.
By specifying output as "matrixComponents",
output from the two runs are retuned as a list with elements hcRow and hcCol.
The matrix multiplication in HierarchyCompute is extended to
outputMatrix = hcRow$dataDummyHierarchy
%*% hcRow$valueMatrix
%*% t(hcCol$dataDummyHierarchy).
This is modified in cases with more than a single valueVar.
Value
As specified by the parameter output
Note
There is no need to call HierarchyCompute2 directly.
The main function HierarchyCompute can be used instead.
Author(s)
Øyvind Langsrud
See Also
Hierarchies2ModelMatrix, AutoHierarchies.
Examples
x <- SSBtoolsData("sprt_emp")
geoHier <- SSBtoolsData("sprt_emp_geoHier")
ageHier <- SSBtoolsData("sprt_emp_ageHier")
HierarchyCompute(x, list(age = ageHier, geo = geoHier, year = "rowFactor"), "ths_per",
colVar = c("age", "year"))
HierarchyCompute(x, list(age = ageHier, geo = geoHier, year = "rowFactor"), "ths_per",
colVar = c("age", "geo"))
HierarchyCompute(x, list(age = ageHier, geo = geoHier, year = "rowFactor"), "ths_per",
colVar = c("age", "year"), output = "matrixComponents")
HierarchyCompute(x, list(age = ageHier, geo = geoHier, year = "rowFactor"), "ths_per",
colVar = c("age", "geo"), output = "matrixComponents")