Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Confidence intervals for linear predictions based on predict vs predictnl

    Hello,
    I am running a linear regression and wanted to obtain confidence intervals for linear predictions. I predicted the linear predictions and their standard errors using predict, and then compared these with confidence intervals from predictnl.
    Although the confidence intervals are similar in this exampe they are not exactly the same and I wondered which ones are the correct ones.
    I use Stata 17
    Thank you for your help
    André

    Code:
    use "https://www.stata-press.com/data/r17/mheart0", clear
    
    regress bmi female age
    
    predict xb_bmi, xb
    predict std_bmi, stdp
    generate inf = xb_bmi - 1.96*std_bmi
    generate sup = xb_bmi + 1.96*std_bmi
    
    predictnl xb_bmi2 = predict(xb), ci(cil_mi ciu_mi)
    
    list xb_bmi xb_bmi2 if xb_bmi != xb_bmi2
    list inf cil_mi if inf != cil_mi
    list sup ciu_mi if sup != ciu_mi
    
    generate mean1 = (inf + sup)/2 - xb_bmi
    generate mean2 = (cil_mi + ciu_mi)/2 - xb_bmi2
    tab mean1
    tab mean2
    
    clear

  • #2
    generate inf = xb_bmi - 1.96*std_bmi
    1.96 is just the approximate value of the 97.5 percentile point of the standard normal distribution, so precision is biting you. You can do better with

    Code:
    di invnormal(.975)
    Res.:

    Code:
    . di invnormal(.975)
    1.959964
    But the values are approximately the same.

    Code:
    use "https://www.stata-press.com/data/r17/mheart0", clear
    regress bmi female age
    predict xb_bmi, xb
    predict std_bmi, stdp
    generate inf = xb_bmi - invnormal(.975)*std_bmi
    predictnl xb_bmi2 = predict(xb), ci(cil_mi ciu_mi)
    list inf cil_mi if inf != cil_mi
    Res.:

    Code:
    . list inf cil_mi if inf != cil_mi, sep(0)
    
         +---------------------+
         |      inf     cil_mi |
         |---------------------|
      3. | 24.31096   24.31096 |
      4. | 23.72331   23.72331 |
      7. |  24.1277    24.1277 |
     22. | 24.57969   24.57969 |
     28. | 24.58625   24.58625 |
     30. | 24.54341   24.54341 |
     36. |  23.9354   23.93539 |
     37. | 24.58586   24.58586 |
     49. | 24.54216   24.54216 |
     51. | 24.54716   24.54716 |
     52. | 24.58618   24.58619 |
     72. |  24.5443    24.5443 |
     80. | 24.47736   24.47736 |
     81. | 24.30888   24.30887 |
     83. | 23.91905   23.91905 |
     88. | 23.72967   23.72967 |
     90. |  23.8711    23.8711 |
     91. | 24.49766   24.49766 |
     95. | 23.72579   23.72579 |
    106. | 24.14487   24.14487 |
    119. | 23.77176   23.77176 |
    123. | 23.75073   23.75073 |
    128. |  23.0179   23.01791 |
    130. | 24.58358   24.58358 |
    136. | 24.53123   24.53124 |
    143. |  24.5852    24.5852 |
    149. | 24.58372   24.58372 |
    151. | 24.58628   24.58628 |
         +---------------------+
    
    .

    Comment


    • #3
      Excellent ! Thank you so much Andrew.

      Comment

      Working...
      X