title: Creating and plotting confidence intervals
body: <p>I have fitted a gaussian GLM model to my data, i now wish to create 95% CIs and fit them to my data. Im having a couple of issues with this when plotting as i cant get them to capture my data, they just seem to plot the same line as the model without captuing the data points. Also Im also unsure that I've created my CIs the correct way here for the mean. I entered my data and code below if anyone knows how to fix this</p>
  <p>data used</p>
  <pre><code>aids
   cases quarter  date
  1      2       1 83.00
  2      6       2 83.25
  3     10       3 83.50
  4      8       4 83.75
  5     12       1 84.00
  6      9       2 84.25
  7     28       3 84.50
  8     28       4 84.75
  9     36       1 85.00
  10    32       2 85.25
  11    46       3 85.50
  12    47       4 85.75
  13    50       1 86.00
  14    61       2 86.25
  15    99       3 86.50
  16    95       4 86.75
  17   150       1 87.00
  18   143       2 87.25
  19   197       3 87.50
  20   159       4 87.75
  21   204       1 88.00
  22   168       2 88.25
  23   196       3 88.50
  24   194       4 88.75
  25   210       1 89.00
  26   180       2 89.25
  27   277       3 89.50
  28   181       4 89.75
  29   327       1 90.00
  30   276       2 90.25
  31   365       3 90.50
  32   300       4 90.75
  33   356       1 91.00
  34   304       2 91.25
  35   307       3 91.50
  36   386       4 91.75
  37   331       1 92.00
  38   368       2 92.25
  39   416       3 92.50
  40   374       4 92.75
  41   412       1 93.00
  42   358       2 93.25
  43   416       3 93.50
  44   414       4 93.75
  45   496       1 94.00
  </code></pre>
  <p>my code used to create the model and intervals before plotting</p>
  <pre><code>#creating the model
  model3 = glm(cases ~ date,
           data = aids,
           family = poisson(link='log'))
  
  #now to add approx. 95% confidence envelope around this line
  #predict again but at the linear predictor level along with standard errors
  my_preds &lt;- predict(model3, newdata=data.frame(aids), se.fit=T, type=&quot;link&quot;) 
  
  #calculate CI limit since linear predictor is approx. Gaussian
  upper &lt;- my_preds$fit+1.96*my_preds$se.fit #this might be logit not log
  lower &lt;- my_preds$fit-1.96*my_preds$se.fit
  
  #transform the CI limit to get one at the level of the mean
  upper &lt;- exp(upper)/(1+exp(upper)) 
  lower &lt;- exp(lower)/(1+exp(lower))
  
  #plotting data
  plot(aids$date, aids$cases,
   xlab = 'Date', ylab = 'Cases', pch = 20)
  
  #adding CI lines
  plot(aids$date, exp(my_preds$fit), type = &quot;link&quot;,
   xlab = 'Date', ylab = 'Cases') #add title
  lines(aids$date,exp(my_preds$fit+1.96*my_preds$se.fit),lwd=2,lty=2)
  lines(aids$date,exp(my_preds$fit-1.96*my_preds$se.fit),lwd=2,lty=2)
  </code></pre>
  <p>outcome i currently get with no data points, the model is correct here but the CI isnt as i have no data points, so the CIs are made incorrectly i think somewhere</p>
  <p><a href="https://i.stack.imgur.com/qCcXP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qCcXP.png" alt="enter image description here" /></a></p>