making a figure with stata or excel biostatistics 212 lecture 7

47
Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Upload: aron-mcgee

Post on 28-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Making a figure with Stata or Excel

Biostatistics 212

Lecture 7

Page 2: 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 (5th floor) by the end of the

day on 9/19/06– 20 points docked for each 1 day late– Email or call for help!

• PLEASE DO COURSE EVALUATIONS– You’ll get a link by email

Page 3: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

. cs dead anycac, by(ageover60)

ageover60 | RR [95% Conf. Interval] M-H Weight-----------------+------------------------------------------------- 0 | 3.294296 2.124413 5.108418 11.78094 1 | 3.372508 1.922288 5.916809 9.848343 -----------------+------------------------------------------------- Crude | 4.763402 3.413478 6.64718 M-H combined | 3.329908 2.345418 4.727639-------------------------------------------------------------------Test of homogeneity (M-H) chi2(1) = 0.004 Pr>chi2 = 0.9479

Page 4: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

. mhodds dead anycac, by(ageover60)

Maximum likelihood estimate of the odds ratioComparing anycac==1 vs. anycac==0by ageover60

------------------------------------------------------------------------------- ageov~60 | Odds Ratio chi2(1) P>chi2 [95% Conf. Interval]----------+-------------------------------------------------------------------- 0 | 3.343423 31.95 0.0000 2.14383 5.21426 1 | 3.537836 20.94 0.0000 1.98502 6.30536-------------------------------------------------------------------------------

Mantel-Haenszel estimate controlling for ageover60 ---------------------------------------------------------------- Odds Ratio chi2(1) P>chi2 [95% Conf. Interval] ---------------------------------------------------------------- 3.429722 51.90 0.0000 2.400138 4.900967 ----------------------------------------------------------------

Test of homogeneity of ORs (approx): chi2(1) = 0.02 Pr>chi2 = 0.8776

Page 5: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

. xi: logistic dead i.anycac*i.ageover60i.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 = 10372 LR chi2(3) = 188.43 Prob > chi2 = 0.0000Log likelihood = -1065.5418 Pseudo R2 = 0.0812

------------------------------------------------------------------------------ dead | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]-------------+---------------------------------------------------------------- _Ianycac_1 | 3.343423 .7564415 5.33 0.000 2.145898 5.209232_Iageover6~1 | 3.075541 1.040157 3.32 0.001 1.585049 5.96761_IanyXage_~1 | 1.058148 .3922776 0.15 0.879 .5116676 2.188289------------------------------------------------------------------------------

Page 6: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

. logistic dead anycac ageover60

Logistic regression Number of obs = 10372 LR chi2(2) = 188.41 Prob > chi2 = 0.0000Log likelihood = -1065.5534 Pseudo R2 = 0.0812

------------------------------------------------------------------------------ dead | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]-------------+---------------------------------------------------------------- anycac | 3.415374 .6105826 6.87 0.000 2.40583 4.848547 ageover60 | 3.223499 .4453269 8.47 0.000 2.458861 4.225919------------------------------------------------------------------------------

Page 7: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

. cs dead anycac, by(male)

male | RR [95% Conf. Interval] M-H Weight-----------------+------------------------------------------------- 0 | 5.901622 3.668887 9.493106 8.3619 1 | 4.287304 2.679298 6.860369 11.74511 -----------------+------------------------------------------------- Crude | 4.763402 3.413478 6.64718 M-H combined | 4.95865 3.549869 6.926513-------------------------------------------------------------------Test of homogeneity (M-H) chi2(1) = 0.883 Pr>chi2 = 0.3473

Page 8: 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 (5th floor) by the end of the

day on 9/19/06– 20 points docked for each 1 day late– Email or call for help!

• PLEASE DO COURSE EVALUATIONS– You’ll get a link by email

Page 9: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 10: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Figures

• Figures are GOOD for presenting overall effects

• Figure are NOT GOOD for presenting specific measurements

Browner, W. Publishing and Presenting Clinical Research

Page 11: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Figures

• “A picture is worth a thousand words”

Page 12: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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 13: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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 14: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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 15: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 16: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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 17: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Figures

• “A picture is worth a thousand words”

How many words is this picture worth?

% with CAC

Abstainer Mod drinker

Black women .047 .036

White women .054 .049

Black men .068 .132

White men .180 .167

Page 18: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Figures

• “A picture is worth a thousand words”

How many words is this picture worth?

Worth = “A thousand words”?

Page 19: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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 20: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Figures

• “A picture is worth a thousand words”

How many words is this picture worth?

Worth = 968 data points + lines > 1000 words?

Page 21: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 22: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Figures

• Types of figures– Photographs– Diagrams– Data representation

Browner, W. Publishing and Presenting Clinical Research

Page 23: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Figures

• Types of data figures– Pie charts– Bar graphs– Line graphs– Scatter plots– Box plots

Browner, W. Publishing and Presenting Clinical Research

Page 24: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 25: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 26: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Steps in making a Figure

• Sketch the Figure, with title– Try several versions– Point should be clear at a glance– Requires some artistic vision…

Page 27: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Steps in making a Figure

• Can I make this figure with Stata?

Page 28: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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?

Page 29: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 30: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Stata vs. Excel for Figures

• Both Stata and Excel can produce very nice-looking figures.

Page 31: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 32: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Steps in making a Figure

• Write a do file– If making a figure with Stata, your do file

might contain only 1 actual Stata commandtwoway (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))

Page 33: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 34: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 35: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 36: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 37: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 38: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Steps in making a Figure

• Example – Excel

• Example - Stata0

.05

.1.1

5.2

Pre

vale

nce

of c

oron

ary

cal

cific

atio

n

Black women White women Black men White men

By race and genderPrevalence of coronary calcification in moderate drinkers and abstainers

Abstainer Moderate drinker

Prevalence of coronary calcification in abstainers and moderate drinkers, by race and gender

0

0.05

0.1

0.15

0.2

Black women White women Black men White men

Pre

vale

nce

of

coro

nar

y ca

lcif

icat

ion

Abstainer Moderate drinker

RR of CAC for moderate drinking in Black Men = 1.9 (3.3-8.4)p = 0.017p for interaction = 0.10

Page 39: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 40: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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))

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 41: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 42: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 43: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 44: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 45: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

Final Project, grading

• Extra credit– 10 points extra credit and bragging rights for

the most artistic, creative, and clear figure turned in

Page 46: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

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

Page 47: Making a figure with Stata or Excel Biostatistics 212 Lecture 7

That’s it!

• Thanks for your active participation in the course.