title: R - Manually plot calibration plot
body: <p>From Clinical Prediction Models by Ewout W. Steyerberg we have the following:</p>
  
  <blockquote>
    <p>A calibration plot has predictions on the x axis, and the outcome on
    the y axis. A line of identity helps for orientation: Perfect
    predictions should be on the 45° line. For linear regression, the
    calibration plot results in a simple scatter plot. For binary
    outcomes, the plot contains only 0 and 1 values for the y axis.
    Probabilities are not observed directly. However, smoothing techniques
    can be used to estimate the observed probabilities of the outcome ( p
    ( y = 1)) in relation to the predicted probabilities. The observed 0/1
    outcomes are replaced by values between 0 and 1 by combining outcome
    values of subjects with similar predicted probabilities, e.g. using
    the loess algorithm.</p>
  </blockquote>
  
  <p>I'm fitting a logistic regression model with a binary outcome. Below is an example code. The calibration curve is going to look weird because the sample is so small. I'm mostly wondering if the methodology is correct.</p>
  
  <pre><code>library(tidyverse)
  
  tibble_ex &lt;- tibble(
    event = c(1, 0, 1, 0, 0, 1),
    weight = c(100, 200, 110, 210, 220, 105)
  )
  
  model &lt;- glm(event ~ weight, family = 'binomial', data = tibble_ex) 
  
  tibble_ex &lt;- tibble_ex %&gt;%
    mutate(pred = predict(model, type = 'response'))
  
  tibble_ex %&gt;%
    arrange(pred) %&gt;%
    ggplot(aes(x = pred, y = event)) +
    stat_smooth(method = 'glm', method.args = list(family = binomial), se = F) +
    geom_abline()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/YRYhG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YRYhG.png" alt="enter image description here"></a></p>