impute_datamatrix: Imputes the missing values in the input data

Description Usage Arguments Value Examples

Description

This function uses Amelia::amelia to impute missing (NA) values in the input data set. This function averages over multiple Amelia imputations to obtain more consistent results. The Amelia imputation model uses all variables of the supplied data_matrix, the first lag of those variables, time, time squared, and day-part dummies.

Usage

1
impute_datamatrix(data_matrix, measurements_per_day, imputation_iterations)

Arguments

data_matrix

The raw, unimputed data matrix.

measurements_per_day

The number of measurements per day. This variable is used for adding day part dummy variables to aid the imputation.

imputation_iterations

The amount of times the Amelia imputation should be averaged over.

Value

This function returns the modified matrix.

Examples

1
2
3
4
5
6
7
8
# create a matrix with some missing values
data_matrix <- matrix(nrow = 40, ncol = 3)
data_matrix[, ] <- runif(ncol(data_matrix) * nrow(data_matrix), 1, nrow(data_matrix))
while (sum(is.na(data_matrix)) == 0)
  data_matrix[as.logical(round(runif(ncol(data_matrix) * nrow(data_matrix), -0.3, 0.7)))] <- NA
colnames(data_matrix) <- c('rumination', 'happiness', 'activity')
data_matrix
autovarCore:::impute_datamatrix(data_matrix, 1, 100)

autovarCore documentation built on May 2, 2019, 4:01 a.m.