1 / 50

Stata 3, Regression

Stata 3, Regression. Hein Stigum Presentation, data and programs at: http://folk.uio.no/heins/. Agenda. Linear regression GLM Logistic regression Binary regression (Conditional logistic). Linear regression. Birth weight by gestational age. Regression idea. Model and assumptions.

tasha-adams
Download Presentation

Stata 3, Regression

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Stata 3, Regression Hein Stigum Presentation, data and programs at: http://folk.uio.no/heins/ H.S.

  2. Agenda • Linear regression • GLM • Logistic regression • Binary regression • (Conditional logistic) H.S.

  3. Linear regression Birth weight by gestational age H.S.

  4. Regression idea H.S.

  5. Model and assumptions • Model • Assumptions • Independent errors • Linear effects • Constant error variance H.S.

  6. Association measure: RD Model: Start with: Hence: H.S.

  7. Purpose of regression • Estimation • Estimate association between outcome and exposure adjusted for other covariates • Prediction • Use an estimated model to predict the outcome given covariates in a new dataset H.S.

  8. Not adjust Cofactor is a collider Cofactor is in causal path May or may not adjust Cofactor has missing Cofactor has error Adjusting for confounders H.S.

  9. Workflow • Scatterplots • Bivariate analysis • Regression • Model fitting • Cofactors in/out • Interactions • Test of assumptions • Independent errors • Linear effects • Constant error variance • Influence (robustness) H.S.

  10. Scatterplot H.S.

  11. Syntax • Estimation • regress y x1 x2 linear regression • xi: regress y x1 i.c1 categorical c1 • Post estimation • predict yf, xb predict • Manage models • estimates store m1 save model H.S.

  12. Model 1: outcome+exposure H.S.

  13. Model 2: Add counfounders Estimate association: m1=m2 Prediction: m2 is best H.S.

  14. ”Dummies” Assume educ is coded 1, 2, 3 for low, medium and high education Choose low educ as reference Make dummies for the two other categories: generate medium=(educ==2) if educ<. generate high =(educ==3) if educ<. H.S.

  15. Interaction Model: Start with: Hence: H.S.

  16. Model 3: with interaction H.S.

  17. twoway (scatter res y )(qfitci res y) Test of assumptions • Predict y and residuals • predict y, xb • predict res, resid • Plot resid vs y • independent? • linear? • const. var? H.S.

  18. Violations of assumptions • Dependent residuals Mixed models: xtmixed • Non linear effects gen gest2=gest^2 regress weigth gest gest2 sex • Non-constant variance regress weigth gest sex, robust H.S.

  19. Measures of influence • Measure change in: • Outcome (y) • Deviance • Coefficients (beta) • Delta beta, Cook’s distance Remove obs 1, see change remove obs 2, see change H.S.

  20. Points with high influence lvr2plot, mlabel(id) H.S.

  21. Added variable plot: gestational age avplot gest, mlabel(id) H.S.

  22. Removing outlier H.S.

  23. Influence H.S.

  24. Final model Give meaning to constant term: sum gest /* find smallest value */ generate gest2=gest-204 /* smallest gest=204 */ generate sex2=sex-1 /* boys=0, girls=1 */ regress weight gest2 sex2 /* final model */ estimates store m4 H.S.

  25. Logistic regression Being bullied H.S.

  26. Model and assumptions • Model • Assumptions • Independent residuals • Linear effects H.S.

  27. Association measure, Odds ratio Model: Start with: Hence: H.S.

  28. Syntax • Estimation • logistic y x1 x2 logistic regression • xi: logistic y x1 i.c1 categorical c1 • Post estimation • predict yf, pr predict probability • Manage models • estimates store m1 save model • est table m1, eform show OR H.S.

  29. Workflow • Bivariate analysis • Regression • Model fitting • Cofactors in/out • Interactions • Test of assumptions • Independent errors • Linear effects • Influence (robustness) H.S.

  30. Bivariate Generate dummies gen Island= (country==2) if country<. gen Norway= (country==3) gen Finland= (country==4) gen Denmark= (country==5) H.S.

  31. Model 1: outcome and exposure Alternative commands: xi:logistic bullied i.country use xi: i.var for categorical variables xi:logistic bullied i.country , coef coefs instead of OR's xi:logistic bullied i.country if sex!=. & age!=. do if sex and age not missing H.S.

  32. Estimate associations: m1=m2 Predict: m2 best Model 2: Add confounders H.S.

  33. Interaction Model: Start with: Hence: H.S.

  34. Model 3: interaction H.S.

  35. Test of assumptions • Linear effects (of age) • findit lincheck search and install • lincheck xi:logistic bullied age I.country sex H.S.

  36. Points with high influence estimates restore m2 restore best model predict p, p probability (mu in our notation) predict db, db delta-beta (one value, not one per estimate) scatter db p delta-beta plot H.S.

  37. Removing 2 observations Conclusion: Robust results H.S.

  38. Generalized Linear Models Being bullied H.S.

  39. Designs and measures H.S.

  40. Generalized Linear Models, GLM Linear regression Logistic regression Poisson regression H.S.

  41. GLM: Distribution and link • Distribution family • Given by data • Influence p-value, CI • Link function • May chose • Shape (=link-1) • Scale • Association measure H.S.

  42. Distribution and link examples OBS: not for traditional case control data Link: Identity  linear model  additive scale H.S.

  43. Being bullied, 3 models glm bullied Island Norway Finland Denmark sex age, family(binomial) link(logit) glm bullied Island Norway Finland Denmark sex age, family(binomial) link(log) glm bullied Island Norway Finland Denmark sex age, family(binomial) link(identity) H.S.

  44. Convergence problems • If glm does not converge, use: • poisson y x1 x2, irr robust RR • regress y x1 x2, robust RD Stop H.S.

  45. Association measure, RR Model: Start with: Hence: H.S.

  46. Association measure: RD Model: Start with: Hence: H.S.

  47. The importance of scale Additive scale Absolute increase Females: 30-20=10 Males: 20-10=10 Conclusion: Same increase for males and females RD Multiplicative scale Relative increase Females: 30/20=1.5 Males: 20/10=2.0 Conclusion: More increase for males RR H.S.

  48. Stata regression commands H.S.

  49. Regression with simple error structure • regress linear regression (also heteroschedastic errors) • nl non linear least squares • GLM • logistic logistic regression • poisson Poisson regression • binreg binary outcome, OR, RR, or RD effect measures • Conditional logistc • clogit for matched case-control data • Multiple outcome • mlogit multinomial logit (not ordered) • ologit ordered logit • Regression with complex error structure • xtmixed linear mixed models • xtlogit random effect logistic H.S.

  50. Syntax • Estimation • regress y x1 x2 linear regression • logistic y x1 x2 logistic regression • xi:regress y x1 i.x2 categorical x2 • Manage results • estimates store m1 store results • estimates table m1 m2 table of results • estimates stats m1 m2 statistics of results • Post estimation • predict y, xb linear prediction • predict res, resid residuals • lincom b0+2*b3 linear combination • Help • help logistic postestimation H.S.

More Related