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 13:30:30 -0500 |

At 12:03 PM 10/24/2013, Trevor Zink wrote:

Thanks, Richard. I had actually run across some of your materials before; they were helpful. My actual problem is obviously more complex than the simple example I illustrated with. At what point (of complexity) is -margins- no longer "just plugging numbers into formulas"? In my actual problem I'm not using interactions, but I am using multiple regressors and factor variables.

Thanks Trevor On 10/24/2013 10:24 AM, Richard Williams wrote: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) toprobabilities (and their slopes) for us". I have spent a lot oftime reading about -margins- over the past few weeks, and I can'trecall ever hearing it explained like this. Is this really what-margins- does? Simply converts from log-odds back to probability?If so, that is great news--it makes the interpretation of theoutput 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 inthe probability/ 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 predictforeign vs domestic as well as it does)Thanks again for your answer. TrevorTrevor, particularly for a simple problem like yours, margins isjust plugging numbers into formulas. So, for example, if you had a formula likey = 2 + 3*xyou could plug in whatever value you wanted for x (including atotally nonsensical one, e.g. a negative value for weight) and youcould get a value for y. Margins doesn't know or care whether thenumbers are sensible or not. Sometimes it is realistic to go a bitoutside the observed sample range, e.g. try a 5,000 pound car, butin this case it would be silly to go up to 100,000 pounds. But youhave to figure that out, not margins.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.pdfOn 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 the predictors. 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 0to 10,000 and also 100,000. The maximum weight observed in thedata 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/-- 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/

**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>

**Re: st: Clarification requested about the at() option of -margins-***From:*Richard Williams <richardwilliams.ndu@gmail.com>

**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):