# How does one calculate confidence intervals on predictions generated by logit in Stata?

I'd like to make an assertion about whether individuals in my dataset exceed legal standards for commitment, which is largely determined by estimated risk of recidivism. I have estimated a logit model predicting recidivism. Here is sample code written trying to determine what percentage of individuals had predicted recidivism of at least 75% with 75% confidence:

.logit sexrecS [INDEPENDENT VARIABLES]
.predict sr1
.predict stdsr1, stdp
.gen byte sr1C1R1=0
.replace sr1C1R1=1 if 1/(1 + exp(ln((1-sr1)/sr1) - 0.67448975*stdsr1)) > .75
.sum sr1C1R1 if sr1!=. & sexrecS!=.


I later replace 0.67448975 with 1.281551566 to reflect a higher legal standard of proof, but the code generates more, not fewer, hits, so I know I've done something wrong.

-
Fred, a couple of questions: (1) when you say 'commitment' here, is that meaning 'the trait of sincere and steadfast fixity of purpose' or 'the official act of consigning a person to confinement'? (2) If the latter, are you really saying people will be confined or not based on the predictions from your model? If so I think I might wish to seek legal advice before posting an answer! By the way, you might like to take a quick look at the latter paragraphs of the section 'How do I ask questions here?' in the site FAQ:stats.stackexchange.com/faq – onestop Oct 29 '10 at 21:28
@onestop, there actually is a venue through which a person can be "civilly committed" based on future dangerousness to themselves or others. Here's a website that has a good description of what civil commitment is, oregoncounseling.org/LawsRights/CivilCommit.htm . It also is often used against sexual offenders, see nytimes.com/2010/05/18/us/politics/18offenders.html . Although I'm not familiar with any "legal" standards determined through predictive modeling. See my comment to Fred directly. – Andy W Oct 30 '10 at 15:17
@Fred, although you've provided a description well enough to be able to answer your question, given onestop's and mine question over what exactly you are modelling I think it would be nice if you could clarify your design a bit more precisely. In your question do you really mean "legal standards" of commitment are determined by some type of logistic model (and if you do I'd like to know what State (or State entity) you are referring to? Or is this model simply evidence of whether someone should be committed. – Andy W Oct 30 '10 at 15:23
@Fred, Also could you clarify if you mean civilly committed? I am aware of no circumstances where a legal statute has a calculated measure of risk in guiding the laws decision. Although it could be used as evidence in a parole hearing it wouldn't be used in any standardized way that I am aware. – Andy W Oct 30 '10 at 15:25
@Andy W #1: Seems the term 'civil commitment' is a rather wonderful example of our two nations' separation by a common language! e.g. guthriecastle.com/terms-and-conditions – onestop Oct 30 '10 at 17:18
show 1 more comment

Don't try to do too much at once. Note, too:

• 'Predict' without options computes the probabilities. I don't think you want those for this calculation. Use 'predict, xb' to obtain the linear fits.

• Subtract a multiple of the standard error of prediction (obtained via 'predict, stdp') from the linear prediction.

• Now transform the limit with a logistic transformation to convert it to a probability.

• Compare that to .75 (or whatever).

At each step of the way summarize (and even graph) the results to make sure they are behaving as you expect.

It's actually simpler, if not quite as clear, to replace the last two steps by a direct comparison of the limit to the logit of 0.75, defined as ln(.75) - ln(.25) = 1.099.

-
Thanks for the comments and answer. First on the comments: I do mean civil commitment (ie, confinement). I am not proposing a model to be used, but rather using a model to illustrate shortcomings in current practice. The statistics are generally used as evidence, not alone determinative. Some jurisdictions do define sufficient future dangerousness quantitatively (eg, more likely than not). – Fred Vars Oct 31 '10 at 18:12
Based on the answer and my own research, I've written new code that generates plausible results. With a little trepidation (I read the FAQs and still think the question is appropriate, but my apologies if I'm missing something), here it is (feedback welcome) (0.03... is the constant from the logit model): .predict sr2, xb .gen byte sr2C1R1=0 if sr2!=. .gen sr2w = (0.0310417 + sr2 - 0.67448975*stdsr1) .replace sr2C1R1=1 if 1/(1 + exp(-sr2w)) > .75 & sr2!=. & sexrecS!=. .sum sr2C1R1 if sr2!=. & sexrecS!=. – Fred Vars Oct 31 '10 at 18:20
@Fred Questions specifically about how to code such-and-such are of marginal interest, but you actually have presented a statistically interesting question: how does one compute a prediction interval for logistic regression? – whuber Oct 31 '10 at 20:30
@Fred Your calculations still look incorrect. You seem to be mixing up predicted probabilities and standard errors of their logits. – whuber Oct 31 '10 at 20:32
@Fred Ignore the probabilities: work entirely in logits. That will bring you closer to familiar OLS and ML calculations and lets you avoid all that stuff with logarithms and exponentials. All that's required is to convert your threshold of 0.75 into its logit in order to make comparisons. – whuber Nov 2 '10 at 19:40