Here you will find daily news and tutorials about R, contributed by over 573 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

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)
Loading required package: editrules
># 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
11 NA 424 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
113424 NA 1# a list of imputations performed> imp$corrections
row variable old new11 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.

Related

To leave a comment for the author, please follow the link and comment on their blog: Mark van der Loo.