This function takes a fitted serp object produced by serp() and produces predicted values. Type of predictions returned include response, link and class. Prediction is also possible with new set of values having the same column names as in the original values used for the model fit.

# S3 method for serp
predict(object, type = c("link", "response", "class"), newdata = NULL, ...)

Arguments

object

An object of class serp.

type

could be any of these: response, link or terms.

newdata

fresh dataset with all relevant variables.

...

additional arguments.

Value

A vector of predicted classes with type equal to 'class' or a dataframe of predicted values for type equal to 'response' and 'link'.

Examples

library(serp)
m <- serp(rating ~ temp + contact, slope = "penalize",
           reverse = TRUE, link = "logit", tuneMethod = "user",
           lambda = 1, data = wine)

head(predict(m, type = "link"))
#>   logitlink(P[Y>=2]) logitlink(P[Y>=3]) logitlink(P[Y>=4]) logitlink(P[Y>=5])
#> 1           1.322412          -1.163636         -3.7198686          -5.346249
#> 2           1.322412          -1.163636         -3.7198686          -5.346249
#> 3           2.858788           0.296956         -2.1109684          -4.087473
#> 4           2.858788           0.296956         -2.1109684          -4.087473
#> 5           4.058936           1.144613         -0.9680906          -2.239792
#> 6           4.058936           1.144613         -0.9680906          -2.239792
head(predict(m, type = "response"))
#>            1         2         3          4           5
#> 1 0.21041723 0.5515755 0.2143436 0.01892023 0.004743386
#> 2 0.21041723 0.5515755 0.2143436 0.01892023 0.004743386
#> 3 0.05422884 0.3720729 0.4656629 0.09153069 0.016504618
#> 4 0.05422884 0.3720729 0.4656629 0.09153069 0.016504618
#> 5 0.01697428 0.2245001 0.4832644 0.17902762 0.096233637
#> 6 0.01697428 0.2245001 0.4832644 0.17902762 0.096233637
predict(m, type = "class")
#>  [1] 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3
#> [39] 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4
#> Levels: 1 2 3 4 5

n.wine <- wine[1:20,]
predict(m, newdata = n.wine, type = "class")
#>  [1] 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3
#> Levels: 1 2 3 4 5