Gulnaz
Gulnaz

Reputation: 21

How to perform sensitivity analysis using Lek's profile in R?

I am trying to do sensitivity analysis using R. My data set has few continuous explanatory variables and a categorical response variable (7 categories).

I tried to run the below mentioned code.

model=train(factor(mode)~Time+Cost+Age+Income, 
            method="nnet",
            preProcess("center","scale"),
            data=train, 
            verbose=F, 
            trControl=trainControl(method='cv', verboseIter = F), 
            tuneGrid=expand.grid(.size=c(1:20), .decay=c(0,0.001,0.01,0.1)))

After getting the output through this code, I tried to develop Lek's profile using the below mentioned code.

Lekprofile(model)

          

However, I got the error stating "Errors in xvars[, x_names]: subscript out of bound"

Please help me to resolve the error.

Upvotes: 2

Views: 442

Answers (1)

StupidWolf
StupidWolf

Reputation: 46908

It doesn't work for a classification model , for example, if we use a regression model:

library(caret)
library(NeuralNetTools)
library(mlbench)

data(BostonHousing)
str(BostonHousing)
'data.frame':   506 obs. of  14 variables:
 $ crim   : num  0.00632 0.02731 0.02729 0.03237 0.06905 ...
 $ zn     : num  18 0 0 0 0 0 12.5 12.5 12.5 12.5 ...
 $ indus  : num  2.31 7.07 7.07 2.18 2.18 2.18 7.87 7.87 7.87 7.87 ...
 $ chas   : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
 $ nox    : num  0.538 0.469 0.469 0.458 0.458 0.458 0.524 0.524 0.524 0.524 ...
 $ rm     : num  6.58 6.42 7.18 7 7.15 ...
 $ age    : num  65.2 78.9 61.1 45.8 54.2 58.7 66.6 96.1 100 85.9 ...
 $ dis    : num  4.09 4.97 4.97 6.06 6.06 ...
 $ rad    : num  1 2 2 3 3 3 5 5 5 5 ...
 $ tax    : num  296 242 242 222 222 222 311 311 311 311 ...
 $ ptratio: num  15.3 17.8 17.8 18.7 18.7 18.7 15.2 15.2 15.2 15.2 ...
 $ b      : num  397 397 393 395 397 ...
 $ lstat  : num  4.98 9.14 4.03 2.94 5.33 ...
 $ medv   : num  24 21.6 34.7 33.4 36.2 28.7 22.9 27.1 16.5 18.9 ...

We train the model, exclude the categorical chas:

model = train(medv ~ .,data=BostonHousing[,-4],method="nnet",
trControl=trainControl(method="cv",number=10),
tuneGrid=data.frame(size=c(5,10,20),decay=0.1))

lekprofile(model)

enter image description here

You can see the y-axis is meant to be continuous. We can try to discretize our response variable medv and you can see it crashes:

BostonHousing$medv = cut(BostonHousing$medv,4)

model = train(medv ~ .,data=BostonHousing[,-4],method="nnet",
trControl=trainControl(method="cv",number=10),
tuneGrid=data.frame(size=c(5,10,20),decay=0.1))

lekprofile(model)
Error in `[.data.frame`(preds, , ysel, drop = FALSE) : 
  undefined columns selected

Upvotes: 1

Related Questions