PLSroundingFits: Small count rounding with post-processing to expected...

View source: R/PLSroundingFits.R

PLSroundingFitsR Documentation

Small count rounding with post-processing to expected frequencies

Description

The counts rounded by PLSrounding Thereafter, based on the publishable rounded data, expected inner cell frequencies are generated by iterative proportional fitting using Mipf. To ensure that empty cells missing in input data are included in the fitting process, the data is first extended using Extend0.

Usage

PLSroundingFits(
  data,
  freqVar = NULL,
  roundBase = 3,
  hierarchies = NULL,
  formula = NULL,
  dimVar = NULL,
  preAggregate = is.null(freqVar),
  printInc = nrow(data) > 1000,
  xReturn = FALSE,
  extend0 = FALSE,
  extend0Fits = TRUE,
  limit = 1e-10,
  viaQR = FALSE,
  iter = 1000,
  eps = 0.01,
  tol = 1e-13,
  reduceBy0 = TRUE,
  reduceByColSums = TRUE,
  reduceByLeverage = FALSE,
  ...
)

Arguments

data

data frame (inner cells)

freqVar

Variable holding counts

roundBase

Rounding base

hierarchies

List of hierarchies

formula

Model formula

dimVar

Dimensional variables

preAggregate

Aggregation

printInc

Printing iteration information

xReturn

Dummy matrix in output when TRUE. To return crossTable as well, use xReturn = 2.

extend0

PLSrounding parameter. See below.

extend0Fits

When extend0Fits is set to TRUE (default), the data is automatically extended. Additionally, extend0Fits can be specified as a list, or set to "all" (see PLSrounding). Previously, this functionality was controlled by a parameter called extend0, but now extend0 is specific to the PLSrounding function. When both extend0 and extend0Fits are used simultaneously, extend0Fits adds an additional extension on top of the one provided by extend0 (see example).

limit

LSfitNonNeg parameter

viaQR

LSfitNonNeg parameter

iter

Mipf parameter

eps

Mipf parameter

tol

Mipf parameter

reduceBy0

Mipf parameter

reduceByColSums

Mipf parameter

reduceByLeverage

Mipf parameter

...

Further parameters to PLSrounding.

Details

The nine first parameters is documented in more detail in PLSrounding. If iterative proportional fitting succeeds, the maximum difference between rounded counts and ipFit is less than input parameter eps.

Value

Output from PLSrounding (class attribute "PLSrounded") with modified versions of inner and publish:

inner

Extended with more input data variables and with expected frequencies (ipFit).

publish

Extended with aggregated expected frequencies (ipFit).

Examples

z <- data.frame(geo  = c("Iceland", "Portugal", "Spain"), 
                eu = c("nonEU", "EU", "EU"),
                year = rep(c("2018","2019"), each = 3),
                freq = c(2,3,7,1,5,6), stringsAsFactors = FALSE)
z4 <- z[-c(1:2), ]

PLSroundingFits(z4, "freq", formula = ~eu * year + geo, extend0 = FALSE)[c("inner", "publish")]
PLSroundingFits(z4, "freq", formula = ~eu * year + geo)[c("inner", "publish")]

my_km2 <- SSBtools::SSBtoolsData("my_km2")

# Default automatic extension (extend0Fits = TRUE)
PLSroundingFits(my_km2, "freq", 
       formula = ~(Sex + Age) * Municipality * Square1000m + Square250m)[c("inner", "publish")]

# Manual specification to avoid Nittedal combined with another_km
PLSroundingFits(my_km2, "freq", formula = ~(Sex + Age) * Municipality * Square1000m + Square250m, 
       extend0Fits = list(c("Sex", "Age"), 
       c("Municipality", "Square1000m", "Square250m")))[c("inner", "publish")]
       
# Example with both extend0 (specified) and extend0Fits (default is TRUE)
PLSroundingFits(my_km2, "freq", formula = ~(Sex + Age) * Municipality * Square1000m + Square250m, 
       printInc = TRUE, zeroCandidates = TRUE, roundBase = 5, extend0 = list(c("Sex", "Age"), 
       c("Municipality", "Square1000m", "Square250m")))[c("inner", "publish")]        

SmallCountRounding documentation built on Oct. 22, 2024, 5:06 p.m.