Example: quiz answers

Interpreting and Visualizing Regression models with Stata ...

Interpreting and Visualizing Regression models with Stata Margins and Marginsplot Boriana Pratt May 2017 2 Interpreting Regression models Often Regression results are presented in a table format, which makes it hard for Interpreting effects of interactions, of categorical variables or effects in a non-linear models . For nonlinear models , such as logistic Regression , the raw coefficients are often not of much interest. What we want to see for interpretation are effects on outcomes such as probabilities (instead of log odds). Stata has a number of handy commands such as margins, marginsplot, contrast for making sense of Regression results and for Visualizing such results. 3 Topics: Marginal Effects at the Mean Average Marginal Effects Marginal Effects at Representative values 660665670675680 Linear Prediction200620072008200920102011 YearAdjusted Predictions of year with 95% CIsmarginsplot ---------------------------------------- -------------------------------------- | Delta-method | Margin Std.

Interpreting regression models • Often regression results are presented in a table format, which makes it hard for interpreting effects of interactions, of categorical variables or effects in a non-linear models. • For nonlinear models, such as logistic regression, the raw coefficients are often not of much interest.

Tags:

  Model, Logistics, Regression, Regression model, Logistic regression

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Interpreting and Visualizing Regression models with Stata ...

1 Interpreting and Visualizing Regression models with Stata Margins and Marginsplot Boriana Pratt May 2017 2 Interpreting Regression models Often Regression results are presented in a table format, which makes it hard for Interpreting effects of interactions, of categorical variables or effects in a non-linear models . For nonlinear models , such as logistic Regression , the raw coefficients are often not of much interest. What we want to see for interpretation are effects on outcomes such as probabilities (instead of log odds). Stata has a number of handy commands such as margins, marginsplot, contrast for making sense of Regression results and for Visualizing such results. 3 Topics: Marginal Effects at the Mean Average Marginal Effects Marginal Effects at Representative values 660665670675680 Linear Prediction200620072008200920102011 YearAdjusted Predictions of year with 95% CIsmarginsplot ---------------------------------------- -------------------------------------- | Delta-method | Margin Std.

2 Err. t P>|t| [95% Conf. Interval] -------------+-------------------------- -------------------------------------- year | 2006 | .2751133 2007 | .2705957 2008 | .26794 2009 | .2651201 margins Margins : asbalanced ---------------------------------------- ---------------- | Contrast Std. Err. t P>|t| ----------------+----------------------- ---------------- year | (2007 vs 2006) | .3858877 (2008 vs 2006) | .3840301 (2009 vs 2006) | .382068 (2010 vs 2006) | .380687 (2011 vs 2006) | .379856 ---------------------------------------- ---------------- margins, contrast margins, pwcompare 4 Margins What are margins ? Margins are statistics calculated from predictions of a previously fit model at fixed values of some covariates and averaging or otherwise integrating over the remaining covariates.

3 (from margins help) conditional margin response at fixed values for all covariates predictive margin response when at least one covariate is left to vary With the margins command you can compute predicted levels for different covariate values or differences in levels (often called marginal effects), or even differences in differences. Continuous vs. discrete marginal effects: For a continuous covariate, margins computes the first derivative of the response with respect to the covariate. For a discrete covariate, margins computes the effect of a discrete change of the covariate (discrete change effects). Use margins command to get marginal means, predictive margins and marginal effects. 5 Datasets NYC math assessment data for 2006-2011 by school and gender (from NYC Open Data: ) nhanes2 (from Stata webuse) 6 Adjusted means .use NYC_MATH_2006_2011_byschool, clear . regress meanscore Source | SS df MS Number of obs = 42,321 -------------+-------------------------- -------- F(1, 42319) = model | 1 Prob > F = Residual | 42,319 R-squared = -------------+-------------------------- -------- Adj R-squared = Total | 42,320 Root MSE = ---------------------------------------- -------------------------------------- meanscore | Coef.

4 Std. Err. t P>|t| [95% Conf. Interval] -------------+-------------------------- -------------------------------------- gender | Male | .2304428 _cons | .1641427 ---------------------------------------- -------------------------------------- How to get mean scores by gender? 7 Adjusted means . di _b[_cons] . di _b[_cons] +_b[ ] . margins gender Adjusted predictions Number of obs = 42,321 model VCE : OLS Expression : Linear prediction, predict() ---------------------------------------- -------------------------------------- | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+-------------------------- -------------------------------------- gender | Female | .1641427 Male | .1617439 ---------------------------------------- -------------------------------------- How to get means by gender?

5 Or, by using `margins : 8 Predicted means . regress meanscore year Source | SS df MS Number of obs = 42,321 -------------+-------------------------- -------- F(2, 42318) = model | 2 Prob > F = Residual | 42,318 R-squared = -------------+-------------------------- -------- Adj R-squared = Total | 42,320 Root MSE = ---------------------------------------- -------------------------------------- meanscore | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+-------------------------- -------------------------------------- gender | Male | .220029 year | .0646029 _cons | ---------------------------------------- -------------------------------------- . di _b[_cons] +_b[year]*2006.

6 Di _b[_cons] +_b[ ] +_b[year]*2006 . di _b[_cons] +_b[year]*2008 . di _b[_cons] +_b[ ] +_b[year]*2008 Predicted meanscore for female in 2006 Predicted meanscore for male in 2006 Predicted meanscore for female in 2008 Predicted meanscore for male in 2008 How to get predicted mean scores for 2006 and 2008 by gender? 9 Predicted means . margins gender, at(year=(2006 2008)) vsquish Adjusted predictions Number of obs = 42,321 model VCE : OLS Expression : Linear prediction, predict() : year = 2006 : year = 2008 ---------------------------------------- -------------------------------------- | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+-------------------------- -------------------------------------- _at#gender | 1#Female | .2277025 1#Male |.

7 2260839 2#Female | .1608015 2#Male | .1585551 ---------------------------------------- -------------------------------------- !Note: gender has to be a factor variable in the model . How to get predicted mean scores for 2006 and 2008 by gender? 10 Marginsplot . margins gender, at(year=(2006(1)2011)) vsquish . marginsplot 660665670675680685 Linear Prediction200620072008200920102011 YearFemaleMaleAdjusted Predictions of gender with 95% CIs!Note: marginsplot has to be right after margins . 11 Marginsplot . margins, at(year=(2006(1)2011)) vsquish To plot with confidence interval lines: . marginsplot, recast(line) recastci(rarea) ciopts(color(*.7)) 660665670675680685 Linear Prediction200620072008200920102011 YearPredictive Margins with 95% CIs12 Predicted means Q: What does the following command produce? . margins, at(year=(2006 2008)) vsquish Q: How can you get the same numbers from the Regression equation?

8 13 Predicted means . margins , at(year=(2006 2008)) vsquish Predictive margins Number of obs = 42,321 model VCE : OLS Expression : Linear prediction, predict() : year = 2006 : year = 2008 ---------------------------------------- -------------------------------------- | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+-------------------------- -------------------------------------- _at | 1 | .1984318 2 | .1157263 ---------------------------------------- -------------------------------------- . di _b[_cons] +_b[ ]* +_b[year]*2006 . di _b[_cons] +_b[ ]* +_b[year]*2008 Q: What does the following command produce? . margins, at(year=(2006 2008)) vsquish Q: How can you get the same numbers from the Regression equation?

9 14 Predicted means . margins , at(year=(2006 2008)) vsquish asbalanced Adjusted predictions Number of obs = 42,321 model VCE : OLS Expression : Linear prediction, predict() : gender (asbalanced) year = 2006 : gender (asbalanced) year = 2008 ---------------------------------------- -------------------------------------- | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] -------------+-------------------------- -------------------------------------- _at | 1 | .1984388 2 | .1157378 ---------------------------------------- -------------------------------------- Margins option treat all factor variables as balanced: In the data there are boys and girls, with the asbalanced option margins predicts the means if the data had 50% boys and 50% girls.

10 15 Average marginal effects . margins , dydx(*) Average marginal effects Number of obs = 42,321 model VCE : OLS Expression : Linear prediction, predict() dy/dx : year ---------------------------------------- -------------------------------------- | Delta-method | dy/dx Std. Err. t P>|t| [95% Conf. Interval] -------------+-------------------------- -------------------------------------- gender | Male | .220029 year | .0646029 ---------------------------------------- -------------------------------------- Note: dy/dx for factor levels is the discrete change from the base level. Marginal effect (ME) measures the effect on the conditional mean of y of a change in one of the regressors . In the linear Regression model , the marginal effect equals the relevant slope coefficient.


Related search queries