Learn R Programming

toweranNA (version 0.1.0)

makeTower: Nonimputational method for dealing with NA values in prediction application

Description

In a prediction application, the intended regression model is applied to complete cases, from which marginal regression models can be derived for predicting new cases having arbitrary NA patterns.

Usage

makeTower(data,yName,regFtnName,opts,scaling=NULL,yesYVal=NULL)
# S3 method for tower
predict(object,newx,k=1,...)

Value

Object of class 'tower', to be used as input to predict.tower.

Arguments

data

Data frame or equivalent.

yName

Name of the column in data to be predicted.

regFtnName

Regression model to be used, currently 'lm', 'glm' (family=binomial), or 'towerKNN'.

opts

Optional arguments for regFtnName, an R list.

k

number of nearest neighbors

scaling

Scaling to be applied to x and newx. Default NULL means no scaling.

yesYVal

In the case of dichotomous Y, this specifies the level to be considered positive, i.e. for which Y will be 1.

object

Object of type 'tower'.

newx

New case(s) to be predicted, in the same format as in the non-Y portion of data.

...

Other arguments need by regFtnName.

Author

Norm Matloff, Pete Mohanty

Examples

Run this code
towerOut <- makeTower(mtcars,'mpg','lm')

newx <- mtcars[-c(1:10),-1]
for(i in 1:10)
  newx[i, i] <- NA

head(newx)
#                     cyl  disp  hp drat    wt  qsec vs am gear carb
# Merc 280C            NA 167.6 123 3.92 3.440 18.90  1  0    4    4
# Merc 450SE            8    NA 180 3.07 4.070 17.40  0  0    3    3
# Merc 450SL            8 275.8  NA 3.07 3.730 17.60  0  0    3    3
# Merc 450SLC           8 275.8 180   NA 3.780 18.00  0  0    3    3
# Cadillac Fleetwood    8 472.0 205 2.93    NA 17.98  0  0    3    4
# Lincoln Continental   8 460.0 215 3.00 5.424    NA  0  0    3    4
 
predict(towerOut,newx,k=3)
#  [1] 20.00086 15.17132 15.17132 15.17132 11.15469 11.15469 11.15469 28.52625
#  [9] 29.06067 28.52625 24.72144 17.45622 16.75827 15.52077 14.95958 28.52625
# [17] 25.34890 26.08506 15.52077 19.19484 15.37239 24.72144

Run the code above in your browser using DataLab