Making a figure with Stata or Excel Biostatistics 212 Lecture 7
Housekeeping Lab 5 cleanup –Which p-value is which? –Deciding when to “call” an interaction Final Project questions? –Print and hand in to Olivia or Allison (5 th floor) by the end of the day on 9/19/06 –20 points docked for each 1 day late – or call for help! PLEASE DO COURSE EVALUATIONS –You’ll get a link by
. cs dead anycac, by(ageover60) ageover60 | RR [95% Conf. Interval] M-H Weight | | Crude | M-H combined | Test of homogeneity (M-H) chi2(1) = Pr>chi2 =
. mhodds dead anycac, by(ageover60) Maximum likelihood estimate of the odds ratio Comparing anycac==1 vs. anycac==0 by ageover ageov~60 | Odds Ratio chi2(1) P>chi2 [95% Conf. Interval] | | Mantel-Haenszel estimate controlling for ageover Odds Ratio chi2(1) P>chi2 [95% Conf. Interval] Test of homogeneity of ORs (approx): chi2(1) = 0.02 Pr>chi2 =
. xi: logistic dead i.anycac*i.ageover60 i.anycac _Ianycac_0-1 (naturally coded; _Ianycac_0 omitted) i.ageover60 _Iageover60_0-1 (naturally coded; _Iageover60_0 omitted) i.any~c*i.ag~60 _IanyXage_#_# (coded as above) Logistic regression Number of obs = LR chi2(3) = Prob > chi2 = Log likelihood = Pseudo R2 = dead | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] _Ianycac_1 | _Iageover6~1 | _IanyXage_~1 |
. logistic dead anycac ageover60 Logistic regression Number of obs = LR chi2(2) = Prob > chi2 = Log likelihood = Pseudo R2 = dead | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] anycac | ageover60 |
. cs dead anycac, by(male) male | RR [95% Conf. Interval] M-H Weight | | Crude | M-H combined | Test of homogeneity (M-H) chi2(1) = Pr>chi2 =
Housekeeping Lab 5 cleanup –Which p-value is which? –Deciding when to “call” an interaction Final Project questions? –Print and hand in to Olivia or Allison (5 th floor) by the end of the day on 9/19/06 –20 points docked for each 1 day late – or call for help! PLEASE DO COURSE EVALUATIONS –You’ll get a link by
Today... Figure basics –Why make a figure? –Types of figures –Elements of a figure Steps in making a figure Stata versus Excel The Final Project, grading
Figures Figures are GOOD for presenting overall effects Figure are NOT GOOD for presenting specific measurements Browner, W. Publishing and Presenting Clinical Research
Figures “A picture is worth a thousand words”
Figures “A picture is worth a thousand words” How many words is this picture worth?
Figures “A picture is worth a thousand words” How many words is this picture worth? 48% of CARDIA participants consume alcohol moderately. Worth = 7 words
Figures “A picture is worth a thousand words” How many words is this picture worth?
Figures “A picture is worth a thousand words” How many words is this picture worth? WhiteBlack Drinks/dayn=1935n= %57% %26% %9% 2+8%8% Worth = 1 small table
Figures “A picture is worth a thousand words” How many words is this picture worth?
Figures “A picture is worth a thousand words” How many words is this picture worth? % with CAC AbstainerMod drinker Black women White women Black men White men
Figures “A picture is worth a thousand words” How many words is this picture worth? Worth = “A thousand words”?
Figures “A picture is worth a thousand words” How many words is this picture worth?
Figures “A picture is worth a thousand words” How many words is this picture worth? Worth = 968 data points + lines > 1000 words?
Figures “A picture is worth a thousand words” Guidelines –Figures should have a minimum of 4 data points –Convey important effects, or interactions Browner, W. Publishing and Presenting Clinical Research
Figures Types of figures –Photographs –Diagrams –Data representation Browner, W. Publishing and Presenting Clinical Research
Figures Types of data figures –Pie charts –Bar graphs –Line graphs –Scatter plots –Box plots Browner, W. Publishing and Presenting Clinical Research
Figures Elements of a figure –Graphics (non-text) –Labels (axes, lines/bars, etc), other text –Figure legend (Title, explanations, p-values) Browner, W. Publishing and Presenting Clinical Research
Steps in making a Figure In Stata: –Sketch the Figure, with title –Write a do file –Format so it makes sense and looks nice –Compose a figure legend In Excel: –Sketch the Figure, with title –Dummy data table in Excel –Write a do file to fill in table –Copy and paste the data in –Format so it makes sense and looks nice –Compose a figure legend
Steps in making a Figure Sketch the Figure, with title –Try several versions –Point should be clear at a glance –Requires some artistic vision…
Steps in making a Figure Can I make this figure with Stata?
Stata vs. Excel for Figures Stata –Can create very customizable figures using 1 complex Stata command Easy to recreate – simple do file No error Scatter plots are MUCH easier with Stata –But… Harder to create the first time? - no point and click A little less flexible?
Stata vs. Excel for Figures Excel –Flexible and intuitive point-and-click figures Easy to create and modify Flexible, more options, error bars, adjusted estimates, etc –But… Requires an extra step – copy/pasting to Excel Harder to reproduce Much harder to do scatter plots
Stata vs. Excel for Figures Both Stata and Excel can produce very nice- looking figures.
Steps in making a Figure Write a do file –If making a figure with Stata, your do file might contain only 1 actual Stata command
Steps in making a Figure Write a do file –If making a figure with Stata, your do file might contain only 1 actual Stata command twoway (scatter dfev1 cumpy10 if menthol1==1, msymbol(plus) msize(small) mcolor(black)) /// (scatter dfev1 cumpy10 if menthol1==0, msymbol(circle_hollow)) /// (line m cumpy10 if menthol1==1, sort clcolor(black) clpat(dash) clwidth(thick)) /// (line nm cumpy10 if menthol1==0, sort clcolor(black) clpat(solid) clwidth(thick)) ///, ytitle(Change in FEV1 (milliliters), size(large)) yscale(titlegap(5)) /// xtitle(Pack-years of exposure to tobacco, size(large)) /// xscale(titlegap(3)) /// legend(order(1 "Menthol smokers" 2 "Non-menthol smokers" 3 "Menthol regression" /// 4 "Non-menthol regression")) /// scheme(s1mono) /// graphregion(fcolor(none) lcolor(none) ifcolor(none) ilcolor(none)) /// plotregion(fcolor(none) lcolor(none) ifcolor(none) ilcolor(none))
Steps in making a Figure Write a do file –If making a figure with Stata, your do file might contain only 1 actual Stata command Compose using dialog box from menu
Steps in making a Figure Write a do file –If making a figure with Stata, your do file might contain only 1 actual Stata command Compose using dialog box from menu –If making it with Excel, you’ll need to produce all the numbers with analysis Paste into Excel from log file Use Chart Wizard
Steps in making a Figure Write a do file –If making a figure with Stata, your do file might contain only 1 actual Stata command Compose using dialog box from menu –If making it with Excel, you’ll need to produce all the numbers with analysis Paste into Excel from log file Use Chart Wizard –Either way, you may need additional Stata commands for p-values, figure legend, etc
Steps in making a Figure Format so it looks nice, and makes sense –With Stata: Use dialog box Submit, modify, submit again, etc –With Excel Point, click, modify
Steps in making a Figure Compose a figure legend –Title, explanations, p-values, etc –Separate section in manuscript or at bottom of page – depends on journal
Steps in making a Figure Example – Excel Example - Stata
twoway (scatter dfev1 cumpy10 if menthol1==1, msymbol(plus) msize(small) mcolor(black)) /// (scatter dfev1 cumpy10 if menthol1==0, msymbol(circle_hollow)) /// (line m cumpy10 if menthol1==1, sort clcolor(black) clpat(dash) clwidth(thick)) /// (line nm cumpy10 if menthol1==0, sort clcolor(black) clpat(solid) clwidth(thick)) ///, ytitle(Change in FEV1 (milliliters), size(large)) yscale(titlegap(5)) /// xtitle(Pack-years of exposure to tobacco, size(large)) /// xscale(titlegap(3)) /// legend(order(1 "Menthol smokers" 2 "Non-menthol smokers" 3 "Menthol regression" /// 4 "Non-menthol regression")) /// scheme(s1mono) /// graphregion(fcolor(none) lcolor(none) ifcolor(none) ilcolor(none)) /// plotregion(fcolor(none) lcolor(none) ifcolor(none) ilcolor(none))
graph bar (mean) cac ///, over(modalc) /// over(racegender) /// asyvars /// ytitle(Prevalence of coronary calcification) /// title("Prevalence of coronary calcification in moderate drinkers and abstainers", /// size(medium) span) /// subtitle("By race and gender", size(medsmall))
Summary figure tips Only use a Figure if: –There is an important message to convey –The visual will be more compelling and clear Try using both Stata and Excel –Stata will be harder at first, but often worth it –Browner book, Stata book both helpful Document, label, and be creative
Final Project, grading Grading –80% (256 out of 319 possible) required to get a “Satisfactory” score in the class –Also need to turn in all the Labs, even if they are late
Final Project, grading Final Project will count for 150/319 points –Table – 75 points 35 for do file log –Housekeeping commands: open/close log, use dataset, etc –Analysis: generate numbers in the Table 40 for Table itself –Architecture –Documentation –Formatting/appearance
Final Project, grading Final Project will count for 150/319 points –Figure – 75 points 35 for do file log –Housekeeping commands: open/close log, use dataset, etc –Analysis 40 for Figure itself –Design –Documentation –Formatting/appearance
Final Project, grading Extra credit –10 points extra credit and bragging rights for the most artistic, creative, and clear figure turned in
Final Project, grading Advice –Find a classmate, give them your Table and Figure, and get their critiques. See if they can understand it without any verbal explanation
That’s it! Thanks for your active participation in the course.