imputeData: imputeData

Description Usage Arguments Examples

View source: R/imputeData.R

Description

using tree model to impute na values in a data

Usage

1
2
imputeData(data, impVars, modelVars, seed = 1, treeMethod = c("rpart",
  "ctree"), treeParams = list(), method = c("sample", "pred")[1])

Arguments

data

data.frame

impVars

variables needed imputed

modelVars

variables used in cart tree model

treeParams

parameters control aspects of cart tree.

method

impute methods, could be sample and pred. when using sample, the na values will be imputed from the raw data in the terminal node of a tree model. when using pred, the na values will be imputed by the predicted value of cart tree model.

Examples

1
2
3
4
5
6
7
8
mt<-mtcars
set.seed(123)
mt[cbind(sample(1:30,10,rep=F),sample(1:3,10,rep=T))]<-NA
imputeData(mt,impVars=names(mt)[1:3],modelVars=names(mt),treeParams=list(maxdepth=5,minbucket=7,minsplit=20,cp=0.01),method='sample')->mtImpSample
imputeData(mt,impVars=names(mt)[1:3],modelVars=names(mt),treeParams=list(maxdepth=5,minbucket=7,minsplit=20,cp=0.01),method='pred')->mtImpPred

plot(mtcars$mpg,mtImpSample$mpg)
plot(mtcars$mpg,mtImpPred$mpg)

sontron/madis documentation built on March 23, 2021, 10:17 p.m.