title: Adding p-values to a polr model (for modelsummary)
body: <p>I know that <code>polr</code> does not give p-values because they are not very reliable. Nevertheless, I would like to add them to my <code>modelsummary</code> (<a href="https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#adding-new-models-part-i-" rel="nofollow noreferrer">Vignette</a>) output. I know to get the values as follows:</p>
  <pre><code>library(MASS)
  polr_res &lt;- polr(as.ordered(rep77) ~ foreign + length + mpg, Hess=TRUE, data=fullauto);summary(polr_res)
  
  Call:
  polr_res(formula = as.ordered(rep77) ~ foreign + length + mpg, data = fullauto, 
      Hess = TRUE)
  
  ## coefficient test
  library(&quot;AER&quot;)
  coeftest(polr_res)
  </code></pre>
  <h1>modelsummary</h1>
  <p>Because <code>polr</code> has no p-values, I cannot call <code>modelsummary(models, stars=TRUE)</code> on my <code>models</code> (which includes other models which do have p-values and for which I want to show stars).</p>
  <pre><code>library(modelsummary)
  models &lt;- list(
  &quot;Ordinal Probit&quot; = polr_res,
  )
  # model_names &lt;- c(&quot;OLS&quot;, &quot;&quot;)
  modelsummary(models, stars=TRUE)
  </code></pre>
  <p>I tried first to simply add the p-values to the <code>tidy</code> object, but I cannot add that object to the list of <code>models</code>.</p>
  <pre><code>polr_pval &lt;- coeftest(polr)[,4]
  polr_pval &lt;- as.data.frame(polr_pval)
  tidy_polr &lt;- tidy(polr)
  tidy_polr[,5] &lt;- polr_pval
  </code></pre>
  <p>The vignette describes that I can make a custom class which adapts the <code>polr</code>, but I do not understand how:
  <a href="https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#customizing-existing-models-part-i-" rel="nofollow noreferrer">https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#customizing-existing-models-part-i-</a></p>
  <p><a href="https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#customizing-existing-models-part-ii-" rel="nofollow noreferrer">https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#customizing-existing-models-part-ii-</a></p>
  <p>Could anyone help me figure this out?</p>
  <h1>EDIT:</h1>
  <p>I am posting an edit showing the problem I was having when using Vincent's answer, with <code>R version 3.6.1 (2019-07-05)</code>. If you are encountering this issue, (preferably) update to R version 4.0.0 or download an update for <code>modelsummary</code> from Github (see also Vincent's comments below).:</p>
  <pre><code>library(remotes)
  remotes::install_github('vincentarelbundock/modelsummary')
  </code></pre>
  <p>Output:</p>
  <p><a href="https://i.stack.imgur.com/PZsqj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PZsqj.png" alt="enter image description here" /></a></p>
  <h1>DATA for R</h1>
  <pre><code>fullauto &lt;- structure(list(make = structure(c(1, 1, 1, 2, 2, 3, 4, 4, 4, 
  4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 
  9, 10, 10, 11, 11, 12, 12, 12, 13, 14, 14, 14, 14, 14, 14, 15, 
  15, 15, 15, 15, 15, 15, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 
  18, 18, 19, 20, 21, 21, 21, 22, 22, 22, 22, 23), label = &quot;Make&quot;, format.stata = &quot;%8.0g&quot;, class = c(&quot;haven_labelled&quot;, 
  &quot;vctrs_vctr&quot;, &quot;double&quot;), labels = c(AMC = 1, Audi = 2, BMW = 3, 
  Buick = 4, Cad. = 5, Chev. = 6, Datsun = 7, Dodge = 8, Fiat = 9, 
  Ford = 10, Honda = 11, Linc. = 12, Mazda = 13, Merc. = 14, Olds = 15, 
  Peugeot = 16, Plym. = 17, Pont. = 18, Renault = 19, Subaru = 20, 
  Toyota = 21, VW = 22, Volvo = 23)), model = structure(c(1, 2, 
  3, 4, 5000, 320, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 
  18, 19, 20, 200, 210, 510, 810, 21, 22, 23, 24, 25, 26, 27, 28, 
  29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 
  45, 98, 604, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 
  58, 59, 60, 61, 62, 63, 64, 65, 260), label = &quot;Model&quot;, format.stata = &quot;%8.0g&quot;, class = c(&quot;haven_labelled&quot;, 
  &quot;vctrs_vctr&quot;, &quot;double&quot;), labels = c(Concord = 1, Pacer = 2, Spirit = 3, 
  Fox = 4, Century = 5, Electra = 6, LeSabre = 7, Opel = 8, Regal = 9, 
  Riviera = 10, Skylark = 11, Deville = 12, Eldrado = 13, Seville = 14, 
  Chevette = 15, Impala = 16, Malibu = 17, MCarlo = 18, Monza = 19, 
  Nova = 20, Colt = 21, Diplomat = 22, Magnum = 23, StRegis = 24, 
  Strada = 25, Fiesta = 26, Mustang = 27, Accord = 28, Civic = 29, 
  Cntntl = 30, `Mark V` = 31, Vrsills = 32, GLC = 33, Bobcat = 34, 
  Cougar = 35, `XR-7` = 36, Marquis = 37, Monarch = 38, Zephyr = 39, 
  Cutlass = 40, CutlSupr = 41, `Delta 88` = 42, Omega = 43, Starfire = 44, 
  Toronado = 45, Arrow = 46, Champ = 47, Horizon = 48, Sapporo = 49, 
  Volare = 50, Catalina = 51, Firebird = 52, GranPrix = 53, `Le Mans` = 54, 
  Phoenix = 55, Sunbird = 56, `Le Car` = 57, Subaru = 58, Celica = 59, 
  Corolla = 60, Corona = 61, Rabbit = 62, Diesel = 63, Scirocco = 64, 
  Dasher = 65)), price = structure(c(4099, 4749, 3799, 6295, 9690, 
  9735, 4816, 7827, 5788, 4453, 5189, 10372, 4082, 11385, 14500, 
  15906, 3299, 5705, 4504, 5104, 3667, 3955, 6229, 4589, 5079, 
  8129, 3984, 4010, 5886, 6342, 4296, 4389, 4187, 5799, 4499, 11497, 
  13594, 13466, 3995, 3829, 5379, 6303, 6165, 4516, 3291, 4733, 
  5172, 4890, 4181, 4195, 10371, 8814, 12990, 4647, 4425, 4482, 
  6486, 4060, 5798, 4934, 5222, 4723, 4424, 4172, 3895, 3798, 5899, 
  3748, 5719, 4697, 5397, 6850, 7140, 11995), label = &quot;Price&quot;, format.stata = &quot;%8.0g&quot;), 
      mpg = structure(c(22, 17, 22, 23, 17, 25, 20, 15, 18, 26, 
      20, 16, 19, 14, 14, 21, 29, 16, 22, 22, 24, 19, 23, 35, 24, 
      21, 30, 18, 16, 17, 21, 28, 21, 25, 28, 12, 12, 14, 30, 22, 
      14, 14, 15, 18, 20, 19, 19, 18, 19, 24, 16, 21, 14, 38, 34, 
      25, 26, 18, 18, 18, 19, 19, 19, 24, 26, 35, 18, 31, 18, 25, 
      41, 25, 23, 17), label = &quot;Mileage (mpg)&quot;, format.stata = &quot;%8.0g&quot;), 
      rep78 = structure(c(3, 3, NA, 3, 5, 4, 3, 4, 3, NA, 3, 3, 
      3, 3, 2, 3, 3, 4, 3, 2, 2, 3, 4, 5, 4, 4, 5, 2, 2, 2, 3, 
      4, 3, 5, 4, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 3, 1, 
      3, 4, NA, 3, 5, 3, NA, 2, 4, 1, 3, 3, NA, 2, 3, 5, 5, 5, 
      5, 4, 5, 4, 4, 5), label = &quot;Repair Record 1978&quot;, format.stata = &quot;%9.0g&quot;, class = c(&quot;haven_labelled&quot;, 
      &quot;vctrs_vctr&quot;, &quot;double&quot;), labels = c(Poor = 1, Fair = 2, Average = 3, 
      Good = 4, Excellent = 5)), rep77 = structure(c(2, 1, NA, 
      3, 2, 4, 3, 4, 4, NA, 3, 4, 3, 3, 2, 3, 3, 4, 3, 3, 2, 3, 
      3, 5, 4, 4, 4, 2, 2, 2, 1, NA, 3, 5, 4, 4, 4, 3, 4, 3, 3, 
      4, 2, NA, 3, 3, 4, 4, 3, 1, 3, 4, NA, 3, 4, NA, NA, 2, 4, 
      2, 3, 3, NA, 2, 3, 4, 5, 5, 5, 3, 4, 3, 3, 3), label = &quot;Repair Record 1977&quot;, format.stata = &quot;%9.0g&quot;, class = c(&quot;haven_labelled&quot;, 
      &quot;vctrs_vctr&quot;, &quot;double&quot;), labels = c(Poor = 1, Fair = 2, Average = 3, 
      Good = 4, Excellent = 5)), hdroom = structure(c(2.5, 3, 3, 
      2.5, 3, 2.5, 4.5, 4, 4, 3, 2, 3.5, 3.5, 4, 3.5, 3, 2.5, 4, 
      3.5, 2, 2, 3.5, 1.5, 2, 2.5, 2.5, 2, 4, 4, 4.5, 2.5, 1.5, 
      2, 3, 2.5, 3.5, 2.5, 3.5, 3.5, 3, 3.5, 3, 3.5, 3, 3.5, 4.5, 
      2, 4, 4.5, 2, 3.5, 4, 3.5, 2, 2.5, 4, 1.5, 5, 4, 1.5, 2, 
      3.5, 3.5, 2, 3, 2.5, 2.5, 3, 2, 3, 3, 2, 2.5, 2.5), label = &quot;Headroom (in.)&quot;, format.stata = &quot;%6.1f&quot;), 
      rseat = structure(c(27.5, 25.5, 18.5, 28, 27, 26, 29, 31.5, 
      30.5, 24, 28.5, 30, 27, 31.5, 30, 30, 26, 29.5, 28.5, 28.5, 
      25, 27, 21, 23.5, 22, 27, 24, 29, 29, 28, 26.5, 26, 23, 25.5, 
      23.5, 30.5, 28.5, 27, 25.5, 25.5, 29.5, 25, 30.5, 27, 29, 
      28, 28, 29, 27, 25.5, 30, 31.5, 30.5, 21.5, 23, 25, 22, 31, 
      29, 23.5, 28.5, 28, 27, 25, 23, 25.5, 22, 24.5, 23, 25.5, 
      25.5, 23.5, 37.5, 29.5), label = &quot;Rear Seat (in.)&quot;, format.stata = &quot;%6.1f&quot;), 
      trunk = structure(c(11, 11, 12, 11, 15, 12, 16, 20, 21, 10, 
      16, 17, 13, 20, 16, 13, 9, 20, 17, 16, 7, 13, 6, 8, 8, 8, 
      8, 17, 17, 21, 16, 9, 10, 10, 5, 22, 18, 15, 11, 9, 16, 16, 
      23, 15, 17, 16, 16, 20, 14, 10, 17, 20, 14, 11, 11, 17, 8, 
      16, 20, 7, 16, 17, 13, 7, 10, 11, 14, 9, 11, 15, 15, 16, 
      12, 14), label = &quot;Trunk space (cu. ft.)&quot;, format.stata = &quot;%8.0g&quot;), 
      weight = structure(c(2930, 3350, 2640, 2070, 2830, 2650, 
      3250, 4080, 3670, 2230, 3280, 3880, 3400, 4330, 3900, 4290, 
      2110, 3690, 3180, 3220, 2750, 3430, 2370, 2020, 2280, 2750, 
      2120, 3600, 3600, 3740, 2130, 1800, 2650, 2240, 1760, 4840, 
      4720, 3830, 1980, 2580, 4060, 4130, 3720, 3370, 2830, 3300, 
      3310, 3690, 3370, 2730, 4030, 4060, 3420, 3260, 1800, 2200, 
      2520, 3330, 3700, 3470, 3210, 3200, 3420, 2690, 1830, 2050, 
      2410, 2200, 2670, 1930, 2040, 1990, 2160, 3170), label = &quot;Weight (lbs.)&quot;, format.stata = &quot;%8.0g&quot;), 
      length = structure(c(186, 173, 168, 174, 189, 177, 196, 222, 
      218, 170, 200, 207, 200, 221, 204, 204, 163, 212, 193, 200, 
      179, 197, 170, 165, 170, 184, 163, 206, 206, 220, 161, 147, 
      179, 172, 149, 233, 230, 201, 154, 169, 221, 217, 212, 198, 
      195, 198, 198, 218, 200, 180, 206, 220, 192, 170, 157, 165, 
      182, 201, 214, 198, 201, 199, 203, 179, 142, 164, 174, 165, 
      175, 155, 155, 156, 172, 193), label = &quot;Length (in.)&quot;, format.stata = &quot;%8.0g&quot;), 
      turn = structure(c(40, 40, 35, 36, 37, 34, 40, 43, 43, 34, 
      42, 43, 42, 44, 43, 45, 34, 43, 31, 41, 40, 43, 35, 32, 34, 
      38, 35, 46, 46, 46, 36, 33, 43, 36, 34, 51, 48, 41, 33, 39, 
      48, 45, 44, 41, 43, 42, 42, 42, 43, 40, 43, 43, 38, 37, 37, 
      36, 38, 44, 42, 42, 45, 40, 43, 41, 34, 36, 36, 35, 36, 35, 
      35, 36, 36, 37), label = &quot;Turn Circle (ft.) &quot;, format.stata = &quot;%8.0g&quot;), 
      displ = structure(c(121, 258, 121, 97, 131, 121, 196, 350, 
      231, 304, 196, 231, 231, 425, 350, 350, 231, 250, 200, 200, 
      151, 250, 119, 85, 119, 146, 98, 318, 318, 225, 105, 98, 
      140, 107, 91, 400, 400, 302, 86, 140, 302, 302, 302, 250, 
      140, 231, 231, 231, 231, 151, 350, 350, 163, 156, 86, 105, 
      119, 225, 231, 231, 231, 231, 231, 151, 79, 97, 134, 97, 
      134, 89, 90, 97, 97, 163), label = &quot;Displacement (cu. in.)&quot;, format.stata = &quot;%8.0g&quot;), 
      gratio = structure(c(3.57999992370605, 2.52999997138977, 
      3.07999992370605, 3.70000004768372, 3.20000004768372, 3.64000010490417, 
      2.9300000667572, 2.41000008583069, 2.73000001907349, 2.86999988555908, 
      2.9300000667572, 2.9300000667572, 3.07999992370605, 2.27999997138977, 
      2.19000005722046, 2.24000000953674, 2.9300000667572, 2.55999994277954, 
      2.73000001907349, 2.73000001907349, 2.73000001907349, 2.55999994277954, 
      3.89000010490417, 3.70000004768372, 3.53999996185303, 3.54999995231628, 
      3.53999996185303, 2.47000002861023, 2.47000002861023, 2.94000005722046, 
      3.36999988555908, 3.15000009536743, 3.07999992370605, 3.04999995231628, 
      3.29999995231628, 2.47000002861023, 2.47000002861023, 2.47000002861023, 
      3.73000001907349, 2.73000001907349, 2.75, 2.75, 2.25999999046326, 
      2.4300000667572, 3.07999992370605, 2.9300000667572, 2.9300000667572, 
      2.73000001907349, 3.07999992370605, 2.73000001907349, 2.41000008583069, 
      2.41000008583069, 3.57999992370605, 3.04999995231628, 2.97000002861023, 
      3.36999988555908, 3.53999996185303, 3.23000001907349, 2.73000001907349, 
      3.07999992370605, 2.9300000667572, 2.9300000667572, 3.07999992370605, 
      2.73000001907349, 3.72000002861023, 3.80999994277954, 3.05999994277954, 
      3.21000003814697, 3.04999995231628, 3.77999997138977, 3.77999997138977, 
      3.77999997138977, 3.74000000953674, 2.98000001907349), label = &quot;Gear Ratio&quot;, format.stata = &quot;%6.2f&quot;), 
      order = structure(c(1, 2, 3, 5, 4, 6, 7, 8, 9, 10, 11, 12, 
      13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 
      28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 
      43, 44, 45, 47, 48, 49, 50, 51, 52, 46, 53, 54, 55, 56, 57, 
      58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 
      73, 74), label = &quot;Original order&quot;, format.stata = &quot;%8.0g&quot;), 
      foreign = structure(c(0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 
      0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
      0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1), label = &quot;Foreign&quot;, format.stata = &quot;%8.0g&quot;, class = c(&quot;haven_labelled&quot;, 
      &quot;vctrs_vctr&quot;, &quot;double&quot;), labels = c(Domestic = 0, Foreign = 1
      )), wgtd = structure(c(2930, 3350, 2640, NA, NA, NA, 3250, 
      4080, 3670, 2230, 3280, 3880, 3400, 4330, 3900, 4290, 2110, 
      3690, 3180, 3220, 2750, 3430, NA, NA, NA, NA, 2120, 3600, 
      3600, 3740, NA, 1800, 2650, NA, NA, 4840, 4720, 3830, NA, 
      2580, 4060, 4130, 3720, 3370, 2830, 3300, 3310, 3690, 3370, 
      2730, 4030, 4060, NA, 3260, 1800, 2200, 2520, 3330, 3700, 
      3470, 3210, 3200, 3420, 2690, NA, NA, NA, NA, NA, NA, NA, 
      NA, NA, NA), format.stata = &quot;%9.0g&quot;), wgtf = structure(c(NA, 
      NA, NA, 2070, 2830, 2650, NA, NA, NA, NA, NA, NA, NA, NA, 
      NA, NA, NA, NA, NA, NA, NA, NA, 2370, 2020, 2280, 2750, NA, 
      NA, NA, NA, 2130, NA, NA, 2240, 1760, NA, NA, NA, 1980, NA, 
      NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3420, NA, 
      NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1830, 2050, 2410, 
      2200, 2670, 1930, 2040, 1990, 2160, 3170), format.stata = &quot;%9.0g&quot;)), label = &quot;Automobile Models&quot;, row.names = c(NA, 
  -74L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;))
  </code></pre>