primary
and forced
from suppressed data
Source: R/PrimaryFromSuppressedData.R
PrimaryFromSuppressedData.Rd
Function for GaussSuppressionFromData
Usage
PrimaryFromSuppressedData(
x,
crossTable,
suppressedData,
forcedData = FALSE,
totCode = FindTotCode2(x, crossTable),
...
)
ForcedFromSuppressedData(..., forcedData = TRUE)
NotPrimaryFromSuppressedData(..., forcedData = TRUE)
Arguments
- x
A (sparse) dummy matrix
- crossTable
crossTable generated by parent function
- suppressedData
A data frame or a list of data frames as output from
GaussSuppressionFromData
. If the variablesuppressed
is not included, all rows are considered suppressed.- forcedData
When
TRUE
, the suppressed coding is swapped.- totCode
A named list of totals codes
- ...
Unused parameters
Value
Logical vector to be used as GaussSuppression
input
Details
ForcedFromSuppressedData
uses forcedData = TRUE
and hence a vector to be use as forced is generated.
NotPrimaryFromSuppressedData
is similar, but TRUE
elements are replaced by NA
's.
Hence the result can be used as an extra primary vector to ensure that code combinations
not suppressed according to suppressedData
are forced not to be primary suppressed.
The variables used in suppressedData
in addition to "suppressed"
are those with matching names in crossTable
. Others are ignored.
For variables in crossTable
not in suppressedData
, only totals are considered.
Others rows are ignored when mathing with suppressedData
.
When suppressedData is a list, the final result is the union of individual results of each data frame.
Examples
z2 <- SSBtoolsData("z2")
# Data to be used as suppressedData
a <- GaussSuppressionFromData(z2, c(1, 3, 4), 5, protectZeros = FALSE)
#> GaussSuppression_anySum: ...............................
# For alternative ways to suppress the same table
b1 <- GaussSuppressionFromData(z2, 1:4, 5)
#> GaussSuppression_anySum: ............................
b2 <- GaussSuppressionFromData(z2, 1:4, 5, primary = c(PrimaryDefault, PrimaryFromSuppressedData),
suppressedData = a)
#> GaussSuppression_anySum: ..........................
b3 <- GaussSuppressionFromData(z2, 1:4, 5, primary = c(PrimaryDefault, PrimaryFromSuppressedData),
suppressedData = a, forced = ForcedFromSuppressedData)
#> Warning: Primary suppression of forced cells ignored
#> GaussSuppression_anySum
#> Warning: Singleton marking of forced cells ignored (freq)
#> : ..........................
b4 <- GaussSuppressionFromData(z2, 1:4, 5,
primary = c(PrimaryDefault, PrimaryFromSuppressedData, NotPrimaryFromSuppressedData),
suppressedData = a, forced = ForcedFromSuppressedData)
#> GaussSuppression_anySum
#> Warning: Singleton marking of forced cells ignored (freq)
#> : ..........................
# Reducing data to rows mathing a
b1r <- b1[SSBtools::Match(a[1:2], b1[1:2]), ]
b2r <- b2[SSBtools::Match(a[1:2], b2[1:2]), ]
b3r <- b3[SSBtools::Match(a[1:2], b3[1:2]), ]
b4r <- b4[SSBtools::Match(a[1:2], b4[1:2]), ]
# Look at rows where new suppression is different from that in a
# Both TRUE and FALSE changed
cbind(a, b1r)[b1r$suppressed != a$suppressed, c(1:5, 9:10)]
#> region hovedint ant primary suppressed primary.1 suppressed.1
#> 47 A annet 11 FALSE FALSE FALSE TRUE
#> 48 A arbeid 11 FALSE FALSE FALSE TRUE
#> 50 A trygd 36 FALSE FALSE FALSE TRUE
#> 52 B annet 7 FALSE TRUE FALSE FALSE
#> 55 B trygd 18 FALSE FALSE FALSE TRUE
#> 57 C annet 5 FALSE FALSE FALSE TRUE
#> 58 C arbeid 8 FALSE FALSE FALSE TRUE
#> 77 G annet 6 FALSE FALSE FALSE TRUE
#> 78 G arbeid 4 FALSE FALSE FALSE TRUE
#> 88 I arbeid 0 FALSE FALSE TRUE TRUE
#> 92 J annet 9 FALSE FALSE FALSE TRUE
#> 93 J arbeid 0 FALSE FALSE TRUE TRUE
#> 97 K annet 4 FALSE FALSE FALSE TRUE
# Only FALSE changed to TRUE (suppression is preserved)
cbind(a, b2r)[b2r$suppressed != a$suppressed, c(1:5, 9:10)]
#> region hovedint ant primary suppressed primary.1 suppressed.1
#> 47 A annet 11 FALSE FALSE FALSE TRUE
#> 48 A arbeid 11 FALSE FALSE FALSE TRUE
#> 50 A trygd 36 FALSE FALSE FALSE TRUE
#> 55 B trygd 18 FALSE FALSE FALSE TRUE
#> 57 C annet 5 FALSE FALSE FALSE TRUE
#> 58 C arbeid 8 FALSE FALSE FALSE TRUE
#> 77 G annet 6 FALSE FALSE FALSE TRUE
#> 78 G arbeid 4 FALSE FALSE FALSE TRUE
#> 88 I arbeid 0 FALSE FALSE TRUE TRUE
#> 92 J annet 9 FALSE FALSE FALSE TRUE
#> 93 J arbeid 0 FALSE FALSE TRUE TRUE
# Only change is due to new primary suppression rule (protectZeros = TRUE)
cbind(a, b3r)[b3r$suppressed != a$suppressed, c(1:5, 9:10)]
#> [1] region hovedint ant primary suppressed primary.1 forced
#> <0 rows> (or 0-length row.names)
# No changes
cbind(a, b4r)[b4r$suppressed != a$suppressed, c(1:5, 9:10)]
#> [1] region hovedint ant primary suppressed primary.1 forced
#> <0 rows> (or 0-length row.names)