#set document(title: "11.1 Chi-Square Test for Independence", author: "Kathryn Kozak") #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")) == 11.1#h(0.6em)Chi-Square Test for Independence Remember, qualitative data is where you collect data on individuals that are categories or names. Then you would count how many of the individuals had particular qualities. An example is that there is a theory that there is a relationship between breastfeeding and autism. To determine if there is a relationship, researchers could collect the time period that a mother breastfed her child and if that child was diagnosed with autism. Then you would have a table containing this information. Now you want to know if each cell is independent of each other cell. Remember, independence says that one event does not affect another event. Here it means that having autism is independent of being breastfed. What you really want is to see if they are not independent. In other words, does one affect the other? If you were to do a hypothesis test, this is your alternative hypothesis and the null hypothesis is that they are independent. There is a hypothesis test for this and it is called the #strong[Chi-Square Test for Independence]. Technically it should be called the Chi-Square Test for Dependence, but for historical reasons it is known as the test for independence. Just as with previous hypothesis tests, all the steps are the same except for the assumptions and the test statistic. #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[Hypothesis Test for Chi-Square Test] + State the null and alternative hypotheses and the level of significance #linebreak() #math.equation(block: false, alt: "H sub o")[$H_(o)$]: the two variables are independent (this means that the one variable is not affected by the other) #linebreak() #math.equation(block: false, alt: "H sub A")[$H_(A)$]: the two variables are dependent (this means that the one variable is affected by the other) #linebreak() Also, state your #math.equation(block: false, alt: "α")[$α$] level here. + State and check the assumptions for the hypothesis test + A random sample is taken. + Expected frequencies for each cell are greater than or equal to 5 (The expected frequencies, E, will be calculated later, and this assumption means #math.equation(block: false, alt: "E greater than or equal to 5")[$E ≥ 5$]). + Find the test statistic and p-value #linebreak() Finding the test statistic involves several steps. First the data is collected and counted, and then it is organized into a table (in a table each entry is called a cell). These values are known as the observed frequencies, which the symbol for an observed frequency is#emph[O]. Each table is made up of rows and columns. Then each row is totaled to give a row total and each column is totaled to give a column total. #linebreak() The null hypothesis is that the variables are independent. Using the multiplication rule for independent events you can calculate the probability of being one value of the first variable, #emph[A,] and one value of the second variable, #emph[B] (the probability of a particular cell #math.equation(block: false, alt: "P open parenthesis A and B close parenthesis close parenthesis")[$P \( A " and " B \) \)$]. Remember in a hypothesis test, you assume that #math.equation(block: false, alt: "H sub o")[$H_(o)$] is true, the two variables are assumed to be independent. #math.equation(block: true, alt: "P open parenthesis A and B close parenthesis equals P open parenthesis A close parenthesis times P open parenthesis B close parenthesis if A and B a r e i n d e p e n d e n t; equals the fraction number of ways A can happen over total number of individuals times the fraction number of ways B can happen over total number of individuals; equals the fraction row total over n * the fraction column total over n")[$P ( A " and " B ) = P ( A ) · P ( B ) " if " A " and " B a r e i n d e p e n d e n t \ = frac(" number of ways " A " can happen ", " total number of individuals ") · frac(" number of ways " B " can happen ", " total number of individuals ") \ = frac(" row total ", n) * frac(" column total ", n)$] ] Now you want to find out how many individuals you expect to be in a certain cell. To find the expected frequencies, you just need to multiply the probability of that cell times the total number of individuals. Do not round the expected frequencies. Expected frequency #math.equation(block: false, alt: "open parenthesis cell A and B close parenthesis equals E open parenthesis A and B close parenthesis")[$( op("cell") A " and " B ) = E ( A " and " B )$] #math.equation(block: true, alt: "equals n open parenthesis the fraction row total over n times the fraction column total over n close parenthesis; equals the fraction row total -column total over n")[$= n ( frac(" row total ", n) · frac(" column total ", n) ) \ = frac(" row total -column total ", n)$] If the variables are independent the expected frequencies and the observed frequencies should be the same. The test statistic here will involve looking at the difference between the expected frequency and the observed frequency for each cell. Then you want to find the “total difference” of all of these differences. The larger the total, the smaller the chances that you could find that test statistic given that the assumption of independence is true. That means that the assumption of independence is not true. How do you find the test statistic? First find the differences between the observed and expected frequencies. Because some of these differences will be positive and some will be negative, you need to square these differences. These squares could be large just because the frequencies are large, you need to divide by the expected frequencies to scale them. Then finally add up all of these fractional values. This is the test statistic. === Test Statistic: The symbol for Chi-Square is #math.equation(block: false, alt: "χ squared")[$χ^(2)$] #math.equation(block: true, alt: "χ squared equals ∑ the fraction open parenthesis O minus E close parenthesis squared over E")[$χ^(2) = ∑ frac(( O − E )^(2), E)$] where #emph[O] is the observed frequency and #emph[E] is the expected frequency === Distribution of Chi-Square #math.equation(block: false, alt: "χ squared")[$χ^(2)$] has different curves depending on the degrees of freedom. It is skewed to the right for small degrees of freedom and gets more symmetric as the degrees of freedom increases (see #emph[Figure #math.equation(block: false, alt: "1")[$1$]]). Since the test statistic involves squaring the differences, the test statistics are all positive. A chi-squared test for independence is always right tailed. p-value: Using the TI-83/84: #math.equation(block: false, alt: "χ cdf (lower limit, 1 E 99 , d f close parenthesis")[$χ " cdf (lower limit, " 1 E 99 , d f \)$] Using R: #math.equation(block: false, alt: "1 minus pchisq open parenthesis x squared , d f close parenthesis")[$1 − " pchisq " ( x^(2) , d f )$] Where the degrees of freedom is #math.equation(block: false, alt: "d f equals open parenthesis # of rows minus 1 close parenthesis * open parenthesis # of columns minus 1 close parenthesis")[$d f = ( \# " of rows " − 1 ) * ( \# " of columns " − 1 )$] 4. Conclusion This is where you write reject #math.equation(block: false, alt: "H sub o")[$H_(o)$] or fail to reject #math.equation(block: false, alt: "H sub o")[$H_(o)$]. The rule is: if the p-value \< #math.equation(block: false, alt: "α")[$α$], then reject #math.equation(block: false, alt: "H sub o")[$H_(o)$]. If the p-value #math.equation(block: false, alt: "greater than or equal to α")[$≥ α$], then fail to reject #math.equation(block: false, alt: "H sub o")[$H_(o)$]. 5. Interpretation This is where you interpret in real world terms the conclusion to the test. The conclusion for a hypothesis test is that you either have enough evidence to show #math.equation(block: false, alt: "H sub A")[$H_(A)$] is true, or you do not have enough evidence to show #math.equation(block: false, alt: "H sub A")[$H_(A)$] is true. #examplebox("Example 1")[hypothesis test with chi-square test using formula][ Is there a relationship between autism and breastfeeding? To determine if there is, a researcher asked mothers of autistic and non-autistic children to say what time period they breastfed their children. The data is in table \#11.1.1 (Schultz, Klonoff-Cohen, Wingard, Askhoomoff, Macera, Ji & Bacher, 2006). Do the data provide enough evidence to show that that breastfeeding and autism are independent? Test at the1% level. #figure(table( columns: 6, align: left, inset: 6pt, [Autis261m], [Breast Feeding Timelines], [Row Total], [], [], [], [None], [Less than 2 months], [2 to 6 months], [More than 6 months], [], [], [Yes], [241], [198], [164], [215], [818], [No], [20], [25], [27], [44], [116], [Column Total], [261], [223], [191], [259], [934], )) #solutionbox[ 1. State the null and alternative hypotheses and the level of significance #math.equation(block: false, alt: "H sub o")[$H_(o)$]: Breastfeeding and autism are independent #math.equation(block: false, alt: "H sub A")[$H_(A)$]: Breastfeeding and autism are dependent #math.equation(block: false, alt: "α")[$α$] = 0.01 2. State and check the assumptions for the hypothesis test + A random sample of breastfeeding time frames and autism incidence was taken. + Expected frequencies for each cell are greater than or equal to 5 (ie. #math.equation(block: false, alt: "E greater than or equal to 5")[$E ≥ 5$]). See step 3. All expected frequencies are more than 5. 3. Find the test statistic and p-value Test statistic: First find the expected frequencies for each cell #math.equation(block: true, alt: "E open parenthesis Autism and no breastfeeding close parenthesis equals the fraction 818 to the power * 261 over 934 approximately equals 228.585")[$E ( " Autism and no breastfeeding " ) = frac(818^(*) 261, 934) ≈ 228.585$] #math.equation(block: true, alt: "E open parenthesis Autism and less than 2 months close parenthesis equals the fraction 818 to the power * 223 over 934 approximately equals 195.304")[$E ( " Autism and " < 2 " months " ) = frac(818^(*) 223, 934) ≈ 195.304$] #math.equation(block: true, alt: "E open parenthesis Autism and 2 to 6 months close parenthesis equals the fraction 818 to the power * 191 over 934 approximately equals 167.278")[$E ( " Autism and " 2 " to " 6 " months " ) = frac(818^(*) 191, 934) ≈ 167.278$] #math.equation(block: true, alt: "E open parenthesis Autism and more than 6 months close parenthesis equals the fraction 818 * 259 over 934 approximately equals 226.833")[$E ( " Autism and more than " 6 " months " ) = frac(818 * 259, 934) ≈ 226.833$] Others are done similarly. It is easier to do the calculations for the test statistic with a table, the others are in table \#11.1.2 along with the calculation for the test statistic. (Note: the column of #emph[O-E] should add to 0 or close to 0.) #figure(table( columns: 5, align: left, inset: 6pt, table.header([#emph[O]], [#emph[E]], [#emph[O-E]], [#math.equation(block: false, alt: "open parenthesis O minus E close parenthesis squared")[$( O − E )^(2)$]], [#math.equation(block: false, alt: "open parenthesis O minus E close parenthesis squared / E")[$( O − E )^(2) / E$]]), [241], [228.585], [12.415], [154.132225], [0.674288448], [198], [195.304], [2.696], [7.268416], [0.03721591], [164], [167.278], [-3.278], [10.745284], [0.064236086], [215], [226.833], [-11.833], [140.019889], [0.617281828], [20], [32.4154], [-12.4154], [154.1421572], [4.755213792], [25], [27.6959], [-2.6959], [7.26787681], [0.262417066], [27], [23.7216], [3.2784], [10.74790656], [0.453085229], [44], [32.167], [11.833], [140.019889], [4.352904809], [Total], [], [0.0001], [], [11.2166432 = #math.equation(block: false, alt: "χ squared")[$χ^(2)$]], )) The test statistic formula is #math.equation(block: false, alt: "χ squared equals ∑ the fraction open parenthesis O minus E close parenthesis squared over E")[$χ^(2) = ∑ frac(( O − E )^(2), E)$], which is the total of the last column in Example #math.equation(block: false, alt: "2")[$2$]. p-value: #math.equation(block: true, alt: "d f equals open parenthesis 2 minus 1 close parenthesis to the power * open parenthesis 4 minus 1 close parenthesis equals 3")[$d f = ( 2 − 1 )^(*) ( 4 − 1 ) = 3$] Using TI-83/84: #math.equation(block: false, alt: "χ cdf open parenthesis 11.2166432 , 1 E 99 , 3 close parenthesis approximately equals 0.01061")[$χ op("cdf") ( 11.2166432 , 1 E 99 , 3 ) ≈ 0.01061$] Using R: #math.equation(block: false, alt: "1 minus pchisq open parenthesis 11.2166432 , 3 close parenthesis approximately equals 0.01061566")[$1 − "pchisq" ( 11.2166432 , 3 ) ≈ 0.01061566$] pchisq(11.2166432, 3) 4. Conclusion Fail to reject #math.equation(block: false, alt: "H sub o")[$H_(o)$] since the p-value is more than 0.01. 5. Interpretation There is not enough evidence to show that breastfeeding and autism are dependent. This means that you cannot say that the whether a child is breastfed or not will indicate if that the child will be diagnosed with autism. ] ] #examplebox("Example 2")[hypothesis test with chi-square test using technology][ Is there a relationship between autism and breastfeeding? To determine if there is, a researcher asked mothers of autistic and non-autistic children to say what time period they breastfed their children. The data is in Example #math.equation(block: false, alt: "1")[$1$] (Schultz, Klonoff-Cohen, Wingard, Askhoomoff, Macera, Ji & Bacher, 2006). Do the data provide enough evidence to show that that breastfeeding and autism are independent? Test at the1% level. #solutionbox[ 1. State the null and alternative hypotheses and the level of significance #math.equation(block: false, alt: "H sub o")[$H_(o)$]: Breastfeeding and autism are independent #math.equation(block: false, alt: "H sub A")[$H_(A)$]: Breastfeeding and autism are dependent #math.equation(block: false, alt: "α")[$α$] = 0.01 2. State and check the assumptions for the hypothesis test + A random sample of breastfeeding time frames and autism incidence was taken. + Expected frequencies for each cell are greater than or equal to 5 (ie. #math.equation(block: false, alt: "E greater than or equal to 5")[$E ≥ 5$]). See step 3. All expected frequencies are more than 5. 3. Find the test statistic and p-value Test statistic: To use the TI-83/84 calculator to compute the test statistic, you must first put the data into the calculator. However, this process is different than for other hypothesis tests. You need to put the data in as a matrix instead of in the list. Go into the MATRX menu then move over to EDIT and choose 1:\[A\]. This will allow you to type the table into the calculator. #emph[Figure #math.equation(block: false, alt: "2")[$2$]]shows what you will see on your calculator when you choose 1:\[A\] from the EDIT menu. The table has 2 rows and 4 columns (don’t include the row total column and the column total row in your count). You need to tell the calculator that you have a 2 by 4. The 1 X1 (you might have another size in your matrix, but it doesn’t matter because you will change it) on the calculator is the size of the matrix. So type 2 ENTER and 4 ENTER and the calculator will make a matrix of the correct size. See #emph[Figure #math.equation(block: false, alt: "3")[$3$]]. Now type the table in by pressing ENTER after each cell value. #emph[Figure #math.equation(block: false, alt: "4")[$4$]] contains the complete table typed in. Once you have the data in, press QUIT. To run the test on the calculator, go into STAT, then move over to TEST and choose #math.equation(block: false, alt: "χ squared")[$χ^(2)$]-Test from the list. The setup for the test is in #emph[Figure #math.equation(block: false, alt: "5")[$5$]]. Once you press ENTER on Calculate you will see the results in #emph[Figure #math.equation(block: false, alt: "6")[$6$]]. The test statistic is #math.equation(block: false, alt: "χ squared approximately equals 11.2167")[$χ^(2) ≈ 11.2167$] and the p-value is #math.equation(block: false, alt: "p approximately equals 0.01061")[$p ≈ 0.01061$]. Notice that the calculator calculates the expected values for you and places them in matrix B. To eview the expected values, go into MATRX and choose 2:\[B\]. #emph[Figure #math.equation(block: false, alt: "7")[$7$]] shows the output. Press the right arrows to see the entire matrix. To compute the test statistic and p-value with R, #linebreak() row1 = c(data from row 1 separated by commas) #linebreak() row2 = c(data from row 2 separated by commas) #linebreak() keep going until you have all of your rows typed in. #linebreak() data.table = rbind(row1, row2, …) – makes the data into a table. You can call it what ever you want. It does not have to be data.table. #linebreak() data.table – use if you want to look at the table #linebreak() chisq.test(data.table) – calculates the chi-squared test for independence #linebreak() chisq.test(data.table)\$expected – let’s you see the expected values For this example, the commands would be #linebreak() row1 = c(241, 198, 164, 215) #linebreak() row2 = c(20, 25, 27, 44) #linebreak() data.table = rbind(row1, row2) #linebreak() data.table row1 = c(241, 198, 164, 215) row2 = c(20, 25, 27, 44) data.table = rbind(row1, row2) Output: #linebreak() \[,1\] \[,2\] \[,3\] \[,4\] #linebreak() row1 241 198 164 215 #linebreak() row2 20 25 27 44 chisq.test(data.table) chisq.test(data.table) Output: #linebreak() Pearson's Chi-squared test data: data.table #linebreak() X-squared = 11.217, df = 3, p-value = 0.01061 chisq.test(data.table)\$expected Output: \[,1\] \[,2\] \[,3\] \[,4\] #linebreak() row1 228.58458 195.30407 167.27837 226.83298 #linebreak() row2 32.41542 27.69593 23.72163 32.16702 The test statistic is #math.equation(block: false, alt: "χ squared approximately equals 11.217")[$χ^(2) ≈ 11.217$] and the p-value is #math.equation(block: false, alt: "p approximately equals 0.01061")[$p ≈ 0.01061$]. 4. Conclusion Fail to reject #math.equation(block: false, alt: "H sub o")[$H_(o)$] since the p-value is more than 0.01. 5. Interpretation There is not enough evidence to show that breastfeeding and autism are dependent. This means that you cannot say that the whether a child is breastfed or not will indicate if that the child will be diagnosed with autism. ] ] #examplebox("Example 3")[hypothesis test with chi-square test using formula][ The World Health Organization (WHO) keeps track of how many incidents of leprosy there are in the world. Using the WHO regions and the World Banks income groups, one can ask if an income level and a WHO region are dependent on each other in terms of predicting where the disease is. Data on leprosy cases in different countries was collected for the year 2011 and a summary is presented in#emph[Table #math.equation(block: false, alt: "3")[$3$]] ("Leprosy: Number of," 2013). Is there evidence to show that income level and WHO region are independent when dealing with the disease of leprosy? Test at the 5% level. #figure(table( columns: 6, align: left, inset: 6pt, [WHO Region], [World Bank Income Group], [Row Total], [], [], [], [High Income], [Upper Middle Income], [Lower Middle Income], [Low Income], [], [], [Americas], [174], [36028], [615], [0], [36817], [Eastern Mediterranean], [54], [6], [1883], [604], [2547], [Europe], [10], [0], [0], [0], [10], [Western Pacific], [26], [216], [3689], [1155], [5086], [Africa], [0], [39], [1986], [15928], [17953], [South-East Asia], [0], [0], [149896], [10236], [160132], [Column Total], [264], [36289], [158069], [27923], [222545], )) #solutionbox[ 1. State the null and alternative hypotheses and the level of significance #math.equation(block: false, alt: "H sub o")[$H_(o)$]: WHO region and Income Level when dealing with the disease of leprosy are independent #math.equation(block: false, alt: "H sub A")[$H_(A)$]: WHO region and Income Level when dealing with the disease of leprosy are dependent #math.equation(block: false, alt: "α")[$α$] = 0.05 2. State and check the assumptions for the hypothesis test + A random sample of incidence of leprosy was taken from different countries and the income level and WHO region was taken. + Expected frequencies for each cell are greater than or equal to 5 (ie. #math.equation(block: false, alt: "E greater than or equal to 5")[$E ≥ 5$]). See step 3. There are actually 4 expected frequencies that are less than 5, and the results of the test may not be valid. If you look at the expected frequencies you will notice that they are all in Europe. This is because Europe didn’t have many cases in 2011. 3. Find the test statistic and p-value Test statistic: First find the expected frequencies for each cell. #math.equation(block: true, alt: "E open parenthesis Americas and High Income close parenthesis equals the fraction 36817 * 264 over 222545 approximately equals 43.675")[$E ( " Americas and High Income " ) = frac(36817 * 264, 222545) ≈ 43.675$] #math.equation(block: true, alt: "E open parenthesis Americas and Upper Middle Income close parenthesis equals the fraction 36817 * 36289 over 222545 approximately equals 6003.514")[$E ( " Americas and Upper Middle Income " ) = frac(36817 * 36289, 222545) ≈ 6003.514$] #math.equation(block: true, alt: "E open parenthesis Americas and Lower Middle Income) equals the fraction 36817 * 158069 over 222545 approximately equals 26150.335")[$E \( " Americas and Lower Middle Income) " = frac(36817 * 158069, 222545) ≈ 26150.335$] #math.equation(block: true, alt: "E open parenthesis Americas and Lower Income close parenthesis equals the fraction 36817 * 27923 over 222545 approximately equals 4619.475")[$E ( " Americas and Lower Income " ) = frac(36817 * 27923, 222545) ≈ 4619.475$] Others are done similarly. It is easier to do the calculations for the test statistic with a table, and the others are in Example #math.equation(block: false, alt: "4")[$4$] along with the calculation for the test statistic. #figure(table( columns: 5, align: left, inset: 6pt, table.header([#emph[O]], [#emph[E]], [#emph[O-E]], [#math.equation(block: false, alt: "open parenthesis O minus E close parenthesis squared")[$( O − E )^(2)$]], [#math.equation(block: false, alt: "open parenthesis O minus E close parenthesis squared / E")[$( O − E )^(2) / E$]]), [174], [43.675], [130.325], [16984.564], [388.8838719], [54], [3.021], [50.979], [2598.813], [860.1218328], [10], [0.012], [9.988], [99.763], [8409.746711], [26], [6.033], [19.967], [398.665], [66.07628214], [0], [21.297], [-21.297], [453.572], [21.29722977], [0], [189.961], [-189.961], [36085.143], [189.9608978], [36028], [6003.514], [30024.486], [901469735.315], [150157.0038], [6], [415.323], [-409.323], [167545.414], [403.4097962], [0], [1.631], [-1.631], [2.659], [1.6306365], [216], [829.342], [-613.342], [376188.071], [453.5983897], [39], [2927.482], [-2888.482], [8343326.585], [2850.001268], [0], [26111.708], [-26111.708], [681821316.065], [26111.70841], [615], [26150.335], [-25535.335], [652053349.724], [24934.7988], [1883], [1809.080], [73.290], [5464.144], [3.020398811], [0], [7.103], [-7.103], [50.450], [7.1027882], [3689], [3612.478], [76.522], [5855.604], [1.620938405], [1986], [12751.636], [-10765.636], [115898911.071], [9088.944681], [149896], [113738.368], [36157.632], [1307374351.380], [11494.57632], [0], [4619.475], [-4619.475], [21339550.402], [4619.475122], [604], [319.575], [284.425], [80897.421], [253.1404187], [0], [1.255], [-1.255], [1.574], [1.25471253], [1155], [638.147], [516.853], [267137.238], [418.6140882], [15928], [2252.585], [13675.415], [187016964.340], [83023.25138], [10236], [20091.963], [-9855.963], [97140000.472], [4834.769106], [Total], [], [0.000], [], [328594.008 = #math.equation(block: false, alt: "χ squared")[$χ^(2)$]], )) The test statistic formula is #math.equation(block: false, alt: "χ squared equals ∑ the fraction open parenthesis O minus E close parenthesis squared over E")[$χ^(2) = ∑ frac(( O − E )^(2), E)$], which is the total of the last column in Example #math.equation(block: false, alt: "2")[$2$]. p-value: #math.equation(block: true, alt: "d f equals open parenthesis 6 minus 1 close parenthesis * open parenthesis 4 minus 1 close parenthesis equals 15")[$d f = ( 6 − 1 ) * ( 4 − 1 ) = 15$] Using the TI-83/84: #math.equation(block: false, alt: "χ cdf open parenthesis 328594.008 , 1 E 99 , 15 close parenthesis approximately equals 0")[$χ op("cdf") ( 328594.008 , 1 E 99 , 15 ) ≈ 0$] Using R: #math.equation(block: false, alt: "1 minus pchisq open parenthesis 328594.008 , 15 close parenthesis approximately equals 0")[$1 − " pchisq " ( 328594.008 , 15 ) ≈ 0$] pchisq(328594.008, 15) 4. Conclusion Reject #math.equation(block: false, alt: "H sub o")[$H_(o)$] since the p-value is less than 0.05. 5. Interpretation There is enough evidence to show that WHO region and income level are dependent when dealing with the disease of leprosy. WHO can decide how to focus their efforts based on region and income level. Do remember though that the results may not be valid due to the expected frequencies not all be more than 5. ] ] #examplebox("Example 4")[hypothesis test with chi-square test using technology][ The World Health Organization (WHO) keeps track of how many incidents of leprosy there are in the world. Using the WHO regions and the World Banks income groups, one can ask if an income level and a WHO region are dependent on each other in terms of predicting where the disease is. Data on leprosy cases in different countries was collected for the year 2011 and a summary is presented in#emph[Table #math.equation(block: false, alt: "3")[$3$]] ("Leprosy: Number of," 2013). Is there evidence to show that income level and WHO region are independent when dealing with the disease of leprosy? Test at the 5% level. #solutionbox[ 1. State the null and alternative hypotheses and the level of significance #linebreak() #math.equation(block: false, alt: "H sub o")[$H_(o)$]: WHO region and Income Level when dealing with the disease of leprosy are independent #math.equation(block: false, alt: "H sub A")[$H_(A)$]: WHO region and Income Level when dealing with the disease of leprosy are dependent #math.equation(block: false, alt: "α")[$α$] = 0.05 2. State and check the assumptions for the hypothesis test + A random sample of incidence of leprosy was taken from different countries and the income level and WHO region was taken. + Expected frequencies for each cell are greater than or equal to 5 (ie. #math.equation(block: false, alt: "E greater than or equal to 5")[$E ≥ 5$]). See step 3. There are actually 4 expected frequencies that are less than 5, and the results of the test may not be valid. If you look at the expected frequencies you will notice that they are all in Europe. This is because Europe didn’t have many cases in 2011. 3. Find the test statistic and p-value #linebreak() Test statistic: #linebreak() Using the TI-83/84. See Example #math.equation(block: false, alt: "2")[$2$] for the process of doing the test on the calculator. Remember, you need to put the data in as a matrix instead of in the list. #math.equation(block: true, alt: "χ squared approximately equals 328594.0079")[$χ^(2) ≈ 328594.0079$] Press the right arrow to look at the other expected frequencies. p-value: #math.equation(block: true, alt: "p minus value approximately equals 0")[$p − "value" ≈ 0$] Using R: #linebreak() row1=c(174, 36028, 615, 0) #linebreak() row2=c(54, 6, 1883, 604) #linebreak() row3=c(10, 0, 0, 0) #linebreak() row4=c(26, 216, 3689, 1155) #linebreak() row5=c(0, 39, 1986, 15928) #linebreak() row6=c(0, 0, 149896, 10236) #linebreak() chisq.test(data.table) row1=c(174, 36028, 615, 0) row2=c(54, 6, 1883, 604) row3=c(10, 0, 0, 0) row4=c(26, 216, 3689, 1155) row5=c(0, 39, 1986, 15928) row6=c(0, 0, 149896, 10236) Pearson's Chi-squared test data: data.table #linebreak() X-squared = 328590, df = 15, p-value \< 2.2e-16 Warning message: #linebreak() In chisq.test(data.table) : Chi-squared approximation may be incorrect chisq.test(data.table)\$expected #math.equation(block: true, alt: "[ , 1 ] [ , 2 ] [ , 3 ] [ , 4 ]; row1 43.67515783 6003.514404 2.615034 e plus 04 4619.475122; row2 3.02144735 415.323117 1.809080 e plus 03 319.575281; row3 0.01186277 1.630637 7.102788 e plus 00 1.254713; row4 6.03340448 829.341724 3.612478 e plus 03 638.146793; row5 21.29722977 2927.481709 1.275164 e plus 04 2252.585405; row6 189.96089780 26111.708410 1.137384 e plus 05 20091.962686")[$[ , 1 ] [ , 2 ] [ , 3 ] [ , 4 ] \ "row1" 43.67515783 6003.514404 2.615034 e + 04 4619.475122 \ "row2" 3.02144735 415.323117 1.809080 e + 03 319.575281 \ "row3" 0.01186277 1.630637 7.102788 e + 00 1.254713 \ "row4" 6.03340448 829.341724 3.612478 e + 03 638.146793 \ "row5" 21.29722977 2927.481709 1.275164 e + 04 2252.585405 \ "row6" 189.96089780 26111.708410 1.137384 e + 05 20091.962686$] Warning message: #linebreak() In chisq.test(data.table) : Chi-squared approximation may be incorrect #math.equation(block: false, alt: "χ squared equals 328590")[$χ^(2) = 328590$] and p-value = #math.equation(block: false, alt: "2.2 times 10 to the power minus 16")[$2.2 × 10^(− 16)$] 4. Conclusion Reject #math.equation(block: false, alt: "H sub o")[$H_(o)$] since the p-value is less than 0.05. 5. Interpretation There is enough evidence to show that WHO region and income level are dependent when dealing with the disease of leprosy. WHO can decide how to focus their efforts based on region and income level. Do remember though that the results may not be valid due to the expected frequencies not all be more than 5. ] ] === Homework #notebox("Your Turn", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ In each problem show all steps of the hypothesis test. If some of the assumptions are not met, note that the results of the test may not be correct and then continue the process of the hypothesis test. + The number of people who survived the Titanic based on class and sex is in Example #math.equation(block: false, alt: "5")[$5$] ("Encyclopedia Titanica," 2013). Is there enough evidence to show that the class and the sex of a person who survived the Titanic are independent? Test at the 5% level. #figure(table( columns: 4, align: left, inset: 6pt, [Class], [Sex], [Total], [], [Female], [Male], [], [], [1st], [134], [59], [193], [2nd], [94], [25], [119], [3rd], [80], [58], [138], [Total], [308], [142], [450], )) + Researchers watched groups of dolphins off the coast of Ireland in 1998 to determine what activities the dolphins partake in at certain times of the day ("Activities of dolphin," 2013). The numbers in Example #math.equation(block: false, alt: "6")[$6$] represent the number of groups of dolphins that were partaking in an activity at certain times of days. Is there enough evidence to show that the activity and the time period are independent for dolphins? Test at the 1% level. #figure(table( columns: 6, align: left, inset: 6pt, [Activity], [Period], [Row Total], [], [], [], [Morning], [Noon], [Afternoon], [Evening], [], [], [Travel], [6], [6], [14], [13], [39], [Feed], [28], [4], [0], [56], [88], [Social], [38], [5], [9], [10], [62], [Column Total], [72], [15], [23], [79], [189], )) + Is there a relationship between autism and what an infant is fed? To determine if there is, a researcher asked mothers of autistic and non-autistic children to say what they fed their infant. The data is in Example #math.equation(block: false, alt: "7")[$7$] (Schultz, Klonoff-Cohen, Wingard, Askhoomoff, Macera, Ji & Bacher, 2006). Do the data provide enough evidence to show that that what an infant is fed and autism are independent? Test at the 1% level. #figure(table( columns: 5, align: left, inset: 6pt, [Autism], [Feeding], [Row Total], [], [], [Breast feeding], [Formula with DHA/ARA], [Formula without DRA/ARA], [], [], [Yes], [12], [39], [65], [116], [No], [6], [22], [10], [38], [Column Total], [18], [61], [75], [164], )) + A person’s educational attainment and age group was collected by the U.S. Census Bureau in 1984 to see if age group and educational attainment are related. The counts in thousands are in Example #math.equation(block: false, alt: "8")[$8$] ("Education by age," 2013). Do the data show that educational attainment and age are independent? Test at the 5% level. #figure(table( columns: 7, align: left, inset: 6pt, [Education], [Age Group], [Row Total], [], [], [], [], [25-34], [35-44], [45-54], [55-64], [\>64], [], [], [Did not complete HS], [5416], [5030], [5777], [7606], [13746], [37575], [Completed HS], [16431], [1855], [9435], [8795], [7558], [44074], [College 1-3 years], [8555], [5576], [3124], [2524], [2503], [22282], [College 4 or more years], [9771], [7596], [3904], [3109], [2483], [26863], [Column Total], [40173], [20057], [22240], [22034], [26290], [130794], )) + Students at multiple grade schools were asked what their personal goal (get good grades, be popular, be good at sports) was and how important good grades were to them (1 very important and 4 least important). The data is in Example #math.equation(block: false, alt: "9")[$9$] ("Popular kids datafile," 2013). Do the data provide enough evidence to show that goal attainment and importance of grades are independent? Test at the 5% level. #figure(table( columns: 6, align: left, inset: 6pt, [Goal], [Grades Importance Rating], [Row Total], [], [], [], [1], [2], [3], [4], [], [], [Grades], [70], [66], [55], [56], [247], [Popular], [14], [33], [45], [49], [141], [Sports], [10], [24], [33], [23], [90], [Column Total], [94], [123], [133], [128], [478], )) + Students at multiple grade schools were asked what their personal goal (get good grades, be popular, be good at sports) was and how important being good at sports were to them (1 very important and 4 least important). The data is in Example #math.equation(block: false, alt: "10")[$10$] ("Popular kids datafile," 2013). Do the data provide enough evidence to show that goal attainment and importance of sports are independent? Test at the 5% level. #figure(table( columns: 6, align: left, inset: 6pt, [Goal], [Sports Importance Rating], [Row Total], [], [], [], [1], [2], [3], [4], [], [], [Grades], [83], [81], [55], [28], [247], [Popular], [32], [49], [43], [17], [141], [Sports], [50], [24], [14], [2], [90], [Column Total], [165], [154], [112], [47], [478], )) + Students at multiple grade schools were asked what their personal goal (get good grades, be popular, be good at sports) was and how important having good looks were to them (1 very important and 4 least important). The data is in Table 11 ("Popular kids datafile," 2013). Do the data provide enough evidence to show that goal attainment and importance of looks are independent? Test at the 5% level. #figure(table( columns: 6, align: left, inset: 6pt, [Goal], [Looks Importance Rating], [Row Total], [], [], [], [1], [2], [3], [4], [], [], [Grades], [80], [66], [66], [35], [247], [Popular], [81], [30], [18], [12], [141], [Sports], [24], [30], [17], [19], [90], [Column Total], [185], [126], [101], [66], [478], )) + Students at multiple grade schools were asked what their personal goal (get good grades, be popular, be good at sports) was and how important having money were to them (1 very important and 4 least important). The data is in Table 12 ("Popular kids datafile," 2013). Do the data provide enough evidence to show that goal attainment and importance of money are independent? Test at the 5% level. #figure(table( columns: 6, align: left, inset: 6pt, [Goal], [Money Importance Rating], [Row Total], [], [], [], [1], [2], [3], [4], [], [], [Grades], [14], [34], [71], [128], [247], [Popular], [14], [29], [35], [63], [141], [Sports], [6], [12], [26], [46], [90], [Column Total], [34], [75], [132], [237], [478], )) Answer For all hypothesis tests, just the conclusion is given. See solutions for the entire answer. 1. Reject Ho 3. Reject Ho 5. Reject Ho 7. Reject Ho ]