stop_ds_difference {imputeGeneric}R Documentation

Compare differences between two data sets

Description

This function is intended to be used as stop_fun inside of impute_iterative(). It compares the difference of two (numeric) data sets and return ds, if difference is small enough (less than stop_args$eps).

Usage

stop_ds_difference(
  ds,
  ds_old,
  info_list,
  stop_args = list(eps = 1e-06, p = 1, sum_diffs = TRUE, na_rm = TRUE),
  res_stop_fun = NULL
)

Arguments

ds

A numeric data set

ds_old

A numeric data set

info_list

info_list used inside of impute_iterative(). Only the list element nr_iterations is used/needed.

stop_args

A list with following named components (missing elements will be replaced by default ones):

  • eps Threshold value for the difference (default = 1e-6).

  • p Exponent used for the calculation of differences similar to Minkowski distance. For p = 1 (default) the absolute differences are used. For p = 2 The quadratic differences are summed and the square root of this sum is compared with stop_eps.

  • sum_diffs Should differences be summed (default) or averaged (sum_diffs = FALSE)?

  • na_rm Should NA-values be removed (default) when calculating the sum/average? If na_rm = FALSE and there are NAs, the function returns FALSE.

res_stop_fun

Only needed to be a valid stop function. Internally, this argument is ignored at the moment.

Value

list(stop_iter = FALSE), if the difference is too big. Otherwise ds with number of iterations (nr_iterations) as attribute.

Examples

set.seed(123)
ds1 <- data.frame(X = rnorm(10), Y = rnorm(10))
ds2 <- data.frame(X = rnorm(10), Y = rnorm(10))
all.equal(
  stop_ds_difference(ds1, ds1, list(nr_iterations = 3)),
  structure(ds1, nr_iterations = 3)
)
stop_ds_difference(ds1, ds2, list(nr_iterations = 42))

[Package imputeGeneric version 0.1.0 Index]