<div><a rel="nofollow" href="http://www.deeplytrivial.com/p/the-to-z-of-r.html" target="_blank">April A to Z</a> is complete! We now return to your regularly scheduled statistics blog posts! Today, I want to talk about an issue I touched on during A to Z: <a rel="nofollow" href="http://www.deeplytrivial.com/2018/04/y-is-for-ys-y-hats-and-residuals.html" target="_blank">using regression to predict values</a> and see how well your model is doing.
<p>Specifically, I talked a couple of times about binomial regression (<a rel="nofollow" href="http://www.deeplytrivial.com/2018/04/g-is-for-glm-function.html" target="_blank">here</a> and <a rel="nofollow" href="http://www.deeplytrivial.com/2018/04/z-is-for-z-scores-and-standardizing.html" target="_blank">here</a>), which is used to predict (read: recreate with a set of variables significantly related to) a binary outcome. The data example I used involved my dissertation data and the binary outcome was verdict: guilty or not guilty. A regression model returns the linear correction applied to the predictor variables to reproduce the outcome, and will highlight whether a predictor was significantly related to the outcome or not. But a big question you may be asking of your binomial model is: how well does it predict the outcome? Specifically, how can you examine whether your regression model is correctly classifying cases? </p>
<p>We’ll start by loading/setting up the data and rerunning the binomial regression with interactions.</p>
<div>
<div>
<div>
<pre><span>dissertation</span><span>&lt;-</span><span>read.delim</span><span>(</span><span>&quot;dissertation_data.txt&quot;</span><span>,</span><span>header</span><span>=</span><span>TRUE</span><span>)</span><br><span>dissertation</span><span>&lt;-</span><span>dissertation[,</span><span>1</span><span>:</span><span>44</span><span>]</span><br><span>predictors</span><span>&lt;-</span><span>c</span><span>(</span><span>&quot;obguilt&quot;</span><span>,</span><span>&quot;reasdoubt&quot;</span><span>,</span><span>&quot;bettertolet&quot;</span><span>,</span><span>&quot;libertyvorder&quot;</span><span>,</span><br>              <span>&quot;jurevidence&quot;</span><span>,</span><span>&quot;guilt&quot;</span><span>)</span><br><span>dissertation</span><span>&lt;-</span><span>subset</span><span>(dissertation,</span> <span>!</span><span>is.na</span><span>(libertyvorder))</span><br><br><span>dissertation[</span><span>45</span><span>:</span><span>50</span><span>]</span><span>&lt;-</span><span>lapply</span><span>(dissertation[predictors],</span> <span>function</span><span>(</span><span>x</span><span>) {</span><br>  <span>y</span><span>&lt;-</span><span>scale</span><span>(x,</span> <span>center</span><span>=</span><span>TRUE</span><span>,</span> <span>scale</span><span>=</span><span>TRUE</span><span>)</span><br>  <span>}</span><br><span>)</span><br><br><span>pred_int</span><span>&lt;-</span><span>'verdict ~ obguilt.1 + reasdoubt.1 + bettertolet.1 + libertyvorder.1 + <br> jurevidence.1 + guilt.1 + obguilt.1*guilt.1 + reasdoubt.1*guilt.1 +<br> bettertolet.1*guilt.1 + libertyvorder.1*guilt.1 + jurevidence.1*guilt.1'</span><br><span>model</span><span>&lt;-</span><span>glm</span><span>(pred_int,</span> <span>family</span><span>=</span><span>&quot;binomial&quot;</span><span>,</span> <span>data</span><span>=dissertation)</span><br><span>summary</span><span>(model)</span><br></pre>
</div>
<div>
<pre>## <br>## Call:<br>## glm(formula = pred_int, family = &quot;binomial&quot;, data = dissertation)<br>## <br>## Deviance Residuals: <br>##     Min       1Q   Median       3Q      Max  <br>## -2.6101  -0.5432  -0.1289   0.6422   2.2805  <br>## <br>## Coefficients:<br>##                         Estimate Std. Error z value Pr(>|z|)    <br>## (Intercept)             -0.47994    0.16264  -2.951  0.00317 ** <br>## obguilt.1                0.25161    0.16158   1.557  0.11942    <br>## reasdoubt.1             -0.09230    0.20037  -0.461  0.64507    <br>## bettertolet.1           -0.22484    0.20340  -1.105  0.26899    <br>## libertyvorder.1          0.05825    0.21517   0.271  0.78660    <br>## jurevidence.1            0.07252    0.19376   0.374  0.70819    <br>## guilt.1                  2.31003    0.26867   8.598  &lt; 2e-16 ***<br>## obguilt.1:guilt.1        0.14058    0.23411   0.600  0.54818    <br>## reasdoubt.1:guilt.1     -0.61724    0.29693  -2.079  0.03764 *  <br>## bettertolet.1:guilt.1    0.02579    0.30123   0.086  0.93178    <br>## libertyvorder.1:guilt.1 -0.27492    0.29355  -0.937  0.34899    <br>## jurevidence.1:guilt.1    0.27601    0.36181   0.763  0.44555    <br>## ---<br>## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1<br>## <br>## (Dispersion parameter for binomial family taken to be 1)<br>## <br>##     Null deviance: 490.08  on 354  degrees of freedom<br>## Residual deviance: 300.66  on 343  degrees of freedom<br>## AIC: 324.66<br>## <br>## Number of Fisher Scoring iterations: 6<br></pre>
</div>
</div>
</div>
<p>The predict function, which I introduced <a rel="nofollow" href="https://www.deeplytrivial.com/2018/04/y-is-for-ys-y-hats-and-residuals.html" target="_blank">here</a>, can also be used for the binomial model. Let’s have R generate predicted scores for everyone in the dissertation sample:</p>
<div>
<div>
<div>
<pre><span>dissertation</span><span>$</span><span>predver</span><span>&lt;-</span><span>predict</span><span>(model)</span><br><span>dissertation</span><span>$</span><span>predver</span><br></pre>
</div>
<div>
<pre>##   [1]  0.3907097456 -4.1351129605  2.1820478279 -2.8768390246  2.5804618523<br>##   [6]  0.4244692909  2.3065468369 -2.7853434926  0.3504760502 -0.2747339639<br>##  [11] -1.8506160725 -0.6956240161 -4.7860574839 -0.3875950731 -2.4955679446<br>##  [16] -0.3941516951 -4.5831011509  1.6185480937  0.4971923298  4.1581842900<br>##  [21] -0.6320531052 -4.8447046319 -2.3974890696  1.8566258698  0.0360685822<br>##  [26]  2.2151040131  2.3477149003 -2.4493726369 -0.2253481404 -4.8899805287<br>##  [31]  1.7789459288 -0.0978703861 -3.5541042186 -3.6009218603  0.1568318789<br>##  [36]  3.7866003489 -0.6371816898 -0.7047761441 -0.7529742376 -0.0302759317<br>##  [41] -0.1108055330  1.9751810033  0.2373614802  0.0424471071 -0.4018757856<br>##  [46]  0.0530272726 -1.0763759980  0.0099577637  0.3128581222  1.4806679691<br>##  [51] -1.7468626219  0.2998282372 -3.6359162016 -2.2200774510  0.3192366472<br>##  [56]  3.0103216033 -2.0625775984 -6.0179845235  2.0300503627  2.3676828409<br>##  [61] -2.8971753746 -3.2131490026  2.1349358889  3.0215336139  1.2436192890<br>##  [66]  0.2885535375  0.2141821004  1.9480686936  0.0438751446 -1.9368013875<br>##  [71]  0.2931258287  0.5319938265  0.0177643261  3.3724920900  0.0332949791<br>##  [76]  2.5935500970  0.7571810150  0.7131757400  2.5411073339  2.8499853550<br>##  [81]  2.8063291084 -0.4500738791  1.4700679077 -0.8659309719  0.0870492258<br>##  [86]  0.5728074322  0.1476797509  2.4697257261  2.5935500970 -2.2200774510<br>##  [91] -0.0941827753  1.3708676633  1.4345235392 -0.2407209578  2.4662700339<br>##  [96] -1.9687731888 -6.7412580522 -0.0006224018 -4.4132951092 -2.8543032695<br>## [101]  1.2295635352  2.8194173530  0.1215689324 -3.8258079371  1.8959803882<br>## [106] -4.5578801595  2.3754402614  0.0826808026  1.5112359711 -3.5402060466<br>## [111]  0.2556657363  0.7054183194  1.4675797244 -2.3974890696  2.6955929822<br>## [116] -0.3123518919 -4.8431862346 -2.0132721372  0.4673405434 -2.3053405270<br>## [121]  1.9498822386 -0.5164183930 -1.8277820872 -0.0134750769 -2.3013547136<br>## [126] -0.2498730859 -4.4281010683 -0.0134750769 -0.2604532514  0.1476797509<br>## [131] -2.3392939519 -2.0625775984 -3.5541042186  1.5087477879 -4.6453051124<br>## [136]  2.0616474606 -3.2691362859 -7.3752231145 -1.6666447439  1.0532964013<br>## [141] -2.0625775984 -0.3355312717  2.2481601983 -2.2200774510 -4.3276959075<br>## [146]  0.8685972087 -0.7727065311  1.7511589809 -0.4774548995  0.0008056357<br>## [151]  1.7022334970 -0.4202625135 -0.2902646169  2.4409712692  0.0008056357<br>## [156]  0.0008056357 -3.6009218603 -0.8567788439 -0.4528474822  0.3517462520<br>## [161]  0.1307210605 -3.7843118182 -2.8419024763 -3.5191098774 -0.1460684795<br>## [166]  1.8809888141  2.8194173530 -2.4656469123  1.0589888029  0.1659840070<br>## [171]  1.4345235392  2.3676828409  1.5749534339 -0.1681557545  2.6406620359<br>## [176]  0.1476797509 -2.2135177411  1.9168260534 -3.4993205379  0.4557086940<br>## [181] -3.8136089417 -0.1121510987 -3.9772095600  1.3849234171  0.3504760502<br>## [186]  2.3807710856 -3.0667307601  2.3040586537  1.7599138086 -0.2083894500<br>## [191]  0.6844579761 -0.3552635652 -1.9459392035 -0.6075281598 -2.1663310490<br>## [196]  2.3676828409 -1.9205271122 -2.2334295071 -4.4265826710 -1.0117771483<br>## [201] -0.0161530548 -0.3072233074 -0.0161530548 -0.7451676752 -7.0351269313<br>## [206]  2.6406620359 -3.7523234832 -0.2498730859  2.0222929422  3.2886316225<br>## [211] -1.6221457956  2.4749949634  1.7570711677  0.0904873650 -4.7332807307<br>## [216]  0.1568318789 -0.0302759317  0.5127229828  1.3097316594 -6.9309218514<br>## [221]  0.0515992352 -0.4514194447 -0.2253481404 -4.7652690656 -0.4279866041<br>## [226] -4.4136563866 -3.7618312672  0.0156676181 -0.2590252139  2.6076058507<br>## [231]  1.6420333133 -3.9985172969 -6.2076483227  0.1632104039  0.1829426974<br>## [236] -4.7652690656 -4.4212844958  1.6001906117  0.8579971472 -3.8699110198<br>## [241]  0.3022779567 -0.1679979189  1.9421248181  0.6592738895  1.6132788564<br>## [246] -0.0366544567 -3.4818233673 -3.9422152187 -0.3473613776  0.4321933815<br>## [251]  0.7480288869 -0.2498730859 -1.9861068488 -2.2297920164 -0.7621263656<br>## [256]  1.2966434147  0.1632104039  0.2048721368  1.7789459288  0.4926393080<br>## [261]  0.4096285430 -1.7794744955 -2.5822853071  2.0413250624 -6.6574350219<br>## [266] -0.1277642235 -2.1972434657 -2.5075677545 -0.4482774141 -0.6943740757<br>## [271] -0.7821891015  6.3289445390  0.1568318789  0.1165981835  1.4781797859<br>## [276] -4.2287015488 -3.6157278195 -0.1511970641 -0.7047761441  2.0935344484<br>## [281] -3.8258079371 -4.4231102471  1.3097316594  3.4081542651 -0.4996175382<br>## [286] -2.0534397824  0.9783975145 -2.2562634924  3.7196170683  1.1110084017<br>## [291]  2.1661785291 -4.2138955896  1.9421248181  2.3065468369 -0.7139282722<br>## [296] -4.1431023472 -2.0854115837  2.9389399956  1.7711269214 -0.0302759317<br>## [301] -2.6458711124  0.5856241187 -0.1199576611  1.8566258698 -2.2383553905<br>## [306]  2.3807710856 -0.2838860920  3.1176953128  2.8499853550  2.8063291084<br>## [311]  0.0034011417 -0.4683781352 -3.0377484314 -1.3833686805  1.7764577456<br>## [316]  1.7842151661  3.4081542651  0.1165981835 -4.6988069009 -2.6013721641<br>## [321]  2.0616474606 -0.2498730859 -4.2207121622  4.1705330009  5.2103776377<br>## [326] -4.5406977837 -1.5080855068 -2.5232652805 -5.7259789038  2.5211393933<br>## [331] -0.3487069432 -2.5035573312 -2.2764097339 -5.8364854607 -1.8694684539<br>## [336]  1.3402996614  0.5728074322  0.3663267540 -0.1603491921 -2.1690805453<br>## [341] -1.4105339689  3.0768201201 -5.1065624241 -4.5966850670 -4.5498907729<br>## [346] -1.3078399029 -1.0882592824  0.3128581222 -0.3644156933  0.3100845191<br>## [351]  2.4774831467 -1.0763759980  2.2151040131 -0.0952748801 -4.6864864366<br></pre>
</div>
</div>
</div>
<p>Now, remember that the outcome variable is not guilty (0) and guilty (1), so you might be wondering – what’s with these predicted values? Why aren’t they 0 or 1?</p>
<p>Binomial regression is used for nonlinear outcomes. Since the outcome is 0/1, it’s nonlinear. But binomial regression is based on the general linear model. So how can we apply the general linear model to a nonlinear outcome? Answer: by transforming scores. Specifically, it transforms the outcome into a <a rel="nofollow" href="https://www.deeplytrivial.com/2017/09/statistics-sunday-everyone-loves-log.html" target="_blank">log odds ratio</a>; the log transform makes the outcome variable behave somewhat linearly and symmetrically. The predicted outcome, then, is also a log odds ratio.</p>
<div>
<div>
<div>
<pre><span>ordvalues</span><span>&lt;-</span><span>dissertation[</span><span>order</span><span>(dissertation</span><span>$</span><span>predver),]</span><br><span>ordvalues</span><span>&lt;-</span><span>ordvalues[,</span><span>51</span><span>]</span><br><span>ordvalues</span><span>&lt;-</span><span>data.frame</span><span>(</span><span>1</span><span>:</span><span>355</span><span>,ordvalues)</span><br><span>colnames</span><span>(ordvalues)</span><span>&lt;-</span><span>c</span><span>(</span><span>&quot;number&quot;</span><span>,</span><span>&quot;predver&quot;</span><span>)</span><br><span>library</span><span>(ggplot2)</span><br><span>ggplot</span><span>(</span><span>data</span><span>=ordvalues,</span> <span>aes</span><span>(number,predver))</span><span>+</span><span>geom_smooth</span><span>()</span><br></pre>
</div>
<div>
<pre>## `geom_smooth()` using method = 'loess'<br></pre>
</div>
</div>
<div><a rel="nofollow" href="https://i0.wp.com/3.bp.blogspot.com/-t68kCtjcevo/WueGreJepKI/AAAAAAAALbs/QsSzDQL-QjgO27QRZkuhkXsZrqP9GRTiQCLcBGAs/s1600/unnamed-chunk-3-1.png?ssl=1" target="_blank"><img border="0" src="https://i0.wp.com/3.bp.blogspot.com/-t68kCtjcevo/WueGreJepKI/AAAAAAAALbs/QsSzDQL-QjgO27QRZkuhkXsZrqP9GRTiQCLcBGAs/s320/unnamed-chunk-3-1.png?resize=450%2C504&ssl=1" data-original-width="450" width="450" data-original-height="504" data-recalc-dims="1"></a></div>
</div>
<p>Log odds ratios are great for analysis, but when trying to understand how well your model is predicting values, we want to convert them into a metric that’s easier to understand in isolation and when compared to the observed values. We can convert them into probabilities with the following equation:</p>
<div>
<div>
<div>
<pre><span>dissertation</span><span>$</span><span>verdict_predicted</span><span>&lt;-</span><span>exp</span><span>(</span><span>predict</span><span>(model))</span><span>/</span><span>(</span><span>1</span><span>+</span><span>exp</span><span>(</span><span>predict</span><span>(model)))</span><br></pre>
</div>
</div>
</div>
<p>This gives us a value ranging from 0 to 1, which is the probability that a particular person will select guilty. We can use this value in different ways to see how well our model is doing. Typically, we’ll divide at the 50% mark, so anyone with a probability of 0.5 or greater is predicted to select guilty, and anyone with a probability less than 0.5 would be predicted to select not guilty. We then compare this new variable with the observed results to see how well the model did.</p>
<div>
<div>
<div>
<pre><span>dissertation</span><span>$</span><span>vpred_rounded</span><span>&lt;-</span><span>round</span><span>(dissertation</span><span>$</span><span>verdict_predicted,</span><span>digits</span><span>=</span><span>0</span><span>)</span><br><span>library</span><span>(expss)</span><br></pre>
</div>
<div>
<pre>## Warning: package 'expss' was built under R version 3.4.4<br></pre>
</div>
<div>
<pre><span>dissertation</span><span>&lt;-</span> <span>apply_labels</span><span>(dissertation,</span><br>                      <span>verdict</span> <span>=</span> <span>&quot;Actual Verdict&quot;</span><span>,</span><br>                      <span>verdict</span> <span>=</span> <span>c</span><span>(</span><span>&quot;Not Guilty&quot;</span> <span>=</span> <span>0</span><span>,</span><br>                                        <span>&quot;Guilty&quot;</span> <span>=</span> <span>1</span><span>),</span><br>                      <span>vpred_rounded</span> <span>=</span> <span>&quot;Predicted Verdict&quot;</span><span>,</span><br>                      <span>vpred_rounded</span> <span>=</span> <span>c</span><span>(</span><span>&quot;Not Guilty&quot;</span> <span>=</span> <span>0</span><span>,</span><br>                                        <span>&quot;Guilty&quot;</span> <span>=</span> <span>1</span><span>)</span><br><span>)</span><br><span>cro</span><span>(dissertation</span><span>$</span><span>verdict,</span><span>list</span><span>(dissertation</span><span>$</span><span>vpred_rounded,</span> <span>total</span><span>()))</span><br></pre>
</div>
<table>
<thead>
<tr>
<th></th>
<th colspan="2"> Predicted Verdict </th>
<th> </th>
<th colspan="1"> #Total </th>
</tr>
<tr>
<th></th>
<th> Not Guilty </th>
<th> Guilty </th>
<th colspan="1"> </th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="5"> Actual Verdict </td>
</tr>
<tr>
<td>   Not Guilty </td>
<td>152</td>
<td>39</td>
<td colspan="1"> </td>
<td>191</td>
</tr>
<tr>
<td>   Guilty </td>
<td>35</td>
<td>129</td>
<td colspan="1"> </td>
<td>164</td>
</tr>
<tr>
<td>   #Total cases </td>
<td>187</td>
<td>168</td>
<td colspan="1"> </td>
<td>355</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>One thing we could look at regarding this table, which when dealing with actual versus predicted categories is known as a confusion matrix, is how well the model did at correctly categorizing cases – which we get by adding together the number of people with both observed and predicted not guilty, and people with observed and predicted guilty, then dividing that sum by the total.</p>
<div>
<div>
<div>
<pre><span>accuracy</span><span>&lt;-</span><span>(</span><span>152</span><span>+</span><span>129</span><span>)</span><span>/</span><span>355</span><br><span>accuracy</span><br></pre>
</div>
<div>
<pre>## [1] 0.7915493<br></pre>
</div>
</div>
</div>
<p>Our model correctly classified 79% of the cases. However, this is not the only way we can determine how well our model did. There are a <a rel="nofollow" href="https://en.wikipedia.org/wiki/Sensitivity_and_specificity#Definitions" target="_blank">variety of derivations</a> you can make from the confusion matrix. But two you should definitely include when doing this kind of analysis are sensitivity and specificity. Sensitivity refers to the true positive rate, and specificity refers to the true negative rate.</p>
<p>When you’re working with confusion matrices, you’re often trying to diagnose or identify some condition, one that may be deemed positive or present, and the other that may be deemed negative or absent. These derivations are important because they look at how well your model identifies these different states. For instance, if most of my cases selected not guilty, I could get a high accuracy rate by simply predicting that <i>everyone</i> will select not guilty. But then my model lacks sensitivity – it only identifies negative cases (not guilty) and fails to identify any positive cases (guilty). If I were dealing with something even higher stakes, like whether a test result indicates the presence of a condition, I want to make certain my classification is sensitive to those positive cases. And vice versa, I could keep from missing any positive cases by just classifying everyone as positive, but then my model lacks specificity and I may subject people to treatment they don’t need (and that could be harmful).</p>
<p>Just like accuracy, sensitivity and specificity are easy to calculate. As I said above, I’ll consider not guilty to be negative and guilty to be positive. Sensitivity is simply the number of true positives (observed and predicted guilty) divided by the sum of true positives and false negatives (people who selected guilty but were classified as not guilty).</p>
<div>
<div>
<div>
<pre><span>sensitivity</span><span>&lt;-</span><span>129</span><span>/</span><span>164</span><br><span>sensitivity</span><br></pre>
</div>
<div>
<pre>## [1] 0.7865854<br></pre>
</div>
</div>
</div>
<p>And specificity is the number of true negatives (observed and predicted not guilty) divided by the sum of true negatives and false positives (people who selected not guilty but were classified as guilty).</p>
<div>
<div>
<div>
<pre><span>specificity</span><span>&lt;-</span><span>152</span><span>/</span><span>191</span><br><span>specificity</span><br></pre>
</div>
<div>
<pre>## [1] 0.7958115<br></pre>
</div>
</div>
</div>
<p>So the model correctly classifies 79% of the positive cases and 80% of the negative cases. The model could be improved, but it’s functioning equally well across positive and negative cases, which is good.</p>
<p>It should be pointed out that you can select any cutpoint you want for your probability variable. That is, if I want to be very conservative in identifying positive cases, I might want there to be a higher probability that it is a positive case before I classify it as such – perhaps I want to use a cutpoint like 75%. I can easily do that.</p>
<div>
<div>
<div>
<pre><span>dissertation</span><span>$</span><span>vpred2[dissertation</span><span>$</span><span>verdict_predicted</span> <span></span> <span>0.75</span><span>]</span><span>&lt;-</span><span>0</span><br><span>dissertation</span><span>$</span><span>vpred2[dissertation</span><span>$</span><span>verdict_predicted</span> <span>>=</span> <span>0.75</span><span>]</span><span>&lt;-</span><span>1</span><br><span>dissertation</span><span>&lt;-</span> <span>apply_labels</span><span>(dissertation,</span><br>                      <span>vpred2</span> <span>=</span> <span>&quot;Predicted Verdict (0.75 cut)&quot;</span><span>,</span><br>                      <span>vpred2</span> <span>=</span> <span>c</span><span>(</span><span>&quot;Not Guilty&quot;</span> <span>=</span> <span>0</span><span>,</span><br>                                        <span>&quot;Guilty&quot;</span> <span>=</span> <span>1</span><span>)</span><br><span>)</span><br><span>cro</span><span>(dissertation</span><span>$</span><span>verdict,</span><span>list</span><span>(dissertation</span><span>$</span><span>vpred2,</span> <span>total</span><span>()))</span><br></pre>
</div>
<table>
<thead>
<tr>
<th></th>
<th colspan="2"> Predicted Verdict (0.75 cut) </th>
<th> </th>
<th colspan="1"> #Total </th>
</tr>
<tr>
<th></th>
<th> Not Guilty </th>
<th> Guilty </th>
<th colspan="1"> </th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="5"> Actual Verdict </td>
</tr>
<tr>
<td>   Not Guilty </td>
<td>177</td>
<td>14</td>
<td colspan="1"> </td>
<td>191</td>
</tr>
<tr>
<td>   Guilty </td>
<td>80</td>
<td>84</td>
<td colspan="1"> </td>
<td>164</td>
</tr>
<tr>
<td>   #Total cases </td>
<td>257</td>
<td>98</td>
<td colspan="1"> </td>
<td>355</td>
</tr>
</tbody>
</table>
<div>
<pre><span>accuracy2</span><span>&lt;-</span><span>(</span><span>177</span><span>+</span><span>84</span><span>)</span><span>/</span><span>355</span><br><span>sensitivity2</span><span>&lt;-</span><span>84</span><span>/</span><span>164</span><br><span>specificity2</span><span>&lt;-</span><span>177</span><span>/</span><span>191</span><br><span>accuracy2</span><br></pre>
</div>
<div>
<pre>## [1] 0.7352113<br></pre>
</div>
<div>
<pre><span>sensitivity2</span><br></pre>
</div>
<div>
<pre>## [1] 0.5121951<br></pre>
</div>
<div>
<pre><span>specificity2</span><br></pre>
</div>
<div>
<pre>## [1] 0.9267016<br></pre>
</div>
</div>
</div>
<p>Changing the cut score improves specificity but at the cost of sensitivity, which makes sense, because our model was predicting equally well (or poorly, depending on how you look at it) across positives and negatives. In this case, a different cut score won’t improve our model. We would need to go back and see if there are better variables to use for prediction. And to keep us from fishing around in our data, we’d probably want to use a training and testing set for such exploratory analysis. </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.deeplytrivial.com/2018/05/statistical-sins-is-your-classification.html"> Deeply Trivial</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/wIeNX-3OsZo" height="1"></a></div></div>