Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6.
-
Upload
rolf-barber -
Category
Documents
-
view
220 -
download
2
Transcript of Making a figure, dates, and other advanced topics Biostatistics 212 Lecture 6.
Making a figure, dates, and other advanced topics
Biostatistics 212
Lecture 6
Housekeeping
• List of confusing Lab 5 terms– Confounders
– Effect modifiers
– Moderators
– Mediators
– Interaction
– Adjust for
– Control for
Housekeeping
• List of confusing Lab 5 terms– Confounders
– Adjust for = Control for
– Effect modification = Interaction• Effect modifiers = Modifier = “Interaction factor”
– Mediators
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
Housekeeping
• Does A cause B?– “A is associated with B, and much more so when C is
present”
A B
CEffect modifier
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)
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
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)
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?)
Housekeeping
• Other Lab 5 issues?
• Lab 4 issues?
• Final Project questions?
Two-part lecture
• Making a figure
• Dates and other fancy stuff– Extra handouts on the web!
Dedication
• To Andy Choi– Andy helped develop this part of the course– These are adapted from his slides– He will be missed.
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
Why use figures?
• When a graphical display of information more effectively conveys the intended message than words.
• “A picture is worth a thousand words”
Types of Figures
• Photographs
• Diagrams
• Figures that Present Numerical Data– Pie charts– Scatter plots– Bar graphs– Line graphs
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
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?
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?
40%
39%
13%
8%
57%26%
9%8%
White Black
0 <1
1-1.9 2+
Alcohol consumption, in drinks/day
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…)
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
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)
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
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!
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
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
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…
Steps in making an Excel figure
• Make a dummy TABLE– Contains the data for the figure– Doesn’t have to look nice
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
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
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
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
Excel Demonstration…
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.
Pay attention to…
• Labeling– Your figure should be understandable by itself– All axes should be labeled.– Include important p-values
Pay attention to…
• The Figure Legend– Title, explanations, extra p-values, etc– Separate section in manuscript or at bottom of
page – depends on journal
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
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
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
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
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
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
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
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
Demo
• Scatter plots: bmi vs. lipids– Iterative process of adding commands to do file– Cutting and pasting with substitution– Combining plots– Post-graph editing
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?
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.
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
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