Skip to contents

Aggregates microdata from a data frame into interval-valued data using various criteria and latent distribution settings.

Usage

micro2intData(
  microdata,
  agrby,
  agrcrt = "minmax",
  LatentParam = NULL,
  LatentCase = c("U_id_symmetric", "U_id", "General"),
  LatentDist = c("Unif", "Triang", "TNorm", "InvTri", "Beta", "KDE", "Degenerated"),
  TriangParam = 0,
  BetaParam.a = 1,
  BetaParam.b = 1,
  estimate.DistParam = FALSE,
  removeDegenerate = FALSE
)

Arguments

microdata

A data frame containing the microdata. All columns should be numeric.

agrby

A factor used to specify the grouping of the microdata for aggregation.

agrcrt

A string or numeric vector of length 2 specifying the aggregation criterion. The default is "minmax", which takes the minimum and maximum values for each variable. If a numeric vector is provided, it should specify the lower and upper percentiles for aggregation (e.g., c(0.05, 0.95)).

LatentParam

(Optional) A list with the parameters of the latent variables. Expects a list with a single number if LatentCase is "U_id_symmetric", a list of two numbers if LatentCase is "U_id", and a list of two matrices if LatentCase is "General".

LatentCase

A string specifying which of the three scenarios applies to the latent variables:

  • "U_id_symmetric": The case where the latent variables are identically distributed and symmetric.

  • "U_id": The case where the latent variables are identically distributed.

  • "General": The case where the latent variables do not have any nice properties.

Defaults to "U_id_symmetric".

LatentDist

A string or vector of strings specifying the distribution(s) of the latent variables. If the variables are identically distributed it can be one of ("Unif", "Triang", "TNorm", "InvTri", "Beta", "KDE", "Degenerated"), if not a vector must be provided with the distribution for each variable. The default is "Unif" if LatentCase="U_id_symmetric", and "KDE" if LatentCase="General".

TriangParam

Mode of the triangular distribution. If the latent variables are identically distributed, it is only necessary to provide a number, if not a vector is needed. The default is 0.

BetaParam.a

Parameter alpha of the Beta distribution. If the latent variables are identically distributed, it is only necessary to provide a number, if not a vector is needed. The default is 1.

BetaParam.b

Parameter beta of the Beta distribution. If the latent variables are identically distributed, it is only necessary to provide a number, if not a vector is needed. The default is 1.

estimate.DistParam

Logical parameter indicating if estimation of the parameters of the latent distributions should be performed. Can only be set to TRUE if LatentCase="General". The default is FALSE.

removeDegenerate

Logical parameter indicating if observations with at least one degenerate interval should be removed. The default is FALSE.

Value

An intData object containing the aggregated interval-valued data. If removeDegenerate is TRUE, observations with degenerate intervals are removed, and NULL is returned if all observations are removed.

Details

This function processes a data frame of microdata and aggregates it into interval-valued data according to the specified grouping factor and aggregation criteria. It can handle different latent distribution cases and parameter settings.

If some rows contain invalid (non-finite or missing) values, those rows are removed before aggregation. Degenerate intervals (i.e., intervals whose lower and upper bounds are equal) can be removed by setting removeDegenerate to TRUE.

References

Adapted from package MAINT.Data (https://cran.r-project.org/package=MAINT.Data).

Examples

data(creditcard)
CreditCard_microdata <- creditcard$microdata

# Define grouping variable for microdata aggregation
credit_agrby <- factor(paste(CreditCard_microdata$Name, CreditCard_microdata$Month, sep = "_"))

# Create intData object by aggregating microdata using the default minmax criterion 
# and using KDE for estimation of the latent distribution in the general case
credit_agr <- micro2intData(CreditCard_microdata[,3:7],
                            agrby = credit_agrby,
                            LatentCase = "General")