# na_predict: Replace missing values using multivariate statistical model In twolodzko/misster: Simple tools for dealing with missing values

## Description

Replace missing values using multivariate statistical model

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13``` ```na_predict(data, formula, learnFun, predictFun = predict, ...) na_lm(data, formula, ...) na_glm(data, formula, family = gaussian, ...) na_rpart(data, formula, ...) na_rf(data, formula, ...) na_nb(data, formula, ...) na_knn(data, formula, ...) ```

## Arguments

 `data` a data.frame. `formula` an object of class "`formula`": a symbolic description of the model to be fitted. `learnFun` learning function in form `learnFun(formula, data, ...)`. `predictFun` function used for making predictions in form `predictFun(object, newdata)`. `...` further arguments passed to `learnFun`. `family` in `na_glm`, this is the `family` argument from the `glm` method.

## Details

Multiple convenience wrappers allow user to use: linear regression (`na_lm`), generalized linear models (`na_glm`), recursive partitioning and regression trees (`na_rpart`), random forests (`na_rf`) and additionally, for categorical data: naive Bayes (`na_nb`) and k-nearest neighbour classifiers (`na_knn`). Both `na_rpart` and `na_rf` can be used for predicting continuous and categorical variables.

## See Also

`lm`, `glm`, `rpart`, `randomForest`, `naiveBayes`, `knn`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22``` ```set.seed(123) dat <- mtcars dat\$disp[sample.int(nrow(dat), 10)] <- NA dat\$gear[sample.int(nrow(dat), 10)] <- NA dat\$gear <- as.factor(dat\$gear) na_predict(dat, disp ~ mpg + drat, learnFun = glm, predictFun = function(object, newdata) { predict(object, newdata= newdata, type = "response") }) na_predict(dat, gear ~ mpg + drat, learnFun = e1071::naiveBayes) # continuous variables na_lm(dat, disp ~ mpg + drat) na_glm(dat, disp ~ mpg + drat) na_rpart(dat, disp ~ mpg + drat) na_rf(dat, disp ~ mpg + drat) # categorical variables na_nb(dat, gear ~ mpg + drat) na_knn(dat, gear ~ mpg + drat) na_rpart(dat, factor(gear) ~ mpg + drat) na_rf(dat, factor(gear) ~ mpg + drat) ```

twolodzko/misster documentation built on May 24, 2019, 2:54 p.m.