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).
My model follows the same basic principles as the one listed below:
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.
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.
Using StataBE 18 on a Mac (OS14)
As always, thanks in advance,
Chris
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
Code:
melogit outcome age i.Income || Hospital :, or
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)
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)
As always, thanks in advance,
Chris
Comment