#set document(title: "12.3 Hypothesis Test for a Correlation", author: "Rachel Webb") #set page(width: 8.5in, height: auto, margin: 1in) #import "@preview/cetz:0.5.2" #set text(font: ("STIX Two Text", "Libertinus Serif", "New Computer Modern"), size: 10.5pt, lang: "en") #show math.equation: set text(font: ("STIX Two Math", "New Computer Modern Math")) #set par(justify: true, leading: 0.62em, spacing: 0.9em) #set enum(spacing: 1.1em) // room between list items so tall inline fractions don't collide #set list(spacing: 1.1em) #set table(stroke: 0.5pt + rgb("#c7ccd3")) #let BLUE = rgb("#183B6F") // brand navy — section bars + example/solution labels (white on navy 11.09:1) #let ORANGE = rgb("#A94509") // brand primary-700 — AA-safe deep orange for TEXT (5.93:1 on white; raw brand #F37021 is 2.94:1 and must never carry text) #let RED = rgb("#DC2626") // brand error-600 #let GREEN = rgb("#059669") // brand success-600 (decoration only; small green text uses green-text #007942) #show heading.where(level: 1): it => block(width: 100%, above: 0pt, below: 16pt, fill: gradient.linear(BLUE, rgb("#2C5AA0")), inset: (x: 14pt, y: 12pt), radius: 3pt, text(fill: white, weight: "bold", size: 19pt, it.body)) #show heading.where(level: 2): it => block(width: 100%, above: 18pt, below: 10pt, fill: BLUE, inset: (x: 10pt, y: 6pt), radius: 2pt, text(fill: white, weight: "bold", size: 12pt, it.body)) #show heading.where(level: 3): it => text(fill: ORANGE, weight: "bold", size: 12.5pt, it.body) #show heading.where(level: 4): it => text(fill: BLUE, weight: "bold", size: 10.5pt, it.body) #let examplebox(label, title, body) = block(width: 100%, breakable: true, fill: rgb("#EFF1F5"), stroke: 0.5pt + rgb("#CFDDF0"), radius: 4pt, inset: 10pt, above: 12pt, below: 12pt)[ #block(below: 6pt)[#box(fill: BLUE, inset: (x: 6pt, y: 2pt), radius: 2pt, text(fill: white, weight: "bold", size: 8.5pt, label)) #h(0.4em) #strong[#title]] #body] // rail = decorative left rule (raw brand token); labelcolor = AA-safe label text shade #let notebox(label, rail, labelcolor, tint, body) = block(width: 100%, breakable: true, fill: tint, stroke: (left: 3pt + rail), inset: (left: 10pt, rest: 8pt), radius: (right: 4pt), above: 11pt, below: 11pt)[ #text(fill: labelcolor, weight: "bold", size: 7.5pt, tracking: 0.5pt)[#upper(label)] #linebreak() #body] #let solutionbox(body) = block(above: 4pt, below: 8pt)[ #text(fill: BLUE, weight: "bold", size: 8.5pt)[Solution] #linebreak() #body] #let figph(msg) = block(width: 100%, height: 60pt, fill: rgb("#f6f7f9"), stroke: (paint: rgb("#c7ccd3"), dash: "dashed"), radius: 4pt, inset: 10pt)[ #align(center + horizon, text(fill: rgb("#889"), style: "italic", size: 9pt, msg))] // Standardize inlined figure sizes: measure the natural CeTZ canvas, then scale to a // consistent envelope (aspect-aware; see build_typst.py FIG_* constants). Unlike the // print preamble, dimensions are FLOORED: in an editor a user can trim a figure to a // degenerate 1-D shape (a bare line), and w/h or tw/w would then divide by zero. #let _STD_W = 3.5 #let _WIDE_W = 5.6 #let _MAX_H = 3.4 #let _ASPECT_WIDE = 2.2 #let _UPSCALE_MAX = 1.15 #let stdfig(body) = context { let m = measure(body) let w = calc.max(m.width / 1in, 0.01) let h = calc.max(m.height / 1in, 0.01) let tw = if w / h > _ASPECT_WIDE { _WIDE_W } else { _STD_W } let s = calc.min(tw / w, _MAX_H / h, _UPSCALE_MAX) align(center, box(scale(x: s * 100%, y: s * 100%, reflow: true, body))) } #show figure: set block(breakable: false) #set figure(gap: 8pt) #show figure.caption: set text(size: 8.5pt, fill: rgb("#555")) == 12.3#h(0.6em)Hypothesis Test for a Correlation One should perform a hypothesis test to determine if there is a statistically significant correlation between the independent and the dependent variables. The population correlation coefficient #math.equation(block: false, alt: "ρ")[$ρ$] (this is the Greek letter rho, which sounds like “row” and is not a #math.equation(block: false, alt: "p")[$p$]) is the correlation among all possible pairs of data values #math.equation(block: false, alt: "open parenthesis x , y close parenthesis")[$( x , y )$] taken from a population. We will only be using the two-tailed test for a population correlation coefficient #math.equation(block: false, alt: "ρ")[$ρ$]. The hypotheses are: #math.equation(block: true, alt: "H sub 0 : ρ equals 0")[$H_(0) : ρ = 0$] #linebreak() #math.equation(block: true, alt: "H sub 1 : ρ not equal to 0")[$H_(1) : ρ ≠ 0$] The null-hypothesis of a two-tailed test states that there is no correlation (there is not a linear relation) between #math.equation(block: false, alt: "x")[$x$] and #math.equation(block: false, alt: "y")[$y$]. The alternative-hypothesis states that there is a significant correlation (there is a linear relation) between #math.equation(block: false, alt: "x")[$x$] and #math.equation(block: false, alt: "y")[$y$]. The t-test is a statistical test for the correlation coefficient. It can be used when #math.equation(block: false, alt: "x")[$x$] and #math.equation(block: false, alt: "y")[$y$] are linearly related, the variables are random variables, and when the population of the variable #math.equation(block: false, alt: "y")[$y$] is normally distributed. The formula for the t-test statistic is #math.equation(block: false, alt: "t equals r the square root of open parenthesis the fraction n minus 2 over 1 minus r squared close parenthesis")[$t = r sqrt(( frac(n − 2, 1 − r^(2)) ))$]. Use the t-distribution with degrees of freedom equal to #math.equation(block: false, alt: "d f equals n minus 2")[$d f = n − 2$]. Note the #math.equation(block: false, alt: "d f equals n minus 2")[$d f = n − 2$] since we have two variables, #math.equation(block: false, alt: "x")[$x$] and #math.equation(block: false, alt: "y")[$y$]. #examplebox("Example 1")[][ Test to see if the correlation for hours studied on the exam and grade on the exam is statistically significant. Use #math.equation(block: false, alt: "α")[$α$] = 0.05. #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[The correlation t-test in three reads] The first link is the book's invT step: left-tail area 0.975 with df = 13 gives +2.160, so the rejection region is beyond plus or minus 2.160. The second shades the tail above the test statistic t = 5.271 - double that area for the two-tailed p-value 0.000151. The third preloads the data in the Regression panel, which reports the same t and p as LinRegTTest. - invT(0.975, df 13) = 2.160 - P(t \> 5.271) = 0.0000756, doubled = 0.000151 - LinRegTTest readout: t = 5.271, p = 0.000151 ] Hours Studied for Exam 20 16 20 18 17 16 15 17 15 16 15 17 16 17 14 Grade on Exam 89 72 93 84 81 75 70 82 69 83 80 83 81 84 76 #solutionbox[ The hypotheses are: #math.equation(block: true, alt: "H sub 0 : ρ equals 0")[$H_(0) : ρ = 0$] #linebreak() #math.equation(block: true, alt: "H sub 1 : ρ not equal to 0")[$H_(1) : ρ ≠ 0$] Find the critical value using #math.equation(block: false, alt: "d f equals n minus 2 equals 13")[$d f = n − 2 = 13$] for a two-tailed test #math.equation(block: false, alt: "α equals 0.05")[$α = 0.05$] inverse t-function to get the critical values #math.equation(block: false, alt: "± 2.160")[$± 2.160$]. Draw the sampling distribution and label the critical values as shown in Figure 12-5. #figure(figph[Screenshot of using the inverse t-function on a calculator with alpha = 0.05 and df=13 to find the critical values. Graph of the sampling distribution with the critical values of positive and negative 2.160 labeled.], alt: "Screenshot of using the inverse t-function on a calculator with alpha = 0.05 and df=13 to find the critical values. Graph of the sampling distribution with the critical values of positive and negative 2.160 labeled.", caption: [Figure 12-5: Sampling distribution of t-function with critical values labeled.]) Next, find the test statistic #math.equation(block: false, alt: "t equals r the square root of open parenthesis the fraction n minus 2 over 1 minus r squared close parenthesis equals 0.8254 the square root of open parenthesis the fraction 13 over 1 minus 0.8254 squared close parenthesis equals 5.271")[$t = r sqrt(( frac(n − 2, 1 − r^(2)) )) = 0.8254 sqrt(( frac(13, 1 − 0.8254^(2)) )) = 5.271$], which is greater than 2.160 and in the rejection region. Summary: At the 5% significance level, there is enough evidence to support the claim that there is a statistically significant linear relationship (correlation) between the number of hours studied for an exam and exam scores. The p-value method could also be used to find the same decision. We will use technology shortcuts for the p-value method. The p-value = #math.equation(block: false, alt: "2 times P open parenthesis t greater than or equal to 5.271 vertical bar H sub 0 is true close parenthesis equals 0.000151")[$2 · "P" ( t ≥ 5.271 | H_(0) " is true" ) = 0.000151$], which is less than #math.equation(block: false, alt: "α")[$α$] = 0.05; therefore we reject #math.equation(block: false, alt: "H sub 0")[$H_(0)$]. Alternatively, we could test to see if the slope was equal to zero. If the slope is zero then the correlation will also be zero. The setup of a test is a little different, but we get the same results. Most software packages report the test statistic and p-value for a slope. This test is introduced in the next section. #strong[TI-84:] Enter the data in L#sub[1] and L#sub[2]. Press the \[STAT\] key, arrow over to the \[TESTS\] menu, arrow down to the option \[LinRegTTest\] and press the \[ENTER\] key. The default is Xlist: L#sub[1], Ylist: L#sub[1], Freq:1, #math.equation(block: false, alt: "β")[$β$] and #math.equation(block: false, alt: "ρ : not equal to 0")[$ρ : ≠ 0$]. Arrow down to Calculate and press the \[ENTER\] key. The calculator returns the t-test statistic, p-value and the correlation coefficient = #math.equation(block: false, alt: "r")[$r$]. Note the p-value = 0.0001513, is less than #math.equation(block: false, alt: "α")[$α$] = 0.05; therefore reject #math.equation(block: false, alt: "H sub 0")[$H_(0)$], as there is a significant correlation. #figure(figph[LinRegTTest results.], alt: "LinRegTTest results.", caption: none) #strong[TI-89:] Enter the data in List1 and List2. In the Stats/List Editor select F6 for the Tests menu. Use cursor keys to select A:LinRegTTest and press \[Enter\]. In the “X List” space type in the name of your list with the #math.equation(block: false, alt: "x")[$x$] variable without space, for our example “list1” or use \[2nd\] \[Var-Link\] and highlight list1. In the “Y List” space type in the name of your list with the #math.equation(block: false, alt: "y")[$y$] variable without space, for our example “list2” or use \[2nd\] \[Var-Link\] and highlight list2. Under the “Alternate Hyp” menu select the #math.equation(block: false, alt: "β")[$β$] and #math.equation(block: false, alt: "ρ : not equal to 0")[$ρ : ≠ 0$] option, which is the same as the question’s alternative hypothesis statement, then press the \[ENTER\] key, arrow down to \[Calculate\] and press the \[ENTER\] key. The calculator returns the t-test statistic, p-value, and the correlation = #math.equation(block: false, alt: "r")[$r$]. #figure(figph[Selecting the LinRegTTest option from the F6 Tests menu. Selecting the Alternative Hypothesis option where beta and do not equal to 0. Shows the final results.], alt: "Selecting the LinRegTTest option from the F6 Tests menu. Selecting the Alternative Hypothesis option where beta and do not equal to 0. Shows the final results.", caption: none) #strong[Excel:] Type the data into two columns in Excel. Select the Data tab, then Data Analysis, then choose Regression and select OK. #figure(figph[Excel spreadsheet with data for hours studied in one column and data for exam score in another column, including data labels. Both columns are selected and the Regression option in the Data Analysis pop-up window is selected.], alt: "Excel spreadsheet with data for hours studied in one column and data for exam score in another column, including data labels. Both columns are selected and the Regression option in the Data Analysis pop-up window is selected.", caption: none) Be careful here. The second column is the #math.equation(block: false, alt: "y")[$y$] range, and the first column is the #math.equation(block: false, alt: "x")[$x$] range. Only check the Labels box if you highlight the labels in the input range. The output range is one cell reference where you want the output to start, and then select OK. #figure(figph[Excel Regression pop-up window, with the "Labels" option selected and cell D1 selected for the Output Range option.], alt: "Excel Regression pop-up window, with the \"Labels\" option selected and cell D1 selected for the Output Range option.", caption: none) Figure 12-6 shows the regression output. #figure(figph[Excel-generated regression output, including regression statistics table, ANOVA table, and a table of coefficients, standard error, t-test statistic and p-value for the intercept and the hours studied.], alt: "Excel-generated regression output, including regression statistics table, ANOVA table, and a table of coefficients, standard error, t-test statistic and p-value for the intercept and the hours studied.", caption: [Figure 12-6: Excel-generated regression output.]) When you reject #math.equation(block: false, alt: "H sub 0")[$H_(0)$], the slope is significantly different from zero. This means there is a significant relationship (correlation) between #math.equation(block: false, alt: "x")[$x$] and #math.equation(block: false, alt: "y")[$y$], and you can then find a regression line to use for prediction which we explore in the next section, called Simple Linear Regression. ] ] === Correlation is Not Causation Just because two variables are significantly correlated does not imply a cause and effect relationship. There are several relationships that are possible. It could be that #math.equation(block: false, alt: "x")[$x$] causes #math.equation(block: false, alt: "y")[$y$] to change. You can actually swap #math.equation(block: false, alt: "x")[$x$] and #math.equation(block: false, alt: "y")[$y$] in the fields and get the same #math.equation(block: false, alt: "r")[$r$] value and #math.equation(block: false, alt: "y")[$y$] could be causing #math.equation(block: false, alt: "x")[$x$] to change. There could be other variables that are affecting the two variables of interest. For instance, you can usually show a high correlation between ice cream sales and home burglaries. Selling more ice cream does not “cause” burglars to rob homes. More home burglaries do not cause more ice cream sales. We would probably notice that the temperature outside may be causing both ice cream sales to increase and more people to leave their windows open. This third variable is called a #strong[lurking variable] and causes both #math.equation(block: false, alt: "x")[$x$] and #math.equation(block: false, alt: "y")[$y$] to change, making it look like the relationship is just between #math.equation(block: false, alt: "x")[$x$] and #math.equation(block: false, alt: "y")[$y$]. There are also highly correlated variables that seemingly have nothing to do with one another. These seemingly unrelated variables are called spurious correlations. The following website has some examples of spurious correlations (a slight caution that the author has some gloomy examples): #link("http://www.tylervigen.com/spurious-correlations")[http://www.tylervigen.com/spurious-correlations]. Figure 12-7 is one of their examples: #figure(figph[Chart from tylervigen.com, showing correlation from 2000 to 2009 between per-capita mozzerella cheese consumption number of civil engineering doctorates awarded.], alt: "Chart from tylervigen.com, showing correlation from 2000 to 2009 between per-capita mozzerella cheese consumption number of civil engineering doctorates awarded.", caption: [Figure 12-7: Example of spurious correlations. (6/25/2020) Retrieved from #link("http://tylervigen.com/view_correlation?id=28726")[http://tylervigen.com/view\_correlation?id=28726].]) If we were to take out each pair of measurements by year from the time-series plot in Figure 12-7, we would get the following data. #figure(table( columns: 3, align: left, inset: 6pt, table.header([Year], [Engineering Doctorates], [Mozzarella Cheese Consumption]), [2000], [480], [9.3], [2001], [501], [9.7], [2002], [540], [9.7], [2003], [552], [9.7], [2004], [547], [9.9], [2005], [622], [10.2], [2006], [655], [10.5], [2007], [701], [11], [2008], [712], [10.6], [2009], [708], [10.6], )) Using Excel to find a scatterplot and compute a correlation coefficient, we get the scatterplot shown in Figure 12-8 and a correlation of #math.equation(block: false, alt: "r equals 0.9586")[$r = 0.9586$]. #figure(figph[Excel-generated scatterplot of the spurious correlation example, with mozzarella cheese consumption on the x-axis and engineering doctorates on the y-axis.], alt: "Excel-generated scatterplot of the spurious correlation example, with mozzarella cheese consumption on the x-axis and engineering doctorates on the y-axis.", caption: [Figure 12-8: Scatterplot for spurious correlation example.]) With #math.equation(block: false, alt: "r equals 0.9586")[$r = 0.9586$], there is strong correlation between the number of engineering doctorate degrees earned and mozzarella cheese consumption over time, but earning your doctorate degree does not cause one to go eat more cheese. Nor does eating more cheese cause people to earn a doctorate degree. Most likely these items are both increasing over time and therefore show a spurious correlation to one another. When two variables are correlated, it does not imply that one variable causes the other variable to change. “Correlation is causation” is an incorrect assumption that because something correlates, there is a causal relationship. Causality is the area of statistics that is most commonly misused, and misinterpreted, by people. Media, advertising, politicians and lobby groups often leap upon a perceived correlation and use it to “prove” their own agenda. They fail to understand that, just because results show a correlation, there is no proof of an underlying causality. Many people assume that because a poll, or a statistic, contains many numbers, it must be scientific, and therefore correct. The human brain is built to try and subconsciously establish links between many pieces of information at once. The brain often tries to construct patterns from randomness, and may jump to conclusions, and assume that a cause and effect relationship exists. Relationships may be accidental or due to other unmeasured variables. Overcoming this tendency to jump to a cause and effect relationship is part of academic training for students and in most fields, from statistics to the arts. === Summary When looking at correlations, start with a scatterplot to see if there is a linear relationship prior to finding a correlation coefficient. If there is a linear relationship in the scatterplot, then we can find the correlation coefficient to tell the strength and direction of the relationship. Clusters of dots forming a linear uphill pattern from left to right will have a positive correlation. The closer the dots in the scatterplot are to a straight line, the closer #math.equation(block: false, alt: "r")[$r$] will be to #math.equation(block: false, alt: "1")[$1$]. If the cluster of dots in the scatterplots go downhill from left to right in linear pattern, then there is a negative relationship. The closer those dots in the scatterplot are to a straight line going downhill, the closer #math.equation(block: false, alt: "r")[$r$] will be to #math.equation(block: false, alt: "minus 1")[$− 1$]. Use a t-test to see if the correlation is statistically significant. As sample sizes get larger, smaller values of #math.equation(block: false, alt: "r")[$r$] become statistically significant. Be careful with outliers, which can heavily influence correlations. Most importantly, correlation is not causation. When #math.equation(block: false, alt: "x")[$x$] and #math.equation(block: false, alt: "y")[$y$] are significantly correlated, this does not mean that #math.equation(block: false, alt: "x")[$x$] causes #math.equation(block: false, alt: "y")[$y$] to change.