Skip to contents

A pmodel is a model with reduced capacities. It can be used to make predictions, but it cannot be updated or re-fitted, and therefore not cross-validated.

Usage

pmodel(
  x,
  data,
  response,
  label = "pmodel",
  class = attr(x, "class")[[1]],
  weights = NULL,
  predict_function = predict
)

Arguments

x

A fitted model.

data

A data.frame.

response

A character string, the name of the response.

label

Character string: A label to be attributed to the output.

class

Class of the model x.

weights

Evaluation weights.

predict_function

Predict function, often predict (see “Details” section in ?model).

Value

An object of class “pmodel” (also inheriting of class “model”), a simplified version of a model, including the components label, data, response_type, response, fit, predict_function, class and weights. Unlike a model, it does not have components formula and call

Details

The model object x does not have to fulfill the formal requirements of a model (model formula, call component, etc.). The only requirement is that for any data set of the same shape as data, predictions can be obtained with the predict_function.

For tasks including only predicting, not re-fitting, the methods for class model also work for a pmodel. In particular, the following methods remain applicable: predict.model, residuals.model, response.model, performance.model, plot.model, label.model, weights.model. Among the generics with no appropriate method for a pmodel are fit (with arguments inducing a modification of the model), cv and all functions cv_* (cv_performance, cv_predict, etc.).

Examples

mylm <- lm(Sepal.Length ~ ., iris)
mypm <- pmodel(mylm, iris, "Sepal.Length")
mypm
#> --- A “pmodel” object ---
#>   label:          pmodel
#>   model class:    lm
#>   data:           data.frame [150 x 5]
#>   response_type:  continuous
#>   fit:            Object of class ‘lm’
predict(mypm)
#>        1        2        3        4        5        6        7        8 
#> 5.004788 4.756844 4.773097 4.889357 5.054377 5.388886 4.923684 5.038124 
#>        9       10       11       12       13       14       15       16 
#> 4.707255 4.920872 5.186890 5.121048 4.788359 4.539586 5.086884 5.470981 
#>       17       18       19       20       21       22       23       24 
#> 5.057188 4.973273 5.370812 5.204964 5.203972 5.123859 4.722679 5.059837 
#>       25       26       27       28       29       30       31       32 
#> 5.369821 4.922692 5.058017 5.087712 4.955199 5.021870 4.972281 4.975092 
#>       33       34       35       36       37       38       39       40 
#> 5.416761 5.351910 4.889357 4.690173 4.921864 5.085892 4.673919 5.038124 
#>       41       42       43       44       45       46       47       48 
#> 4.890348 4.295281 4.773097 5.044575 5.505146 4.725328 5.319403 4.856021 
#>       49       50       51       52       53       54       55       56 
#> 5.186890 4.905610 6.490778 6.293414 6.575522 5.495523 6.177983 6.158089 
#>       57       58       59       60       61       62       63       64 
#> 6.477336 5.059188 6.290603 5.579438 5.026681 5.945463 5.540480 6.342011 
#>       65       66       67       68       69       70       71       72 
#> 5.461359 6.192416 6.194236 5.871349 5.797525 5.574807 6.447640 5.743467 
#>       73       74       75       76       77       78       79       80 
#> 6.277989 6.355454 6.041829 6.142827 6.375347 6.545827 6.144647 5.324214 
#>       81       82       83       84       85       86       87       88 
#> 5.442294 5.390885 5.642470 6.511500 6.194236 6.361076 6.409674 5.827220 
#>       89       90       91       92       93       94       95       96 
#> 5.925569 5.594701 6.007503 6.308676 5.675805 5.009599 5.859727 6.040009 
#>       97       98       99      100      101      102      103      104 
#> 5.958905 6.041829 4.828488 5.826392 6.971778 6.117018 6.866149 6.662333 
#>      105      106      107      108      109      110      111      112 
#> 6.751709 7.446619 5.583325 7.242804 6.629826 7.203469 6.333447 6.282867 
#>      113      114      115      116      117      118      119      120 
#> 6.534451 5.903400 6.009029 6.404749 6.628997 7.894739 7.434006 5.912211 
#>      121      122      123      124      125      126      127      128 
#> 6.736446 5.969242 7.461881 5.982684 6.849066 7.142797 5.949349 6.131451 
#>      129      130      131      132      133      134      135      136 
#> 6.518198 6.940802 6.995851 7.708997 6.486682 6.292669 6.639628 6.968966 
#>      137      138      139      140      141      142      143      144 
#> 6.721184 6.678586 6.048527 6.501115 6.572418 6.189311 6.117018 6.902295 
#>      145      146      147      148      149      150 
#> 6.723004 6.222647 5.934916 6.317193 6.586851 6.297300 
residuals(mypm)
#>            1            2            3            4            5            6 
#>  0.095211981  0.143156450 -0.073096946 -0.289356835 -0.054376913  0.011114267 
#>            7            8            9           10           11           12 
#> -0.323683608 -0.038123516 -0.307254656 -0.020872352  0.213109802 -0.321047908 
#>           13           14           15           16           17           18 
#>  0.011640933 -0.239585893  0.713116294  0.229018580  0.342811832  0.126727498 
#>           19           20           21           22           23           24 
#>  0.329187643 -0.104963574  0.196027701 -0.023859163 -0.122679348  0.040163147 
#>           25           26           27           28           29           30 
#> -0.569821081  0.077307668 -0.058016873  0.112287590  0.244800875 -0.321870120 
#>           31           32           33           34           35           36 
#> -0.172281226  0.424907518 -0.216761291  0.148089724  0.010643165  0.309827445 
#>           37           38           39           40           41           42 
#>  0.578136372 -0.185892430 -0.273919159  0.061876484  0.109651890  0.204718616 
#>           43           44           45           46           47           48 
#> -0.373096946 -0.044574732 -0.405145622  0.074671968 -0.219403483 -0.256021337 
#>           49           50           51           52           53           54 
#>  0.113109802  0.094389769  0.509221918  0.106586218  0.324477547  0.004477184 
#>           55           56           57           58           59           60 
#>  0.322017402 -0.458089242 -0.177335941 -0.159187524  0.309397473 -0.379438483 
#>           61           62           63           64           65           66 
#> -0.026680731 -0.045462821  0.459519526 -0.242011401  0.138641386  0.507583985 
#>           67           68           69           70           71           72 
#> -0.594235995 -0.071349335  0.402475156  0.025192753 -0.547640404  0.356532715 
#>           73           74           75           76           77           78 
#>  0.022010910 -0.255453541  0.358170647  0.457172879  0.424653102  0.154173084 
#>           79           80           81           82           83           84 
#> -0.144647101  0.375785906  0.057706038  0.109114912  0.157530482 -0.511500143 
#>           85           86           87           88           89           90 
#> -0.794235995 -0.361076053  0.290326329  0.472779619 -0.325569464 -0.094700604 
#>           91           92           93           94           95           96 
#> -0.507502580 -0.208675903  0.124194985 -0.009598630 -0.259727174 -0.340009373 
#>           97           98           99          100          101          102 
#> -0.258904962  0.158170647  0.271512274 -0.126391677 -0.671777514 -0.317017734 
#>          103          104          105          106          107          108 
#>  0.233851489 -0.362332996 -0.251708602  0.153380750 -0.683324634  0.057196266 
#>          109          110          111          112          113          114 
#>  0.070173797 -0.003468587  0.166553314  0.117133483  0.265549054 -0.203400038 
#>          115          116          117          118          119          120 
#> -0.209029042 -0.004748917 -0.128997498 -0.194739274  0.265994187  0.087789057 
#>          121          122          123          124          125          126 
#>  0.163553518 -0.369242328  0.238118630  0.317315531 -0.149066410  0.057202758 
#>          127          128          129          130          131          132 
#>  0.250651028 -0.031451151 -0.118197550  0.259198294  0.404149460  0.191002865 
#>          133          134          135          136          137          138 
#> -0.086682032  0.007331302 -0.539628383  0.731033741 -0.421184361 -0.278586392 
#>          139          140          141          142          143          144 
#> -0.048526760  0.398884551  0.127582321  0.710688760 -0.317017734 -0.102295264 
#>          145          146          147          148          149          150 
#> -0.023004341  0.477353262  0.365084445  0.182806710 -0.386851096 -0.397299933 
response(mypm)
#>   [1] 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7 5.4 5.1
#>  [19] 5.7 5.1 5.4 5.1 4.6 5.1 4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4 5.2 5.5 4.9 5.0
#>  [37] 5.5 4.9 4.4 5.1 5.0 4.5 4.4 5.0 5.1 4.8 5.1 4.6 5.3 5.0 7.0 6.4 6.9 5.5
#>  [55] 6.5 5.7 6.3 4.9 6.6 5.2 5.0 5.9 6.0 6.1 5.6 6.7 5.6 5.8 6.2 5.6 5.9 6.1
#>  [73] 6.3 6.1 6.4 6.6 6.8 6.7 6.0 5.7 5.5 5.5 5.8 6.0 5.4 6.0 6.7 6.3 5.6 5.5
#>  [91] 5.5 6.1 5.8 5.0 5.6 5.7 5.7 6.2 5.1 5.7 6.3 5.8 7.1 6.3 6.5 7.6 4.9 7.3
#> [109] 6.7 7.2 6.5 6.4 6.8 5.7 5.8 6.4 6.5 7.7 7.7 6.0 6.9 5.6 7.7 6.3 6.7 7.2
#> [127] 6.2 6.1 6.4 7.2 7.4 7.9 6.4 6.3 6.1 7.7 6.3 6.4 6.0 6.9 6.7 6.9 5.8 6.8
#> [145] 6.7 6.7 6.3 6.5 6.2 5.9
performance(mypm)       
#> --- Performance table ---
#> Metric: rmse
#>        train_rmse test_rmse
#> pmodel    0.30063        NA