520 likes | 647 Views
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). The Big Picture. Sample. Population. Sampling. Statistical Inference. Descriptive Statistics.
E N D
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)
The Big Picture Sample Population Sampling Statistical Inference Descriptive Statistics
Two Categorical Variables • Look at the relationship between two categorical variables • Relationship status • Gender
Two-Way Table • It doesn’t matter which variable is displayed in the rows and which in the columns Data from Duke students R: table(relationship, gender)
Two-Way Table What proportion of students in this sample are in a relationship? • 42/169 25% • 32/107 30% • 10/62 16% • 32/42 76%
Two-Way Table What proportion of females in this sample are in a relationship? • 42/169 25% • 32/107 30% • 10/62 16% • 32/42 76%
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???
Difference in Proportions • A difference in proportions is a difference in proportions for one categorical variable calculated for different levels of the other categorical variable • Example: proportion of females in a relationship – proportion of males in a relationship
Two-Way Table What proportion of people in a relationship in this sample are female? • 42/169 25% • 32/107 30% • 10/62 16% • 32/42 76%
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%!
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)
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)
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.
Vitamin D Injections • 17,252 • 16,248 • 33,500 • 19,665 • 13,835 • 33,500 • 67,000 • 36,917 • 30,083
Kidney Stones R. Charig, D. R. Webb, S. R. Payne, O. E. Wickham (1986). "Comparison of treatment of renal calculi by open surgery, percutaneousnephrolithotomy, and extracorporeal shockwave lithotripsy". Br Med J (Clin Res Ed)292 (6524): 879–882 • Which treatment is better at removing kidney stones? • Treatment A • Treatment B
Kidney Stones • Which treatment is better at removing small kidney stones? • Treatment A • Treatment B
Kidney Stones • Which treatment is better at removing large kidney stones? • Treatment A • Treatment B
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!?!?
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
Summary: Two Categorical Variables • Summary Statistics • Two-way table • Difference in proportions • Visualization • Side-by-side bar chart • Segmented bar chart
Quantitative and Categorical Relationships • Interested in a quantitative variable broken down by categorical groups
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.
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? • Yes • No Randomized experiment – possible to make conclusions about causality
Side-by-Side Boxplots R: boxplot(InterferonGamma~Drink)
Quantitative Statistics by a Categorical Variable • Any of the statistics we use for a quantitative variable can be looked at separately for each level of a categorical variable Tea: Coffee:
Difference in Means • Often, when comparing a quantitative variable across two categories, and compute the difference in means R: compareMean(InterferonGamma~Drink)
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
Two Quantitative Variables • Summary Statistics: correlation • Visualization: scatterplot
Scatterplot A scatterplot is the graph of the relationship between two quantitative variables. R: plot(study_hours, gpa)
Direction of Association • A positive associationmeans that values of one variable tend to be higher when values of the other variable are higher • A negative associationmeans 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
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. CityMPG • Weight vs. FuelCapacity • PageNum vs. Fuel Capacity • Weight vs. QtrMile • Acc060 vs. QtrMile • CityMPG vs. QtrMile
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)
Car Correlations (-.91) (.89) (-.45) (.51) (.99) (-.08) What are the properties of correlation?
Correlation • -1 ≤ r ≤ 1 • The sign indicates the direction of association • positive association: r > 0 • negative association: r < 0 • no linear association: r 0 • The closer r is to ±1, the stronger the linear association • r has no units and does not depend on the units of measurement • The correlation between X and Y is the same as the correlation between Y and X
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!
Correlation NFL Teams r = 0.43
Correlation r = 0.08 Same plot, but with Dolphins and Raiders (outliers) removed
X Y Human Cannonball Plot Y vs. X • What is the correlation between X and Y? • r > 0 • r < 0 • r = 0 • Are X and Y associated? • Yes • No
Correlation Cautions • Correlation can be heavily affected by outliers. Always plot your data! • r = 0 means no linear association. The variables could still be otherwise associated. Always plot your data! • Correlation does not imply causation!
Summary: Two Quantitative Variables • Summary Statistics: correlation • Visualization: scatterplot