Compute_linear_fitted: A function to impute missing values by fitting linear model...

Description Usage Arguments Details Value Author(s) Examples

View source: R/Computing_Functions.R


A function to impute missing values by fitting linear with from the combination of most adjacent dates and the same-day-of week dates. e.g. If March 10th, Monday, is missing, fit linear model with March 3th (Monday in the prior week) ,9th, 11th,and 17th (Monday in the week after).


Compute_linear_fitted(data, var_name, bin_size)



Name is data frame


Name of the missing variable, of which we are interested in missing values of


If bin_size=1, grab one date from before, one date ahead, one same-day-of-week in the prior week, and one same-day-of-week in the week after.


Each element of input variable has to be matched to consecute dates. The function operates under the assumption that the vector is sorted from oldest to the most recent date, and that there is no absent date.

By default the function starts imputing from the oldest to the most recent missing value. This may result in different imputed values from imputing in the reverse order (from recent to the oldest), since the later-imputed missing values may use earlier-imputed values as input for imputation. If you would like to impute from the most recent to the oldest date, reverse the order of the input variable.

By default, the missing values at the start and end of input variable vector, if they do not have enough prior or post values to impute using Compute_DoW_average, will be replaced by the mean of the variable.


Variable, in vector format, with missing values imputed. The non-missing values are same as the original input vector.


Jimin Lauren Yoo


data=data.frame("ID" = 1:23, "X" = X)
Compute_linear_fitted(data, "X", bin_size=1)

jmybhm/Impute_Mobile_Health documentation built on July 23, 2019, 2:11 a.m.