Impute: Apply the imputation method to a data set

Description Usage Arguments Value Examples

Description

Apply the imputation method to a data set

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Impute(object, Param)

## S4 method for signature 'data.table,MeanImputationParam'
Impute(object, Param)

## S4 method for signature 'data.table,BenchImputationParam'
Impute(object, Param)

## S4 method for signature 'data.table,MedianImputationParam'
Impute(object, Param)

Arguments

object

Object containing the the data upon which the imputation is to be computed.

Param

Object of virtual class ImputationParam with the parameters specifying the method of imputation to be applied.

Value

Object of the same class as the input object with the missing values imputed according to the method specified in the input argument Param

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Not run: 

FF.StQList <- readRDS('../E30183.FF.StQList.rds')
FF <- FF.StQList[["MM072016"]]

ValToImpute <- dcast_StQ(FD, ExtractNames(c('CifraNeg_13.___', 'ActivEcono_35._4._2.1.4._0')))
ValToImpute[sample(1:16941, floor(16941 / 5)), CifraNeg_13.___ := NA_real_]
Units1 <- ValToImpute[, 'NOrden', with = FALSE]

BenchValues <- dcast_StQ(FF, ExtractNames(c('CifraNeg_13.___', 'ActivEcono_35._4._2.1.4._0')))
Units2 <- BenchValues[, 'NOrden', with = FALSE]
Units <- merge(Units1, Units2)
setkeyv(ValToImpute, 'NOrden')
ValToImpute <- ValToImpute[NOrden %chin% Units[['NOrden']]]
BenchValues <- BenchValues[, c('NOrden', 'CifraNeg_13.___', 'ActivEcono_35._4._2.1.4._0'), with = FALSE]
setkeyv(BenchValues, 'NOrden')
BenchValues <- BenchValues[NOrden %chin% Units[['NOrden']]]
BenchValues[is.na(CifraNeg_13.___), CifraNeg_13.___ := mean(CifraNeg_13.___, na.rm = TRUE), by = 'ActivEcono_35._4._2.1.4._0']
BenchValues[is.na(CifraNeg_13.___), CifraNeg_13.___ := mean(CifraNeg_13.___, na.rm = TRUE)]
BenchValues <- BenchValues[, c('NOrden', 'CifraNeg_13.___'), with = F]
BenchImpParam <- new(Class = 'BenchImputationParam',
                     VarNames = 'CifraNeg_13.___',
                     DomainNames = 'ActivEcono_35._4._2.1.4._0',
                     BenchValues = BenchValues)
Impute(ValToImpute, BenchImpParam)

## End(Not run)

david-salgado/StQImputation documentation built on July 31, 2019, 11:33 p.m.