# Imputation by regression in R [closed]

Say I have below example data, where rows are observations and columns are variables, and NAs stand for missing values.

 1  2 NA  4  5 6 14 5  2
6 13  7  1 11 4 NA 9  6
15 12  3 12 NA 8  3 7 12
8  1 NA  7  8 9  4 6  1


I want to impute the missing values by regression (I know I can impute by means, but I need to see how regression performs). There is a CRAN package named 'Amelia' for imputation by regression, but it gives an error for above data saying that #observations is smaller than #variables. 'mi' package also gives an error. I can code myself, but I do not want to reinvent the wheel since I am sure there is already a package for that which would work faster than the one I write (Speed is important since I will run this imputation for thousands of variables and hundreds of observations with lots of missing values). So, does anybody know about a package which would impute the values above by regression? Thanks.

• regressionImp in package VIM
– rcs
Commented Jun 2, 2014 at 10:59
• Also give the R Hmisc package aregImpute function a try. But your sample size for testing all this is not adequate for any analysis. Commented Jun 2, 2014 at 11:44
• Amelia gave me the best results: gking.harvard.edu/amelia Commented Oct 18, 2014 at 12:24
• You cannot use Amelia where the number of observations is smaller than the number of variables, as in the example above (#variables=9 and #observations=4). Commented Oct 19, 2014 at 20:28

Even though this thread is a bit old, I am sure some people are still trying to find a solution in this thread. Therefore I want to add an example how you could use the mice package for regression imputation:

library("mice")

# Example data
data <- data.frame(x1 = c(1, 6, 15, 8, 5, 1, 7, 4),
x2 = c(2, 13, 12, 1, 6, 6, 1, 2),
x3 = c(NA, 7, 3, NA, 1, 2, 7, 3),
x4 = c(4, 1, 12, 7, 12, 1, 6, 6),
x5 = c(5, 11, NA, 8, 8, 11, 5, 6),
x6 = c(6, 4, 8, 9, 3, 9, 6, 12),
x7 = c(14, NA, 3, 4, 12, 5, 10, 10),
x8 = c(5, 9, 7, 6, 12, 2, 6, 3),
x9 = c(2, 6, 12, 1, 2, 2, 7, 1))

# Deterministic regression imputation via mice
imp <- mice(data, method = "norm.predict", m = 1)

# Store data
data_imp <- complete(imp)


With a larger dataset, You could also add a stochastic error term to the imputed values with the "norm.nob" method:

# Stochastic regression imputation
imp <- mice(data, method = "norm.nob", m = 1)


You can find further information on regression imputation in the following two links:

Deterministic vs. stochastic regression imputation & examples in R

Flexible Imputation of Missing Data of Stef van Buuren, the author of mice

• I don't think this method is deterministic. Try: complete(mice(nhanes, method='norm.predict', m=1, seed=123)) == complete(mice(nhanes, method='norm.predict', m=1, seed=456)) Commented Nov 17, 2017 at 19:06
• @AdamO This difference results from the chained equations approach of mice, i.e. in the forefront of the deterministic imputation missing values are replaced by a random draw from your data. The imputation that is conducted based on this filled data is completely deterministic. If you want to keep the starting data fixed, you can use the argument data.init. See also this thread for more details. Commented Nov 24, 2017 at 8:17