Skip to contents

Evaluate a model on inputs

Usage

model_eval(
  mod,
  data = NULL,
  ...,
  skeleton = FALSE,
  ncont = 3,
  interval = c("prediction", "confidence", "none"),
  level = 0.95,
  type = c("response", "link")
)

Arguments

mod

A model as from model_train(), lm() or glm()

data

A data frame of inputs. If missing, the inputs will be assembled from ... or from the training data, or an skeleton will be constructed.

skeleton

Logical flag. If TRUE, a skeleton on inputs will be created. See model_skeleton().

ncont

Only relevant to skeleton. The number of levels at which to evaluate continuous variables. See model_skeleton().

interval

One of "prediction" (default), "confidence", or "none".

level

The level at which to construct the interval (default: 0.95)

type

Either "response" (default) or "link". Relevant only to glm models. The format of the .output

...

Optional vectors specifying the inputs. See examples.

Value

A data frame. There is one row for each row of the input values (see data parameter). The columns include

  • the explanatory variables

  • .output --- the output of the model that corresponds to the explanatory value

  • the .lwr and .upr bounds of the prediction or confidence interval

  • if training data is used as the input, the .response variable and the .resid. Note that the generic name .response is used, not the actual name of the model's response variable.

Examples

mod <- mtcars |> model_train(mpg ~ hp + wt)
model_eval(mod, hp=100, wt=c(2,3))
#>    hp wt     .lwr  .output     .upr
#> 1 100  2 20.77632 26.29431 31.81231
#> 2 100  3 16.98362 22.41648 27.84934
model_eval(mod) # training data
#> Using training data as input to model_eval().
#>    .response  hp    wt      .lwr   .output     .upr      .resid
#> 1       21.0 110 2.620 18.152053 23.572329 28.99261 -2.57232940
#> 2       21.0 110 2.875 17.173052 22.583483 27.99391 -1.58348256
#> 3       22.8  93 2.320 19.814373 25.275819 30.73726 -2.47581872
#> 4       21.4 110 3.215 15.836451 21.265020 26.69359  0.13497989
#> 5       18.7 175 3.440 12.926266 18.327267 23.72827  0.37273336
#> 6       18.1 105 3.460 14.994498 20.473816 25.95313 -2.37381631
#> 7       14.3 245 3.570  9.993171 15.599042 21.20491 -1.29904236
#> 8       24.4  62 3.190 17.284608 22.887067 28.48953  1.51293266
#> 9       22.8  95 3.150 16.532703 21.993673 27.45464  0.80632669
#> 10      19.2 123 3.440 14.552353 19.979460 25.40657 -0.77945988
#> 11      17.8 123 3.440 14.552353 19.979460 25.40657 -2.17945988
#> 12      16.4 180 4.070 10.274249 15.725369 21.17649  0.67463146
#> 13      17.3 180 3.730 11.631452 17.043831 22.45621  0.25616901
#> 14      15.2 180 3.780 11.434088 16.849939 22.26579 -1.64993945
#> 15      10.4 205 5.250  4.579380 10.355205 16.13103  0.04479541
#> 16      10.4 215 5.424  3.530661  9.362733 15.19480  1.03726743
#> 17      14.7 230 5.345  3.414919  9.192487 14.97006  5.50751301
#> 18      32.4  66 2.200 21.087052 26.599028 32.11100  5.80097202
#> 19      30.4  52 1.615 23.691616 29.312380 34.93314  1.08761978
#> 20      33.9  65 1.835 22.484454 28.046209 33.60796  5.85379085
#> 21      21.5  97 2.465 19.143493 24.586441 30.02939 -3.08644148
#> 22      15.5 150 3.520 13.413350 18.811364 24.20938 -3.31136386
#> 23      15.2 150 3.435 13.749010 19.140979 24.53295 -3.94097947
#> 24      13.3 245 3.840  8.981473 14.552028 20.12258 -1.25202805
#> 25      19.2 175 3.845 11.335804 16.756745 22.17769  2.44325481
#> 26      27.3  66 1.935 22.083269 27.626653 33.17004 -0.32665313
#> 27      26.0  91 2.140 20.548743 26.037374 31.52601 -0.03737415
#> 28      30.4 113 1.513 22.072733 27.769769 33.46681  2.63023081
#> 29      15.8 264 3.170 10.725413 16.546489 22.36756 -0.74648866
#> 30      19.7 175 2.770 15.446364 20.925413 26.40446 -1.22541324
#> 31      15.0 335 3.570  6.476550 12.739477 19.00240  2.26052287
#> 32      21.4 109 2.780 17.570829 22.983649 28.39647 -1.58364943
model_eval(mod, skeleton=TRUE)
#>      hp wt        .lwr   .output      .upr
#> 1    50  0 29.33460511 35.638623 41.942640
#> 2    55  0 29.16106307 35.479758 41.798453
#> 3    60  0 28.98620890 35.320893 41.655578
#> 4    65  0 28.81005251 35.162029 41.514005
#> 5    70  0 28.63260449 35.003164 41.373723
#> 6    75  0 28.45387612 34.844299 41.234722
#> 7    80  0 28.27387930 34.685434 41.096989
#> 8    85  0 28.09262652 34.526570 40.960513
#> 9    90  0 27.91013085 34.367705 40.825279
#> 10   95  0 27.72640588 34.208840 40.691274
#> 11  100  0 27.54146570 34.049975 40.558485
#> 12  105  0 27.35532485 33.891111 40.426897
#> 13  110  0 27.16799830 33.732246 40.296494
#> 14  115  0 26.97950140 33.573381 40.167261
#> 15  120  0 26.78984986 33.414516 40.039183
#> 16  125  0 26.59905970 33.255652 39.912244
#> 17  130  0 26.40714722 33.096787 39.786427
#> 18  135  0 26.21412897 32.937922 39.661716
#> 19  140  0 26.02002170 32.779058 39.538093
#> 20  145  0 25.82484238 32.620193 39.415543
#> 21  150  0 25.62860808 32.461328 39.294048
#> 22  155  0 25.43133602 32.302463 39.173591
#> 23  160  0 25.23304351 32.143599 39.054154
#> 24  165  0 25.03374790 31.984734 38.935720
#> 25  170  0 24.83346661 31.825869 38.818272
#> 26  175  0 24.63221703 31.667004 38.701792
#> 27  180  0 24.43001657 31.508140 38.586263
#> 28  185  0 24.22688257 31.349275 38.471667
#> 29  190  0 24.02283235 31.190410 38.357988
#> 30  195  0 23.81788310 31.031545 38.245208
#> 31  200  0 23.61205196 30.872681 38.133309
#> 32  205  0 23.40535593 30.713816 38.022276
#> 33  210  0 23.19781187 30.554951 37.912091
#> 34  215  0 22.98943650 30.396087 37.802737
#> 35  220  0 22.78024639 30.237222 37.694197
#> 36  225  0 22.57025792 30.078357 37.586456
#> 37  230  0 22.35948727 29.919492 37.479497
#> 38  235  0 22.14795046 29.760628 37.373305
#> 39  240  0 21.93566327 29.601763 37.267862
#> 40  245  0 21.72264129 29.442898 37.163155
#> 41  250  0 21.50889986 29.284033 37.059167
#> 42  255  0 21.29445411 29.125169 36.955883
#> 43  260  0 21.07931894 28.966304 36.853289
#> 44  265  0 20.86350899 28.807439 36.751369
#> 45  270  0 20.64703867 28.648574 36.650110
#> 46  275  0 20.42992213 28.489710 36.549497
#> 47  280  0 20.21217330 28.330845 36.449517
#> 48  285  0 19.99380582 28.171980 36.350155
#> 49  290  0 19.77483310 28.013115 36.251398
#> 50  295  0 19.55526830 27.854251 36.153233
#> 51  300  0 19.33512431 27.695386 36.055648
#> 52  305  0 19.11441376 27.536521 35.958629
#> 53  310  0 18.89314906 27.377657 35.862164
#> 54  315  0 18.67134234 27.218792 35.766241
#> 55  320  0 18.44900547 27.059927 35.670849
#> 56  325  0 18.22615011 26.901062 35.575975
#> 57  330  0 18.00278764 26.742198 35.481608
#> 58  335  0 17.77892920 26.583333 35.387737
#> 59   50  2 22.31727530 27.882961 33.448647
#> 60   55  2 22.17006556 27.724097 33.278128
#> 61   60  2 22.02134212 27.565232 33.109122
#> 62   65  2 21.87109665 27.406367 32.941638
#> 63   70  2 21.71932203 27.247502 32.775683
#> 64   75  2 21.56601238 27.088638 32.611263
#> 65   80  2 21.41116305 26.929773 32.448383
#> 66   85  2 21.25477070 26.770908 32.287046
#> 67   90  2 21.09683323 26.612043 32.127254
#> 68   95  2 20.93734988 26.453179 31.969007
#> 69  100  2 20.77632115 26.294314 31.812307
#> 70  105  2 20.61374888 26.135449 31.657150
#> 71  110  2 20.44963616 25.976584 31.503533
#> 72  115  2 20.28398738 25.817720 31.351452
#> 73  120  2 20.11680818 25.658855 31.200902
#> 74  125  2 19.94810543 25.499990 31.051875
#> 75  130  2 19.77788722 25.341126 30.904364
#> 76  135  2 19.60616281 25.182261 30.758359
#> 77  140  2 19.43294258 25.023396 30.613850
#> 78  145  2 19.25823803 24.864531 30.470825
#> 79  150  2 19.08206170 24.705667 30.329271
#> 80  155  2 18.90442714 24.546802 30.189177
#> 81  160  2 18.72534885 24.387937 30.050525
#> 82  165  2 18.54484223 24.229072 29.913303
#> 83  170  2 18.36292353 24.070208 29.777492
#> 84  175  2 18.17960979 23.911343 29.643076
#> 85  180  2 17.99491878 23.752478 29.510038
#> 86  185  2 17.80886894 23.593613 29.378358
#> 87  190  2 17.62147935 23.434749 29.248018
#> 88  195  2 17.43276962 23.275884 29.118998
#> 89  200  2 17.24275987 23.117019 28.991279
#> 90  205  2 17.05147066 22.958155 28.864838
#> 91  210  2 16.85892295 22.799290 28.739657
#> 92  215  2 16.66513803 22.640425 28.615712
#> 93  220  2 16.47013744 22.481560 28.492983
#> 94  225  2 16.27394299 22.322696 28.371448
#> 95  230  2 16.07657663 22.163831 28.251085
#> 96  235  2 15.87806045 22.004966 28.131872
#> 97  240  2 15.67841663 21.846101 28.013786
#> 98  245  2 15.47766740 21.687237 27.896806
#> 99  250  2 15.27583495 21.528372 27.780909
#> 100 255  2 15.07294147 21.369507 27.666073
#> 101 260  2 14.86900907 21.210642 27.552276
#> 102 265  2 14.66405971 21.051778 27.439496
#> 103 270  2 14.45811527 20.892913 27.327711
#> 104 275  2 14.25119741 20.734048 27.216899
#> 105 280  2 14.04332762 20.575183 27.107039
#> 106 285  2 13.83452717 20.416319 26.998110
#> 107 290  2 13.62481707 20.257454 26.890091
#> 108 295  2 13.41421808 20.098589 26.782960
#> 109 300  2 13.20275068 19.939725 26.676698
#> 110 305  2 12.99043505 19.780860 26.571285
#> 111 310  2 12.77729106 19.621995 26.466699
#> 112 315  2 12.56333826 19.463130 26.362922
#> 113 320  2 12.34859587 19.304266 26.259935
#> 114 325  2 12.13308277 19.145401 26.157719
#> 115 330  2 11.91681748 18.986536 26.056255
#> 116 335  2 11.69981817 18.827671 25.955525
#> 117  50  4 14.15986012 20.127300 26.094739
#> 118  55  4 14.03835341 19.968435 25.898517
#> 119  60  4 13.91563671 19.809570 25.703504
#> 120  65  4 13.79168761 19.650706 25.509724
#> 121  70  4 13.66648396 19.491841 25.317198
#> 122  75  4 13.54000390 19.332976 25.125948
#> 123  80  4 13.41222589 19.174111 24.935997
#> 124  85  4 13.28312883 19.015247 24.747364
#> 125  90  4 13.15269205 18.856382 24.560072
#> 126  95  4 13.02089543 18.697517 24.374139
#> 127 100  4 12.88771943 18.538652 24.189585
#> 128 105  4 12.75314516 18.379788 24.006430
#> 129 110  4 12.61715443 18.220923 23.824692
#> 130 115  4 12.47972983 18.062058 23.644387
#> 131 120  4 12.34085478 17.903194 23.465532
#> 132 125  4 12.20051360 17.744329 23.288144
#> 133 130  4 12.05869153 17.585464 23.112237
#> 134 135  4 11.91537484 17.426599 22.937824
#> 135 140  4 11.77055086 17.267735 22.764918
#> 136 145  4 11.62420799 17.108870 22.593532
#> 137 150  4 11.47633582 16.950005 22.423674
#> 138 155  4 11.32692512 16.791140 22.255356
#> 139 160  4 11.17596790 16.632276 22.088583
#> 140 165  4 11.02345741 16.473411 21.923364
#> 141 170  4 10.86938822 16.314546 21.759704
#> 142 175  4 10.71375622 16.155681 21.597607
#> 143 180  4 10.55655861 15.996817 21.437075
#> 144 185  4 10.39779396 15.837952 21.278110
#> 145 190  4 10.23746218 15.679087 21.120712
#> 146 195  4 10.07556453 15.520222 20.964880
#> 147 200  4  9.91210363 15.361358 20.810612
#> 148 205  4  9.74708344 15.202493 20.657903
#> 149 210  4  9.58050922 15.043628 20.506747
#> 150 215  4  9.41238754 14.884764 20.357140
#> 151 220  4  9.24272623 14.725899 20.209071
#> 152 225  4  9.07153438 14.567034 20.062534
#> 153 230  4  8.89882226 14.408169 19.917516
#> 154 235  4  8.72460129 14.249305 19.774008
#> 155 240  4  8.54888403 14.090440 19.631996
#> 156 245  4  8.37168407 13.931575 19.491466
#> 157 250  4  8.19301604 13.772710 19.352405
#> 158 255  4  8.01289550 13.613846 19.214796
#> 159 260  4  7.83133892 13.454981 19.078623
#> 160 265  4  7.64836363 13.296116 18.943869
#> 161 270  4  7.46398769 13.137251 18.810515
#> 162 275  4  7.27822993 12.978387 18.678544
#> 163 280  4  7.09110980 12.819522 18.547934
#> 164 285  4  6.90264735 12.660657 18.418667
#> 165 290  4  6.71286318 12.501793 18.290722
#> 166 295  4  6.52177835 12.342928 18.164077
#> 167 300  4  6.32941433 12.184063 18.038712
#> 168 305  4  6.13579294 12.025198 17.914604
#> 169 310  4  5.94093633 11.866334 17.791731
#> 170 315  4  5.74486684 11.707469 17.670071
#> 171 320  4  5.54760705 11.548604 17.549601
#> 172 325  4  5.34917965 11.389739 17.430299
#> 173 330  4  5.14960742 11.230875 17.312142
#> 174 335  4  4.94891321 11.072010 17.195107
#> 175  50  6  5.04763215 12.371638 19.695644
#> 176  55  6  4.94079099 12.212774 19.484756
#> 177  60  6  4.83314377 12.053909 19.274674
#> 178  65  6  4.72467321 11.895044 19.065415
#> 179  70  6  4.61536184 11.736179 18.856997
#> 180  75  6  4.50519197 11.577315 18.649437
#> 181  80  6  4.39414576 11.418450 18.442754
#> 182  85  6  4.28220519 11.259585 18.236965
#> 183  90  6  4.16935209 11.100720 18.032089
#> 184  95  6  4.05556817 10.941856 17.828143
#> 185 100  6  3.94083504 10.782991 17.625147
#> 186 105  6  3.82513420 10.624126 17.423118
#> 187 110  6  3.70844712 10.465261 17.222076
#> 188 115  6  3.59075521 10.306397 17.022038
#> 189 120  6  3.47203988 10.147532 16.823024
#> 190 125  6  3.35228255  9.988667 16.625052
#> 191 130  6  3.23146470  9.829803 16.428140
#> 192 135  6  3.10956788  9.670938 16.232308
#> 193 140  6  2.98657375  9.512073 16.037572
#> 194 145  6  2.86246411  9.353208 15.843953
#> 195 150  6  2.73722097  9.194344 15.651466
#> 196 155  6  2.61082651  9.035479 15.460131
#> 197 160  6  2.48326319  8.876614 15.269965
#> 198 165  6  2.35451378  8.717749 15.080985
#> 199 170  6  2.22456135  8.558885 14.893208
#> 200 175  6  2.09338935  8.400020 14.706651
#> 201 180  6  1.96098166  8.241155 14.521329
#> 202 185  6  1.82732259  8.082290 14.337258
#> 203 190  6  1.69239695  7.923426 14.154455
#> 204 195  6  1.55619010  7.764561 13.972932
#> 205 200  6  1.41868796  7.605696 13.792705
#> 206 205  6  1.27987706  7.446832 13.613786
#> 207 210  6  1.13974461  7.287967 13.436189
#> 208 215  6  0.99827849  7.129102 13.259926
#> 209 220  6  0.85546731  6.970237 13.085007
#> 210 225  6  0.71130045  6.811373 12.911445
#> 211 230  6  0.56576810  6.652508 12.739248
#> 212 235  6  0.41886125  6.493643 12.568425
#> 213 240  6  0.27057180  6.334778 12.398985
#> 214 245  6  0.12089247  6.175914 12.230935
#> 215 250  6 -0.03018304  6.017049 12.064281
#> 216 255  6 -0.18266016  5.858184 11.899029
#> 217 260  6 -0.33654332  5.699319 11.735182
#> 218 265  6 -0.49183601  5.540455 11.572745
#> 219 270  6 -0.64854074  5.381590 11.411721
#> 220 275  6 -0.80665902  5.222725 11.252110
#> 221 280  6 -0.96619138  5.063861 11.093912
#> 222 285  6 -1.12713734  4.904996 10.937129
#> 223 290  6 -1.28949545  4.746131 10.781758
#> 224 295  6 -1.45326326  4.587266 10.627796
#> 225 300  6 -1.61843733  4.428402 10.475240
#> 226 305  6 -1.78501328  4.269537 10.324087
#> 227 310  6 -1.95298574  4.110672 10.174330
#> 228 315  6 -2.12234845  3.951807 10.025963
#> 229 320  6 -2.29309420  3.792943  9.878979
#> 230 325  6 -2.46521491  3.634078  9.733371
#> 231 330  6 -2.63870165  3.475213  9.589128
#> 232 335  6 -2.81354463  3.316348  9.446241