Learn R Programming

autovarCore (version 1.0-4)

impute_datamatrix: Imputes the missing values in the input data

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

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

Run this code
# NOT RUN {
# 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)
# }

Run the code above in your browser using DataLab