Announcement

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

  • Predicted probabilities greater than one after xtmelogit

    Dear list users,

    I am estimating a multilevel logistic regression (xtmelogit) with cross-level interactions and I am trying to vizualize the results with predicted values (predicted probabilities). After predicting margins, I do get a plot that makes sense substantively (in terms of shape) and is in line with other visualizations, yet the predicted values apear to be greater than one, which makes no sence if they are probabilties. I use the following code to obtain these values:

    xtmelogit polpart_binary2 sex cage ceducation cincome cpolinterest csatisfdem cinternalefficacy c.cexternalefficacy##i.DGOVSPEND CGDP || COUNTRY: cexternalefficacy, intpoints(30)
    margins DGOVSPEND, at(cexternalefficacy =(-1.671587 (.5) 2.770934) sex =(0)) atmeans ///
    expression(exp(predict(xb)))
    matrix b=r(b)'
    matrix list b
    matrix at=r(at)
    matrix list at
    matrix at=at[1...,"cexternalefficacy"]#(1\1)
    matrix list at
    matrix v=r(V)
    matrix list v
    matrix se=vecdiag(cholesky(diag(vecdiag(v))))'
    matrix list se
    matrix d=at,b, se
    matrix list d
    svmat d, names(b)
    generate b5 = mod(_n,2) in 1/18
    generate ub = b2 + 1.960*b3
    generate lb = b2 - 1.960*b3
    clist b1-lb in 1/18
    graph twoway (line b2 ub lb b1 if b5==0) (line b2 ub lb b1 if b5==1)

    I attach the resulting plot.

    Could someone explain to me why it is possible that I get predicted values greater than one?

    Thanks a lot.
    Joost
    Plot of resulting predicted values

  • #2
    Are you sure that they're probabilities?
    Code:
    margins DGOVSPEND, . . . expression(exp(predict(xb)))
    Have you considered just using predict directly after fitting the model, and then plotting the predicted probabilities and confidence bounds from the new variables that you create in the dataset?

    Comment


    • #3
      Joseph Coveney is correct: exp(predict(xb)) does not give you predicted probabilities, it gives you odds ratios. The link function is -logit-, so -invlogit()- is the function connecting the linear predictor to the predicted probability. On top of that, xb gives you only the fixed-effects part of the predictor.

      And why don't you just use -marginsplot- after -margins-?

      Comment


      • #4
        Thanks to you both. This is already very helpful. Would either of you have a syntax for the 'predict' approach?

        Comment

        Working...
        X