Announcement

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

  • Obtaining 95% CI following Melogit for predictions utilizing fixed and random effects

    Hi all,

    A bit confused reading the stata documentation, trying to go about calculating the 95% confidence interval for linear predictors that include fixed and random effects following modeling of an outcome using melogit.

    I have used melogit with patient level data with a mixed effect at the hospital level. I have no other mixed effect contributions other than hospital and the remaining effects are all fixed. I have generated fake data below which (loosely) is similar to my data (but with way fewer covariates).

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str7 var1 str9 var2 str3 var3 str6 var4 str7 var5
    "Patient" "Hospital " "age" "Income" "outcome"
    "1"       "A"         "75"  "low"    "1"      
    "2"       "A"         "80"  "avg"    "0"      
    "3"       "B"         "55"  "high"   "0"      
    "4"       "B"         "14"  "low"    "0"      
    "5"       "C"         "18"  "avg"    "1"      
    "6"       "C"         "27"  "high"   "1"      
    "7"       "C"         "54"  "low"    "1"      
    "8"       "C"         "90"  "avg"    "0"      
    end
    My model follows the same basic principles as the one listed below:
    Code:
     melogit outcome age i.Income || Hospital :, or
    I have obtained predicted values using random + fixed effects (the default for predict).
    I have further calculated predictions using fixed effects only (using conditional(fixedonly)).

    For the confidence intervals utilizing the fixed effects only, I think I can easily calculate the confidence interval using the following code, which seems to be giving me the expected results.

    Code:
    predict expprob, conditional(fixedonly) **Note this is the code I had previously used to calculate the probabilities of outcome using fixed effects only
    predict e_error, stdp
    predict exb, xb
    generate elb = exb - invnormal(0.95)*e_error
    generate eub = exb + invnormal(0.95)*e_error
    generate expected_lower_prob = invlogit(elb)
    generate expected_upper_prob = invlogit(eub)
    However, I am a bit unclear specifically on how to predict a linear predictor utilizing both fixed and random effects and calculate the standard error for this prediction. In my reading, it seems that the best way to calculate the linear predictor (including fixed and random effects) is with the "fitted" option? Following that, it seems that I need to incorporate the random effects error (reses). However, this does not seem to be the appropriate calculation, as my predicted probabilities have a much MUCH higher expected confidence interval than would be expected.

    Code:
    predict PREDPROB **Similarly, code used to calculate probabilities using fixed and random effects
    predict reses
    predict pxb, fitted
    generate plb = pxb - invnormal(0.95)*(reses + e_error)
    generate pub = pxb + invnormal(0.95)*(reses + e_error)
    generate predicted_lower_prob = invlogit(plb)
    generate predicted_upper_prob = invlogit(pub)
    Using StataBE 18 on a Mac (OS14)

    As always, thanks in advance,
    Chris

  • #2
    Hi all,

    Have been doing further reading online, realized that stdf might be a useful option to calculate standard error of the fitted values. However, I am getting an error that this is not allowed with my predict command

    Code:
    predict error, stdf
    Result "option stdf not allowed"

    Any other way to go about this?

    Comment

    Working...
    X