A predict generic function for condvis

CVpredict(
  fit,
  newdata,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL,
  pinterval = NULL,
  pinterval_level = 0.95
)

# S3 method for default
CVpredict(
  fit,
  newdata,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  pinterval = NULL,
  pinterval_level = 0.95,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for lm
CVpredict(
  fit,
  newdata,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  pinterval = NULL,
  pinterval_level = 0.95,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for glm
CVpredict(
  fit,
  ...,
  type = "response",
  ptype = "pred",
  pthreshold = NULL,
  pinterval = NULL,
  pinterval_level = 0.95,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for lda
CVpredict(
  fit,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for qda
CVpredict(
  fit,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for nnet
CVpredict(
  fit,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for randomForest
CVpredict(
  fit,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for ranger
CVpredict(
  fit,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for rpart
CVpredict(
  fit,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for tree
CVpredict(
  fit,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for C5.0
CVpredict(
  fit,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for svm
CVpredict(
  fit,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for gbm
CVpredict(
  fit,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  n.trees = fit$n.trees,
  ptrans = NULL
)

# S3 method for loess
CVpredict(fit, newdata = NULL, ...)

# S3 method for ksvm
CVpredict(
  fit,
  newdata,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for glmnet
CVpredict(
  fit,
  newdata,
  ...,
  type = "response",
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL,
  s = NULL,
  makex = NULL
)

# S3 method for cv.glmnet
CVpredict(
  fit,
  newdata,
  ...,
  type = "response",
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL,
  makex = NULL
)

# S3 method for glmnet.formula
CVpredict(
  fit,
  newdata,
  ...,
  type = "response",
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL,
  s = NULL
)

# S3 method for cv.glmnet.formula
CVpredict(
  fit,
  newdata,
  ...,
  type = "response",
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for keras.engine.training.Model
CVpredict(
  fit,
  newdata,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL,
  batch_size = 32,
  response = NULL,
  predictors = NULL
)

# S3 method for kde
CVpredict(fit, newdata = fit$x, ..., scale = TRUE)

# S3 method for densityMclust
CVpredict(
  fit,
  newdata = NULL,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL,
  scale = TRUE
)

# S3 method for MclustDA
CVpredict(
  fit,
  newdata,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for MclustDR
CVpredict(
  fit,
  newdata,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for Mclust
CVpredict(
  fit,
  newdata,
  ...,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for train
CVpredict(
  fit,
  newdata,
  ...,
  type = "response",
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for bartMachine
CVpredict(
  fit,
  newdata,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for wbart
CVpredict(
  fit,
  newdata,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for lbart
CVpredict(
  fit,
  newdata,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for pbart
CVpredict(
  fit,
  newdata,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for bart
CVpredict(
  fit,
  newdata,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL
)

# S3 method for model_fit
CVpredict(
  fit,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL,
  pinterval = NULL,
  pinterval_level = 0.95
)

# S3 method for WrappedModel
CVpredict(
  fit,
  newdata,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL,
  pinterval = NULL,
  pinterval_level = 0.95
)

# S3 method for Learner
CVpredict(
  fit,
  newdata,
  ...,
  type = NULL,
  ptype = "pred",
  pthreshold = NULL,
  ylevels = NULL,
  ptrans = NULL,
  pinterval = NULL,
  pinterval_level = 0.95
)

Arguments

fit

A fitted model

newdata

Where to calculate predictions.

...

extra arguments to predict

ptype

One of "pred","prob" or "probmatrix"

pthreshold

Used for calculating classes from probs, in the two class case

ylevels

The levels of the response, when it is a factor

ptrans

A function to apply to the result

pinterval

NULL, "confidence" or "prediction". Only for lm, parsnip, mlr(regression, confidence only)

pinterval_level

Defaults to 0.95

type

For some predict methods

n.trees

Used by CVpredict.gbm, passed to predict

s

Used by CVpredict.glmnet and CVpredict.cv.glmnet, passed to predict

makex

Used by CVpredict.glmnet and CVpredict.cv.glmnet. A function to construct xmatrix for predict.

batch_size

Used by CVpredict.keras.engine.training.Model, passed to predict

response

Used by CVpredict.keras.engine.training.Model. Name of response (optional)

predictors

Used by CVpredict.keras.engine.training.Model. Name of predictors

scale

Used by CVpredict for densities. If TRUE (default) rescales the conditional density to integrate to 1.

Value

a vector of predictions, or a matrix when type is "probmatrix"

Details

This is a wrapper for predict used by condvis. When the model response is numeric, the result is a vector of predictions. When the model response is a factor the result depends on the value of ptype. If ptype="pred", the result is a factor. If also threshold is numeric, it is used to threshold a numeric prediction to construct the factor when the factor has two levels. For ptype="prob", the result is a vector of probabilities for the last factor level. For ptype="probmatrix", the result is a matrix of probabilities for each factor level.

Methods (by class)

  • CVpredict(default): CVpredict method

  • CVpredict(lm): CVpredict method

  • CVpredict(glm): CVpredict method

  • CVpredict(lda): CVpredict method

  • CVpredict(qda): CVpredict method

  • CVpredict(nnet): CVpredict method

  • CVpredict(randomForest): CVpredict method

  • CVpredict(ranger): CVpredict method

  • CVpredict(rpart): CVpredict method

  • CVpredict(tree): CVpredict method

  • CVpredict(C5.0): CVpredict method

  • CVpredict(svm): CVpredict method

  • CVpredict(gbm): CVpredict method

  • CVpredict(loess): CVpredict method

  • CVpredict(ksvm): CVpredict method

  • CVpredict(glmnet): CVpredict method

  • CVpredict(cv.glmnet): CVpredict method

  • CVpredict(glmnet.formula): CVpredict method

  • CVpredict(cv.glmnet.formula): CVpredict method

  • CVpredict(keras.engine.training.Model): CVpredict method

  • CVpredict(kde): CVpredict method

  • CVpredict(densityMclust): CVpredict method

  • CVpredict(MclustDA): CVpredict method

  • CVpredict(MclustDR): CVpredict method

  • CVpredict(Mclust): CVpredict method

  • CVpredict(train): CVpredict method for caret

  • CVpredict(bartMachine): CVpredict method

  • CVpredict(wbart): CVpredict method

  • CVpredict(lbart): CVpredict method

  • CVpredict(pbart): CVpredict method

  • CVpredict(bart): CVpredict method

  • CVpredict(model_fit): CVpredict method for parsnip

  • CVpredict(WrappedModel): CVpredict method for mlr

  • CVpredict(Learner): CVpredict method for mlr3

Examples

#Fit a model. 
f <- lm(Fertility~ ., data=swiss)
CVpredict(f)
#>   Courtelary     Delemont Franches-Mnt      Moutier   Neuveville   Porrentruy 
#>     74.61530     82.50994     85.91826     76.82039     64.70241     90.50011 
#>        Broye        Glane      Gruyere       Sarine      Veveyse        Aigle 
#>     79.69351     81.60056     81.33578     79.47931     83.63057     59.03302 
#>      Aubonne     Avenches     Cossonay    Echallens     Grandson     Lausanne 
#>     66.39675     66.02465     65.39121     73.38669     71.59419     55.49884 
#>    La Vallee       Lavaux       Morges       Moudon        Nyone         Orbe 
#>     50.73796     63.44690     62.16857     75.80325     61.59013     64.13413 
#>         Oron      Payerne Paysd'enhaut        Rolle        Vevey      Yverdon 
#>     73.56152     72.51399     71.47848     61.97277     63.73674     72.42658 
#>      Conthey    Entremont       Herens     Martigwy      Monthey   St Maurice 
#>     76.25945     76.97478     78.56615     76.33212     83.30869     73.17632 
#>       Sierre         Sion       Boudry La Chauxdfnd     Le Locle    Neuchatel 
#>     76.87869     70.95452     65.59572     72.04256     68.56686     53.51934 
#>   Val de Ruz ValdeTravers V. De Geneve  Rive Droite  Rive Gauche 
#>     72.53541     73.05290     34.79763     54.36209     58.07426 

#Fit a model with a factor response
swiss1 <- swiss
swiss1$Fertility <-  cut(swiss$Fertility, c(0,80,100))
levels(swiss1$Fertility)<- c("lo", "hi")
f <- glm(Fertility~ ., data=swiss1, family="binomial")
CVpredict(f) # by default gives a factor
#>  [1] lo hi hi lo lo hi lo hi hi hi hi lo lo lo lo lo lo lo lo lo lo lo lo lo lo
#> [26] lo lo lo lo lo lo lo lo lo hi lo lo lo lo lo lo lo lo lo lo lo lo
#> Levels: lo hi
CVpredict(f, ptype="prob") # gives prob of level hi
#>  [1] 0.396514295 0.861764264 0.909279844 0.332544446 0.032936859 0.979777528
#>  [7] 0.440886237 0.663091523 0.680884448 0.766680073 0.726807397 0.002254863
#> [13] 0.010054694 0.019461926 0.003390852 0.027195256 0.078436139 0.022608733
#> [19] 0.001026875 0.004316500 0.003832595 0.090358030 0.005694209 0.004003802
#> [25] 0.028947008 0.081614140 0.034337002 0.004890035 0.047863977 0.086947385
#> [31] 0.151574937 0.275104859 0.231597035 0.212834690 0.664406245 0.181141244
#> [37] 0.208021362 0.190369261 0.017460214 0.130143834 0.085070861 0.017571156
#> [43] 0.089999302 0.088208649 0.004325098 0.025922023 0.077848295
CVpredict(f, ptype="probmatrix") # gives prob of both levels
#>               lo          hi
#>  [1,] 0.60348571 0.396514295
#>  [2,] 0.13823574 0.861764264
#>  [3,] 0.09072016 0.909279844
#>  [4,] 0.66745555 0.332544446
#>  [5,] 0.96706314 0.032936859
#>  [6,] 0.02022247 0.979777528
#>  [7,] 0.55911376 0.440886237
#>  [8,] 0.33690848 0.663091523
#>  [9,] 0.31911555 0.680884448
#> [10,] 0.23331993 0.766680073
#> [11,] 0.27319260 0.726807397
#> [12,] 0.99774514 0.002254863
#> [13,] 0.98994531 0.010054694
#> [14,] 0.98053807 0.019461926
#> [15,] 0.99660915 0.003390852
#> [16,] 0.97280474 0.027195256
#> [17,] 0.92156386 0.078436139
#> [18,] 0.97739127 0.022608733
#> [19,] 0.99897312 0.001026875
#> [20,] 0.99568350 0.004316500
#> [21,] 0.99616740 0.003832595
#> [22,] 0.90964197 0.090358030
#> [23,] 0.99430579 0.005694209
#> [24,] 0.99599620 0.004003802
#> [25,] 0.97105299 0.028947008
#> [26,] 0.91838586 0.081614140
#> [27,] 0.96566300 0.034337002
#> [28,] 0.99510997 0.004890035
#> [29,] 0.95213602 0.047863977
#> [30,] 0.91305261 0.086947385
#> [31,] 0.84842506 0.151574937
#> [32,] 0.72489514 0.275104859
#> [33,] 0.76840297 0.231597035
#> [34,] 0.78716531 0.212834690
#> [35,] 0.33559376 0.664406245
#> [36,] 0.81885876 0.181141244
#> [37,] 0.79197864 0.208021362
#> [38,] 0.80963074 0.190369261
#> [39,] 0.98253979 0.017460214
#> [40,] 0.86985617 0.130143834
#> [41,] 0.91492914 0.085070861
#> [42,] 0.98242884 0.017571156
#> [43,] 0.91000070 0.089999302
#> [44,] 0.91179135 0.088208649
#> [45,] 0.99567490 0.004325098
#> [46,] 0.97407798 0.025922023
#> [47,] 0.92215171 0.077848295