making a figure, dates, and other advanced topics biostatistics 212 lecture 6
TRANSCRIPT
![Page 1: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/1.jpg)
Making a figure, dates, and other advanced topics
Biostatistics 212
Lecture 6
![Page 2: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/2.jpg)
Housekeeping
• List of confusing Lab 5 terms– Confounders
– Effect modifiers
– Moderators
– Mediators
– Interaction
– Adjust for
– Control for
![Page 3: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/3.jpg)
Housekeeping
• List of confusing Lab 5 terms– Confounders
– Adjust for = Control for
– Effect modification = Interaction• Effect modifiers = Modifier = “Interaction factor”
– Mediators
![Page 4: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/4.jpg)
Housekeeping
• Does A cause B?– “A is associated with B before adjusting for C, but not
afterwards”
– “A is associated with B because A causes C and C causes B”
A B
C
A BC
confounder
mediator
![Page 5: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/5.jpg)
Housekeeping
• Does A cause B?– “A is associated with B, and much more so when C is
present”
A B
CEffect modifier
![Page 6: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/6.jpg)
106 585
186 2165Binge
+ -
+
-
89 374
118 801
CAC
Binge
+ -
+
-
17 211
68 1364
CAC
Binge
+ -
+
-
In men In women
(34%) (14%)
(15%) (7%)
RR = 1.57 (0.94-2.62)RR = 1.50 (1.16-1.93)
RR = 1.94 (1.55-2.42)
RRadj = 1.51 (1.21-1.89)
![Page 7: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/7.jpg)
In men In women
RR = 1.57 (0.94-2.62)RR = 1.50 (1.16-1.93)
Crude RR = 1.94 (1.55-2.42)
RRadj = 1.51 (1.21-1.89)
Compare these to look for CONFOUNDING
![Page 8: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/8.jpg)
In men In women
RR = 1.57 (0.94-2.62)RR = 1.50 (1.16-1.93)
Crude RR = 1.94 (1.55-2.42)
RRadj = 1.51 (1.21-1.89)
Compare these to look for EFFECT MODIFICATION
(none here)
![Page 9: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/9.jpg)
In htn In no htn
RR = 1.69 (0.97-2.95)RR = 3.39 (1.78-6.45)
Crude RR = 2.51 (1.69-3.73)
RRadj = 2.38 (1.57-3.62)
Compare these to look for EFFECT MODIFICATION
(maybe here?)
![Page 10: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/10.jpg)
Housekeeping
• Other Lab 5 issues?
• Lab 4 issues?
• Final Project questions?
![Page 11: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/11.jpg)
Two-part lecture
• Making a figure
• Dates and other fancy stuff– Extra handouts on the web!
![Page 12: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/12.jpg)
Dedication
• To Andy Choi– Andy helped develop this part of the course– These are adapted from his slides– He will be missed.
![Page 13: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/13.jpg)
Agenda
1. Figure basics– Why make a figure?– Types of figures– Elements of a figure
2. Steps in making a figure with Excel
3. Steps in making a figure with Stata
![Page 14: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/14.jpg)
Why use figures?
• When a graphical display of information more effectively conveys the intended message than words.
• “A picture is worth a thousand words”
![Page 15: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/15.jpg)
Types of Figures
• Photographs
• Diagrams
• Figures that Present Numerical Data– Pie charts– Scatter plots– Bar graphs– Line graphs
![Page 16: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/16.jpg)
Figures that Present Numerical Data
• GOOD for presenting overall effects
• NOT GOOD for presenting specific measurements
• EXPENSIVE (in time and $ for journal)
Browner, W. Publishing and Presenting Clinical Research
![Page 17: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/17.jpg)
Figures
• “A picture is worth a thousand words”
52%48%
No Yes
Moderate alcohol consumption in CARDIA participants
How many words is this picture worth?
![Page 18: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/18.jpg)
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
![Page 19: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/19.jpg)
Figures
• “A picture is worth a thousand words”
How many words is this picture worth?
40%
39%
13%
8%
57%26%
9%8%
White Black
0 <1
1-1.9 2+
Alcohol consumption, in drinks/day
![Page 20: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/20.jpg)
Figures
• “A picture is worth a thousand words”
How many words is this picture worth?
White Black
Drinks/day n=1935 n=1727
0 40% 57%
0.1-0.9 39% 26%
1-1.9 13% 9%
2+ 8% 8%
Worth = 1 small table?
(and avoid pie charts in general…)
![Page 21: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/21.jpg)
Figures• “A picture is worth a thousand words”
How many words is this picture worth?
0.0
5.1
.15
.2P
reva
lenc
e of
cor
onar
y ca
lcifi
catio
n
Black women White women Black men White men
By race and genderPrevalence of coronary calcification in moderate drinkers and abstainers
Abstainer Moderate drinker
![Page 22: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/22.jpg)
Figures
• “A picture is worth a thousand words”
How many words is this picture worth?
Proportion with CAC
Abstainer Mod drinker
Black women .047 .036
White women .054 .049
Black men .068 .132
White men .180 .167
Can you see the interaction in this table without a figure?
(Figures are good for illustrating interactions)
![Page 23: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/23.jpg)
Figures
• “A picture is worth a thousand words”
How many words is this picture worth?
-20
00
-10
00
01
00
02
00
0
Ch
an
ge
in
FE
V1 (
mill
ilite
rs)
0 20 40 60
Pack-years of exposure to tobacco
Menthol smokers Non-menthol smokers
Menthol regression Non-menthol regression
![Page 24: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/24.jpg)
Figures
• “A picture is worth a thousand words”
How many words is this picture worth?
Worth = 968 data points?
Nice to show actual data points along with main effect, if possible!
![Page 25: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/25.jpg)
Steps in making an Excel figure
• Sketch your figure
• Make a dummy TABLE
• Write a .do file to fill in the table
• Copy and paste from the log file or the results window into the Table
• Use the Chart Wizard to create the Figure
• Format, format, format until it looks nice
![Page 26: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/26.jpg)
Steps in making an Excel figure
• Sketch your figure
• Make a dummy TABLE
• Write a .do file
• Copy and paste from the log file or the results window into the Table
• Use the Chart Wizard to create the Figure
• Format, format, format until it looks nice
![Page 27: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/27.jpg)
Steps in making an Excel figure
• First, ask yourself:
“What is the purpose of the figure?”
• Sketch the Figure, with title– Try several versions– Point should be clear at a glance– Requires some artistic vision…
![Page 28: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/28.jpg)
Steps in making an Excel figure
• Make a dummy TABLE– Contains the data for the figure– Doesn’t have to look nice
![Page 29: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/29.jpg)
Steps in making an Excel figure
• Make a dummy TABLE– Contains the data for the figure– Doesn’t have to look nice
• Write a .do file to fill in the table
![Page 30: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/30.jpg)
Steps in making an Excel figure
• Make a dummy TABLE– Contains the data for the figure– Doesn’t have to look nice
• Write a .do file to fill in the table
• Copy and paste from log file into the Table
![Page 31: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/31.jpg)
Steps in making an Excel figure
• Make a dummy TABLE– Contains the data for the figure– Doesn’t have to look nice
• Write a .do file to fill in the table
• Copy and paste from log file into the Table
• Use the Chart Wizard to create the Figure
![Page 32: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/32.jpg)
Steps in making an Excel figure
• Sketch your figure
• Make a dummy TABLE
• Write a .do file to fill in the table
• Copy and paste from the log file or the results window into the Table
• Use the Chart Wizard to create the Figure
• Format, format, format until it looks nice
![Page 33: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/33.jpg)
Excel Demonstration…
![Page 34: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/34.jpg)
Pay attention to…
• Formatting– Make it look nice and professional, but not
gaudy– The time-consuming part of making a figure is
usually related to formatting.
![Page 35: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/35.jpg)
Pay attention to…
• Labeling– Your figure should be understandable by itself– All axes should be labeled.– Include important p-values
![Page 36: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/36.jpg)
Pay attention to…
• The Figure Legend– Title, explanations, extra p-values, etc– Separate section in manuscript or at bottom of
page – depends on journal
![Page 37: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/37.jpg)
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, good for bar graphs, etc
– But…• Requires an extra step – copy/pasting to Excel• Harder to reproduce• Much harder to do scatter plots
![Page 38: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/38.jpg)
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?
• Difficult to format: Graphic Editor helps address this
![Page 39: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/39.jpg)
Steps in making an Excel figure
• Sketch the figure
• Make a dummy TABLE
• Write a .do file to fill in the table
• Copy and paste from the log file or the results window into the Table
• Use the Chart Wizard to create the Figure
• Format, format, format until it looks nice
![Page 40: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/40.jpg)
Steps in making a Stata figure
• Sketch the figure
• Make a dummy TABLE
• Write a .do file
• Copy and paste from the log file or the results window into the Table
• Use the Chart Wizard to create the Figure
• Format, format, format until it looks nice
![Page 41: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/41.jpg)
Steps in making a Stata figure
1. Sketch the figure
2. Write a .do file– Compose the command using the dialog box
• Get the syntax down, multiple iterations
– Transfer to your do file and edit
![Page 42: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/42.jpg)
Steps in making a Stata figure
1. Sketch the figure
2. Write a .do file– Compose the command using the dialog box
• Get the syntax down, multiple iterations
– Transfer to your do file and edit
3. Produce graph and edit more?– Graph editor function
![Page 43: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/43.jpg)
Steps in making a Stata figure
1. Sketch the figure
2. Write a .do file– Compose the command using the dialog box
• Get the syntax down, multiple iterations
– Transfer to your do file and edit
3. Produce graph and edit more?– Graph editor function – May need additional Stata commands for
calculating p-values, figure legend, etc
![Page 44: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/44.jpg)
Stata commands intro
– Pie charts• graph pie, over(catvar)
– Bar graphs• graph bar (mean) yvar1 yvar2, over(catvar1) over(catvar2) asyvars
– Box plots• graph box contvar1 contvar2, over(catvar1) over(catvar2)
– Scatter plots• twoway (graphtype yvar xvar) (graphtype yvar xvar)
• scatter, line, connect, lowess, lfit, qfit, etc
![Page 45: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/45.jpg)
Demo
• Scatter plots: bmi vs. lipids– Iterative process of adding commands to do file– Cutting and pasting with substitution– Combining plots– Post-graph editing
![Page 46: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/46.jpg)
Final Checklist for Figures
1. Does the figure make its point clearly?
2. Are the axes, line, bars, and points labeled? Are the scales correct? Sig figs appropriate?
3. Does each figure have a legend, not a title?
4. Are the figures numbered, and do they appear in the text in that order?
5. Does the text complement the information in the figures?
![Page 47: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/47.jpg)
Today’s Lab
• You will create a pie chart, a box plot, and a scatter plot using stata.
• The focus will be on bringing the figure to publication grade.
![Page 48: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/48.jpg)
graph bar (mean) anycac ///
, over(male) ///
over(agecat) ///
asyvars ///
ytitle(Prevalence of coronary calcification) ///
title("Prevalence of coronary calcification by age and sex")
0.2
.4.6
.81
Pre
vale
nce
of
coro
na
ry c
alc
ifica
tion
<30 30-39 40-49 50-59 60-69 70-79 80-89
Prevalence of coronary calcification by age and sex
0 1
![Page 49: Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e435503460f94b365d7/html5/thumbnails/49.jpg)
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))
-20
00
-10
00
01
00
02
00
0
Ch
an
ge
in
FE
V1 (
mill
ilite
rs)
0 20 40 60
Pack-years of exposure to tobacco
Menthol smokers Non-menthol smokersMenthol regression Non-menthol regression