Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Richard Williams <richardwilliams.ndu@gmail.com> |

To |
statalist@hsphsun2.harvard.edu, statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Clarification requested about the at() option of -margins- |

Date |
Thu, 24 Oct 2013 12:24:42 -0500 |

At 11:01 AM 10/24/2013, Trevor Zink wrote:

Paul,Thanks very much for your detailed answer. If I may ask a fewfollow-up questions to make sure I understand properly...1) "-margins- converts log-odds (and their slopes) to probabilities(and their slopes) for us". I have spent a lot of time reading about-margins- over the past few weeks, and I can't recall ever hearingit explained like this. Is this really what -margins- does? Simplyconverts from log-odds back to probability? If so, that is greatnews--it makes the interpretation of the output much easier.2) "Although the slope for the log-odds is fixed; that for theprobability is not. As 0 and 1 are approached, the slope tends to0, and the possible values and SE are also constrained". So whatyou're saying is the fact that the slope goes to 0 at the 0 and 1isn't because of any extrapolation like I assumed, it's simply aproduct of mapping onto the logic function?3) You used both -margins, at()- and -margins, dydx() at()-. Myunderstanding of the difference after reading your answer is that-margins, at()- gives the /probability/ of Y==1 at the specifiedvalues of X. Whereas -margins, dydx() at()- gives the /change in theprobability/ of Y==1 from an infintesimal change in X at thespecified values of X. Correct?(as a side note, I wouldn't have expected weight to predict foreignvs domestic as well as it does)Thanks again for your answer. Trevor

y = 2 + 3*x

If you want to know more about how margins works, see http://www3.nd.edu/~rwilliam/xsoc73994/Margins01.pptx http://www3.nd.edu/~rwilliam/xsoc73994/Margins02.pdf http://www3.nd.edu/~rwilliam/xsoc73994/Margins03.pdf

On 10/24/2013 3:13 AM, Seed, Paul wrote:Dear Statalist, Trevor Zink asks why -margins- does not behave as he would expect following logistic regression. The answer is found only by going back to exactly what logistic regression actually does; and how it compares to linear regression.Linear regression is carried out under an assumption of constantslope, and has no problemtherefore in estimating the slope at any value of thepredictors. With a single predictor,the estimated slope does not change. (Point 1 of Stata output).However, it is inappropriate for a binary outcome, as it can leadto estimated proportions beyond 0 and 1.(Point 2).Logistic regression solves this by working with the log-odds,rather than the probability. There are noimpossible values. Extreme log-odds correspond to probabilitiesclose to 0 or 1.-margins- converts log-odds (and their slopes) to probabilities(and their slopes) for us. (Point 3)Although the slope for the log-odds is fixed; that for theprobability is not. As 0 and 1 are approached, theslope tends to 0, and the possible values and SE are alsoconstrained. (Point 4)Plotting the estimated values against weight reveals this quiteclearly. (Point 5)The code below uses Trevor's example (amended and expanded). ************** Begin Stata code******************* set more off sysuse auto, clear gen wt_tons = weight/2240 * Change units to make results easier to understand summarize wt_tons * maximum weight is 2.1607 tons regress foreign wt_tons margins, dydx(wt_tons) at(wt_tons=(0(0.2)2 20)) * Point 1 margins, at(wt_tons=(0(0.2)2 )) * Point 2 logit foreign wt_tons margins, at(wt_tons=(0(0.2)2 )) * Point 3 margins, dydx(wt_tons) at(wt_tons=(0(0.2)2 )) * Point 4 predict Foreign if foreign predict USA if !foreign label var Foreign Foreign label var USA USA label var wt_tons "Car weight (tons)"gr7 Foreign USA wt_tons, xlab(0 1 2) ylab(0 .5 1.0)l1title("Estimated probability of car being foreign")* Point 5 **************** End Stata code ************* Best wishes, Paul T Seed, Senior Lecturer in Medical Statistics, Division of Women's Health, King's College London Women's Health Academic Centre, King's Health Partners (+44) (0) 20 7188 3642.Date: Wed, 23 Oct 2013 23:21:13 -0700 From: Trevor Zink <tzink@bren.ucsb.edu> Subject: st: Clarification requested about the at() option of -margins- Long-time lurker, first-time post. I couldn't find a good explanation in the archives. I'm confused about what, specifically, -margins- is doing with the at() option, such that it can calculate margins for values of variable that don't exist in the data. To articulate with an example: sysuse auto summarize weight //maximum weight is 4840 logit foreign weight //nonsensical, but ok for the example margins, dydx(weight) at(weight=(0(1000)10000 100000)) Here I ask for the slope of the function at a variety of weights from 0 to 10,000 and also 100,000. The maximum weight observed in the data is 4840. My understanding of -margins- with at() was that it calculates the slope of the function holding the specified variables constant at the specified levels. But if the specified level doesn't appear in the data, how can Stata determine what the slope is at this value? Ok, it's clearly extrapolating, but based on what information? The only other information included in the above model is a constant. When I try the above but specifying the nocons option to -logit- Stata returns an error, so it must be forecasting based on the constant; but specifically how? What's even more strange to me is that the standard errors *shrink* as the estimates extend beyond the observed data. If Stata is forecasting based on only the constant this seems counter-intuitive to me. Thanks, and sorry if this is silly. Trevor Zink* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/-- Trevor Zink, MBA, MA Ph.D. Candidate UC Regents Special Fellow Bren School of Environmental Science and Management University of California, Santa Barbara tzink@bren.ucsb.edu <mailto:tzink@bren.ucsb.edu> * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

------------------------------------------- Richard Williams, Notre Dame Dept of Sociology OFFICE: (574)631-6668, (574)631-6463 HOME: (574)289-5227 EMAIL: Richard.A.Williams.5@ND.Edu WWW: http://www.nd.edu/~rwilliam * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: Clarification requested about the at() option of -margins-***From:*Trevor Zink <tzink@bren.ucsb.edu>

**References**:**RE: st: Clarification requested about the at() option of -margins-***From:*"Seed, Paul" <paul.seed@kcl.ac.uk>

**Re: st: Clarification requested about the at() option of -margins-***From:*Trevor Zink <tzink@bren.ucsb.edu>

- Prev by Date:
**Re: st: How to show variable label in a graph title** - Next by Date:
**Re: st: How to get rid of outliers** - Previous by thread:
**Re: st: Clarification requested about the at() option of -margins-** - Next by thread:
**Re: st: Clarification requested about the at() option of -margins-** - Index(es):