# Deductive imputation with the deducorrect package

Missing data hinders statistical analyses. Estimating missing values (imputation) prior to analysis is one way to deal with that. In some cases however, the missings need not be estimated at all, since they can be derived with certainty from other data which is present. The latest version of our package deducorrect can do this for numerical as well as for categorical data.

As an example, consider a record with three fields ,  and , subject to the rules




If we're given a record with values , the value for  can be easily derived, right? Right. You don't have to be a mathematician to impute  here. Now consider . We get , but since this violates the positivity rule above, this is not a valid imputation. The deduIpute function of our package can take this into account. Below is a short R-session, showing how to deductively impute with the deducorrect package.

> library(deducorrect)
> # define the rules
> E <- editmatrix(c(
+     "x + y == z",
+     "x >= 0", "y>=0", "z>=0"
+     )
+ )
> # some data:
> (dat <- data.frame(x=c(1,4),y=c(NA,NA),z=c(4,1)))
x  y z
1 1 NA 4
2 4 NA 1
>
# And now for the magic step: (deduImpute returns a
# 'deducorrect' object)
> imp <- deduImpute(E,dat)

> # the imputed data
> imp$corrected x y z 1 1 3 4 2 4 NA 1 # a list of imputations performed > imp$corrections
row variable old new
1   1        y  NA   3


The deduImpute function only imputes what can be imputed consistently, taking all (in)equality rules into account. Some of the lower-level (record-by-record) functionality is exported as well, and as said before, it also works for categorical data.

There's a lot more to say about deductive imputation. If you're interested in the mathematical background or want to see more examples, please read our paper which is included as the package vignette. Don't hesitate to drop us a line with comments, suggestions or if you find a little insect =:O.

This entry was posted in R and tagged , . Bookmark the permalink.