STAT 101 Dr Kari Lock Morgan Describing Data
STAT 101 Dr. Kari Lock Morgan Describing Data: Two Variables SECTIONS 2. 1, 2. 4, 2. 5 • Two categorical (2. 1) • Quantitative and categorical (2. 4) • Two quantitative (2. 5) Statistics: Unlocking the Power of Data Lock 5
The Big Picture Population Sampling Sample Statistical Inference Statistics: Unlocking the Power of Data Descriptive Statistics Lock 5
Two Categorical Variables � Look at the relationship between two categorical variables 1. Relationship status 2. Gender Statistics: Unlocking the Power of Data Lock 5
Two-Way Table Female In a Relationship 32 It’s Complicated 12 Male 10 7 Total 42 19 Single 63 45 108 Total 107 62 169 � It doesn’t matter which variable is displayed in the rows and which in the columns R: table(relationship, gender) Statistics: Unlocking the Power of Data from Duke students Lock 5
Two-Way Table Female In a Relationship 32 It’s Complicated 12 Male 10 7 Total 42 19 Single 63 45 108 Total 107 62 169 What proportion of students in this sample are in a relationship? Statistics: Unlocking the Power of Data a) b) c) d) 42/169 25% 32/107 30% 10/62 16% 32/42 76% Lock 5
Two-Way Table Female In a Relationship 32 It’s Complicated 12 Male 10 7 Total 42 19 Single 63 45 108 Total 107 62 169 a) What proportion of b) females in this sample are c) in a relationship? d) Statistics: Unlocking the Power of Data 42/169 25% 32/107 30% 10/62 16% 32/42 76% Lock 5
Male and Female Proportions � 30% of females in the sample say they are in a relationship � 16% of males in the sample say they are in a relationship �Why the difference? ? ? Statistics: Unlocking the Power of Data Lock 5
Difference in Proportions � Statistics: Unlocking the Power of Data Lock 5
Two-Way Table Female In a Relationship 32 It’s Complicated 12 Male 10 7 Total 42 19 Single 63 45 108 Total 107 62 169 a) What proportion of b) people in a relationship in c) this sample are female? d) Statistics: Unlocking the Power of Data 42/169 25% 32/107 30% 10/62 16% 32/42 76% Lock 5
Two-Way Table CAUTION: The proportion of females in a relationship is NOT THE SAME AS the proportion of people in a relationship who are female! � 30% ≠ 76%! Statistics: Unlocking the Power of Data Lock 5
Side-by-Side Bar Chart � The height of each bar is the number of the corresponding cell in the two-way table R: barplot(relationship~gender, beside=TRUE) Statistics: Unlocking the Power of Data Lock 5
Segmented Bar Chart � A segmented bar chart is like a side-by-side bar chart, but the bars are stacked instead of side-by-side R: barplot(relationship~gender) Statistics: Unlocking the Power of Data Lock 5
Vitamin D Injections �Many kidney dialysis patients get vitamin D injections to correct for a lack of calcium. Two forms of vitamin D injections are used: calcitriol and paricalcitol. The records of 67, 000 dialysis patients were examined, and half received one drug; the other half the other drug. After three years, 58. 7% of those getting paricalcitol had survived, while only 51. 5% of those getting calcitriol had survived. �Construct an approximate two-way table of the data (due to rounding of the percentages we can’t recover the exact counts – round to whole numbers). Source: Teng, M. , et. al. , “Survival of patients undergoing hemodialysis with paricalcitol or calcitriol Therapy, ” New England Journal of Medicine, July 31, 2003; 349(5): 446 -456. Statistics: Unlocking the Power of Data Lock 5
Vitamin D Injections Survived Died Total Calcitriol 17, 252 16, 248 33, 500 Paricalcitol 19, 665 13, 835 33, 500 Total 36, 917 30, 083 67, 000 Statistics: Unlocking the Power of Data Lock 5
Kidney Stones Success Failure Treatment A 273 77 Treatment B 289 61 Which treatment is better at removing kidney stones? a) Treatment A b) Treatment B R. Charig, D. R. Webb, S. R. Payne, O. E. Wickham (1986). "Comparison of treatment of renal calculi by open surgery, percutaneous nephrolithotomy, and extracorporeal shockwave lithotripsy". Br Med J (Clin Res Ed) 292 (6524): 879– 882 Statistics: Unlocking the Power of Data Lock 5
Kidney Stones SMALL STONES Success Failure Treatment A 81 6 Treatment B 234 36 Which treatment is better at removing small kidney stones? a) Treatment A b) Treatment B Statistics: Unlocking the Power of Data Lock 5
Kidney Stones LARGE STONES Success Failure Treatment A 192 71 Treatment B 55 25 Which treatment is better at removing large kidney stones? a) Treatment A b) Treatment B Statistics: Unlocking the Power of Data Lock 5
Kidney Stones • Treatment A is more effective for all kidney stones, but the data shows Treatment B to be effective overall! • How is this possible!? !? Statistics: Unlocking the Power of Data Lock 5
Kidney Stones – Simpson’s Paradox ALL STONES Success Failure Success Rate Treatment A 273 77 78% Treatment B 289 61 83% Small Stones Success Failure Success Rate Treatment A 81 6 93% Treatment B 234 36 87% Large Stones Success Failure Success Rate Treatment A 192 71 73% Treatment B 55 25 69% Statistics: Unlocking the Power of Data Lock 5
Kidney Stones • Treatment A is used more often on large stones, which are harder to treat. • This is an example of Simpson’s Paradox: an observed relationship between two variables can change (or even reverse!) when a third variable is considered Statistics: Unlocking the Power of Data Lock 5
Kidney Stones Statistics: Unlocking the Power of Data Lock 5
Statistics: Unlocking the Power of Data Lock 5
Slope = # successful / # unsuccessful = odds Small Stones Treatment A Treatment B Successful 81 (93%) 234 (87%) Unsuccessful 6 36 Statistics: Unlocking the Power of Data Lock 5
Slope = # successful / # unsuccessful = odds Large Stones Treatment A Treatment B Successful 192 (73%) 55 (69%) Unsuccessful 71 25 Statistics: Unlocking the Power of Data Lock 5
Combined Treatment A Treatment B Successful 81+192=273 289 Unsuccessful 6+71=77 61 Statistics: Unlocking the Power of Data Lock 5
Combined Treatment A Treatment B Successful 273 (78%) 289 (83%) Unsuccessful 77 61 Statistics: Unlocking the Power of Data Lock 5
Combined Treatment A Treatment B Successful 273 (78%) 289 (83%) Unsuccessful 77 61 Statistics: Unlocking the Power of Data Lock 5
Statistics: Unlocking the Power of Data Lock 5
Summary: Two Categorical Variables � Summary Statistics Two-way table Difference in proportions � Visualization Side-by-side bar chart Segmented bar chart Statistics: Unlocking the Power of Data Lock 5
Quantitative and Categorical Relationships �Interested in a quantitative variable broken down by categorical groups Statistics: Unlocking the Power of Data Lock 5
Tea and the Immune System • Participants were randomized to drink five or six cups of either tea or coffee every day for two weeks (both drinks have caffeine but only tea has L-theanine) • After two weeks, blood samples were exposed to an antigen, and production of interferon gamma (immune system response) was measured • Explanatory variable: tea or coffee • Response variable: measure of interferon gamma Mednick, Cai, Kanady, and Drummond (2008). “Comparing the benefits of caffeine, naps and placebo on verbal, motor and perceptual memory, ” Behavioral Brain Research, 193, 79 -86. Statistics: Unlocking the Power of Data Lock 5
Tea and the Immune System If the tea drinkers have significantly higher levels of interferon gamma, can we conclude that drinking tea rather than coffee caused an increase in this aspect of the immune response? a) Yes b) No Randomized experiment – possible to make conclusions about causality Statistics: Unlocking the Power of Data Lock 5
Side-by-Side Boxplots R: boxplot(Interferon. Gamma~Drink) Statistics: Unlocking the Power of Data Lock 5
Quantitative Statistics by a Categorical Variable � Statistics: Unlocking the Power of Data Lock 5
Difference in Means � R: compare. Mean(Interferon. Gamma~Drink) Statistics: Unlocking the Power of Data Lock 5
Summary: One Quantitative and One Categorical � Summary Statistics Any summary statistics for quantitative variables, broken down by groups Difference in means � Visualization Side-by-side boxplots Statistics: Unlocking the Power of Data Lock 5
Two Quantitative Variables � Summary Statistics: correlation � Visualization: scatterplot Statistics: Unlocking the Power of Data Lock 5
Scatterplot A scatterplot is the graph of the relationship between two quantitative variables. R: plot(study_hours, gpa) Statistics: Unlocking the Power of Data Lock 5
Direction of Association � A positive association means that values of one variable tend to be higher when values of the other variable are higher � A negative association means that values of one variable tend to be lower when values of the other variable are higher � Two variables are not associated if knowing the value of one variable does not give you any information about the value of the other variable Statistics: Unlocking the Power of Data Lock 5
Cars Data Handout � Quantitative Variables: Weight (pounds) City MPG Fuel capacity (gallons) Page number (in Consumer Reports) Time to go ¼ mile (in seconds) Acceleration time from 0 to 60 mph � Relationships Weight vs. City. MPG Weight vs. Fuel. Capacity Page. Num vs. Fuel Capacity Weight vs. Qtr. Mile Acc 060 vs. Qtr. Mile City. MPG vs. Qtr. Mile Statistics: Unlocking the Power of Data Lock 5
Car Associations Statistics: Unlocking the Power of Data Lock 5
Correlation The correlation is a measure of the strength and direction of linear association between two quantitative variables • Sample correlation: r • Population correlation: (“rho”) R: cor(x, y) Statistics: Unlocking the Power of Data Lock 5
Car Correlations (-. 91) (. 89) (-. 45) (. 51) (-. 08) (. 99) What are the properties of correlation? Statistics: Unlocking the Power of Data Lock 5
Correlation 1. -1 ≤ r ≤ 1 2. The sign indicates the direction of association 1. positive association: r > 0 2. negative association: r < 0 3. no linear association: r 0 3. The closer r is to ± 1, the stronger the linear association r has no units and does not depend on the units of measurement 4. 5. The correlation between X and Y is the same as the correlation between Y and X Statistics: Unlocking the Power of Data Lock 5
Correlation Guessing Game http: //istics. net/gett/gcstart. php? group_id=duke Highest scorer in the class by the first exam gets one extra credit point! Statistics: Unlocking the Power of Data Lock 5
Correlation NFL Teams r = 0. 43 Statistics: Unlocking the Power of Data Lock 5
Correlation r = 0. 08 Same plot, but with Dolphins and Raiders (outliers) removed Statistics: Unlocking the Power of Data Lock 5
Human Cannonball Plot Y vs. X X What is the correlation between X and Y? a) r > 0 b) r < 0 c) r = 0 Statistics: Unlocking the Power of Data Y Are X and Y associated? a) Yes b) No Lock 5
Correlation Cautions 1. Correlation can be heavily affected by outliers. Always plot your data! 2. r = 0 means no linear association. The variables could still be otherwise associated. Always plot your data! 3. Correlation does not imply causation! Statistics: Unlocking the Power of Data Lock 5
Summary: Two Quantitative Variables � Summary Statistics: correlation � Visualization: scatterplot Statistics: Unlocking the Power of Data Lock 5
Variable(s) Visualization Summary Statistics Categorical bar chart, pie chart frequency table, relative frequency table, proportion Quantitative dotplot, histogram, boxplot mean, median, max, min, standard deviation, range, IQR, five number summary Categorical vs Categorical side-by-side bar chart, two-way table, segmented bar chart difference in proportions Quantitative vs Categorical side-by-side boxplots statistics by group, difference in means Quantitative vs Quantitative scatterplot correlation Statistics: Unlocking the Power of Data Lock 5
To Do �Read Sections 2. 1, 2. 4, 2. 5 �Do HW 2 (due Wednesday, 1/29) Statistics: Unlocking the Power of Data Lock 5
- Slides: 52