diff --git a/_freeze/20-inference-two-means/execute-results/html.json b/_freeze/20-inference-two-means/execute-results/html.json index d6c646e3..76c9b962 100644 --- a/_freeze/20-inference-two-means/execute-results/html.json +++ b/_freeze/20-inference-two-means/execute-results/html.json @@ -2,7 +2,7 @@ "hash": "fd62e15516b9d856f78af5773a3e2839", "result": { "engine": "knitr", - "markdown": "# Inference for comparing two independent means {#sec-inference-two-means}\n\n\n\n\n\n::: {.chapterintro data-latex=\"\"}\nWe now extend the methods from [Chapter -@sec-inference-one-mean] to apply confidence intervals and hypothesis tests to differences in population means that come from two groups, Group 1 and Group 2: $\\mu_1 - \\mu_2.$\n\nIn our investigations, we'll identify a reasonable point estimate of $\\mu_1 - \\mu_2$ based on the sample, and you may have already guessed its form: $\\bar{x}_1 - \\bar{x}_2.$ \\index{point estimate!difference of means} Then we'll look at the inferential analysis in three different ways: using a randomization test, applying bootstrapping for interval estimates, and, if we verify that the point estimate can be modeled using a normal distribution, we compute the estimate's standard error and apply the mathematical framework.\n:::\n\n\n\n\n\nIn this section we consider a difference in two population means, $\\mu_1 - \\mu_2,$ under the condition that the data are not paired.\nJust as with a single sample, we identify conditions to ensure we can use the $t$-distribution with a point estimate of the difference, $\\bar{x}_1 - \\bar{x}_2,$ and a new standard error formula.\n\nThe details for working through inferential problems in the two independent means setting are strikingly similar to those applied to the two independent proportions setting.\nWe first cover a randomization test where the observations are shuffled under the assumption that the null hypothesis is true.\nThen we bootstrap the data (with no imposed null hypothesis) to create a confidence interval for the true difference in population means, $\\mu_1 - \\mu_2.$ The mathematical model, here the $t$-distribution, is able to describe both the randomization test and the bootstrapping as long as the conditions are met.\n\nThe inferential tools are applied to three different data contexts: determining whether stem cells can improve heart function, exploring the relationship between pregnant women's smoking habits and birth weights of newborns, and exploring whether there is convincing evidence that one variation of an exam is harder than another variation.\nThis section is motivated by questions like \"Is there convincing evidence that newborns from mothers who smoke have a different average birth weight than newborns from mothers who do not smoke?\"\n\n## Randomization test for the difference in means {#sec-rand2mean}\n\nAn instructor decided to run two slight variations of the same exam.\nPrior to passing out the exams, they shuffled the exams together to ensure each student received a random version.\nAnticipating complaints from students who took Version B, they would like to evaluate whether the difference observed in the groups is so large that it provides convincing evidence that Version B was more difficult (on average) than Version A.\n\n::: {.data data-latex=\"\"}\nThe [`classdata`](http://openintrostat.github.io/openintro/reference/classdata.html) data can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.\n:::\n\n### Observed data\n\nSummary statistics for how students performed on these two exams are shown in @tbl-summaryStatsForTwoVersionsOfExams and plotted in @fig-boxplotTwoVersionsOfExams.\n\n\n::: {#tbl-summaryStatsForTwoVersionsOfExams .cell tbl-cap='Summary statistics of scores for each exam version.'}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n
Group n Mean SD Min Max
A 58 75.1 13.9 44 100
B 55 72.0 13.8 38 100
\n\n`````\n:::\n:::\n\n::: {.cell}\n::: {.cell-output-display}\n![Exam scores for students given one of two different exams.](20-inference-two-means_files/figure-html/fig-boxplotTwoVersionsOfExams-1.png){#fig-boxplotTwoVersionsOfExams fig-alt='Boxplot of exam score broken down by version of exam.' width=90%}\n:::\n:::\n\n\n::: {.guidedpractice data-latex=\"\"}\nConstruct hypotheses to evaluate whether the observed difference in sample means, $\\bar{x}_A - \\bar{x}_B=3.1,$ is likely to have happened due to chance, if the null hypothesis is true.\nWe will later evaluate these hypotheses using $\\alpha = 0.01.$[^20-inference-two-means-1]\n:::\n\n[^20-inference-two-means-1]: $H_0:$ the exams are equally difficult, on average.\n $\\mu_A - \\mu_B = 0.$ $H_A:$ one exam was more difficult than the other, on average.\n $\\mu_A - \\mu_B \\neq 0.$\n\n::: {.guidedpractice data-latex=\"\"}\nBefore moving on to evaluate the hypotheses in the previous Guided Practice, let's think carefully about the dataset.\nAre the observations across the two groups independent?\nAre there any concerns about outliers?[^20-inference-two-means-2]\n:::\n\n[^20-inference-two-means-2]: Since the exams were shuffled, the \"treatment\" in this case was randomly assigned, so independence within and between groups is satisfied.\n The summary statistics suggest the data are roughly symmetric about the mean, and the min/max values do not suggest any outliers of concern.\n\n### Variability of the statistic\n\nIn @sec-foundations-randomization, the variability of the statistic (previously: $\\hat{p}_1 - \\hat{p}_2)$ was visualized after shuffling the observations across the two treatment groups many times.\nThe shuffling process implements the null hypothesis model (that there is no effect of the treatment).\nIn the exam example, the null hypothesis is that exam A and exam B are equally difficult, so the average scores across the two tests should be the same.\nIf the exams were equally difficult, *due to natural variability*, we would sometimes expect students to do slightly better on exam A $(\\bar{x}_A > \\bar{x}_B)$ and sometimes expect students to do slightly better on exam B $(\\bar{x}_B > \\bar{x}_A).$ The question at hand is: does $\\bar{x}_A - \\bar{x}_B=3.1$ indicate that exam A is easier than exam B.\n\n@fig-rand2means shows the process of randomizing the exam to the observed exam scores.\nIf the null hypothesis is true, then the score on each exam should represent the true student ability on that material.\nIt shouldn't matter whether they were given exam A or exam B.\nBy reallocating which student got which exam, we are able to understand how the difference in average exam scores changes due only to natural variability.\nThere is only one iteration of the randomization process in @fig-rand2means, leading to one simulated difference in average scores.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![The version of the test (A or B) is randomly allocated to the test scores,\nunder the null assumption that the tests are equally difficult.\n](images/rand2means.png){#fig-rand2means fig-alt='Four panels representing four different orientations of a toy dataset of\n9 exam scores. The first panel provides the observed data; 4 of the exams were\nversion A and the average score was 77.25; 5 of the exams were version B and the\naverage score was 75.8, a difference of 1.45. The second panel shows the shuffled\nreassignment of the exam versions (4 of the scores are randomly reassigned to A,\n5 of the scores are randomly reassigned to B). The third panel shows which score\nis connected with which new reassigned version of the exam. And the fourth panel\nsorts the exams so that version A exams are together and version B exams are\ntogether. In the randomly reassigned versions, the average score for\nversion A is 74.25 and the average score for version B is 78.2, a difference of -3.95.' width=75%}\n:::\n:::\n\n\nBuilding on @fig-rand2means, @fig-randexams shows the values of the simulated statistics $\\bar{x}_{1, sim} - \\bar{x}_{2, sim}$ over 1,000 random simulations.\nWe see that, just by chance, the difference in scores can range anywhere from -10 points to +10 points.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Histogram of differences in means, calculated from 1,000 different randomizations\nof the exam types.\n](20-inference-two-means_files/figure-html/fig-randexams-1.png){#fig-randexams fig-alt='Histogram of differences in means, calculated from 1,000 different randomizations\nof the exam types.' width=90%}\n:::\n:::\n\n\n### Observed statistic vs. null statistics\n\nThe goal of the randomization test is to assess the observed data, here the statistic of interest is $\\bar{x}_A - \\bar{x}_B=3.1.$ The randomization distribution allows us to identify whether a difference of 3.1 points is more than one would expect by natural variability of the scores if the two tests were equally difficult.\nBy plotting the value of 3.1 on @fig-randexamspval, we can measure how different or similar 3.1 is to the randomized differences which were generated under the null hypothesis.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Histogram of differences in means, calculated from 1,000 different randomizations\nof the exam types. The observed difference of 3.1 points is plotted as a vertical\nline, and the area more extreme than 3.1 is shaded to represent the p-value.\n](20-inference-two-means_files/figure-html/fig-randexamspval-1.png){#fig-randexamspval fig-alt='Histogram of differences in means, calculated from 1,000 different randomizations\nof the exam types. The observed difference of 3.1 points is plotted as a vertical\nline, and the area more extreme than 3.1 is shaded to represent the p-value.' width=90%}\n:::\n:::\n\n\n::: {.workedexample data-latex=\"\"}\nApproximate the p-value depicted in @fig-randexamspval, and provide a conclusion in the context of the case study.\n\n------------------------------------------------------------------------\n\nUsing software, we can find the number of shuffled differences in means that are less than the observed difference (of 3.14) is 900 (out of 1,000 randomizations).\nSo 10% of the simulations are larger than the observed difference.\nTo get the p-value, we double the proportion of randomized differences which are larger than the observed difference, p-value = 0.2.\n\nPreviously, we specified that we would use $\\alpha = 0.01.$ Since the p-value is larger than $\\alpha,$ we do not reject the null hypothesis.\nThat is, the data do not convincingly show that one exam version is more difficult than the other, and the teacher should not be convinced that they should add points to the Version B exam scores.\n:::\n\n\n::: {.cell}\n\n:::\n\n\nThe large p-value and consistency of $\\bar{x}_A - \\bar{x}_B=3.1$ with the randomized differences leads us to *not reject the null hypothesis*.\nSaid differently, there is no evidence to think that one of the tests is easier than the other.\nOne might be inclined to conclude that the tests have the same level of difficulty, but that conclusion would be wrong.\nThe hypothesis testing framework is set up only to reject a null claim, it is not set up to validate a null claim.\nAs we concluded, the data are consistent with exams A and B being equally difficult, but the data are also consistent with exam A being 3.1 points \"easier\" than exam B.\nThe data are not able to adjudicate on whether the exams are equally hard or whether one of them is slightly easier.\nIndeed, conclusions where the null hypothesis is not rejected often seem unsatisfactory.\nHowever, in this case, the teacher and class are probably all relieved that there is no evidence to demonstrate that one of the exams is more difficult than the other.\n\n## Bootstrap confidence interval for the difference in means\n\nBefore providing a full example working through a bootstrap analysis on actual data, we return to the fictional Awesome Auto example as a way to visualize the two sample bootstrap setting.\nConsider an expanded scenario where the research question centers on comparing the average price of a car at one Awesome Auto franchise (Group 1) to the average price of a car at a different Awesome Auto franchise (Group 2).\nThe process of bootstrapping can be applied to *each* Group separately, and the differences of means recalculated each time.\n@fig-bootmeans2means visually describes the bootstrap process when interest is in a statistic computed on two separate samples.\nThe analysis proceeds as in the one sample case, but now the (single) statistic of interest is the *difference in sample means*.\nThat is, a bootstrap resample is done on each of the groups separately, but the results are combined to have a single bootstrapped difference in means.\nRepetition will produce $k$ bootstrapped differences in means, and the histogram will describe the natural sampling variability associated with the difference in means.\n\n\n\n\n::: {.cell}\n::: {.cell-output-display}\n![For the two group comparison, the bootstrap resampling is done separately\non each group, but the statistic is calculated as a difference. The set of\nk differences is then analyzed as the statistic of interest with\nconclusions drawn on the parameter of interest.\n](images/bootmeans2means.png){#fig-bootmeans2means fig-alt='Samples are shown as separately coming from two independent, large, unknown\npopulations. Direcly from each of the two observed samples, bootstrap\nresamples can be taken (with replacement). Bootstrap resample 1 from sample\n1 is compared to bootstrap resample 1 from sample 2 by comparing the difference\nin bootstrapped averages. A histogram of differences in bootstrapped\naverages displays the differences ranging from roughly -20000 dollars to\n+10000 dollars.' width=75%}\n:::\n:::\n\n\nIn the following sections, we leave the fictional setting of Awesome Auto and apply the boostrap method to actual datasets investigating whether or not embryonic stem cells help improve heart function and later to investigate characteristics of births. Note that the fictional setting allowed us to visualize the bootstrap method because we had samples of size five. The visualization was important in understanding how the bootstrap method works. However, the bootstrap relies heavily on the sample being an outstanding proxy for the population, and five observations are almost never enough to truly represent the nuances of a full population. To that end, we apply bootstrap methods with much larger sample sizes, as seen in the 1000 random samples provided in the births data.\n\n### Observed data\n\nDoes treatment using embryonic stem cells (ESCs) help improve heart function following a heart attack?\n@tbl-statsSheepEscStudy contains summary statistics for an experiment to test ESCs in sheep that had a heart attack.\nEach of these sheep was randomly assigned to the ESC or control group, and the change in their hearts' pumping capacity was measured in the study.\n[@Menard:2005] @fig-stem-cell-histograms provides histograms of the two datasets.\nA positive value corresponds to increased pumping capacity, which generally suggests a stronger recovery.\nOur goal will be to identify a 95% confidence interval for the effect of ESCs on the change in heart pumping capacity relative to the control group.\n\n::: {.data data-latex=\"\"}\nThe [`stem_cell`](http://openintrostat.github.io/openintro/reference/stem_cell.html) data can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.\n:::\n\n\n::: {#tbl-statsSheepEscStudy .cell tbl-cap='Summary statistics of the embryonic stem cell study.'}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n\n
Group n Mean SD
ESC 9 3.50 5.17
Control 9 -4.33 2.76
\n\n`````\n:::\n:::\n\n\nThe point estimate of the difference in the heart pumping variable is straightforward to find: it is the difference in the sample means.\n\n$$\\bar{x}_{esc} - \\bar{x}_{control}\\ =\\ 3.50 - (-4.33)\\ =\\ 7.83$$\n\n### Variability of the statistic\n\nAs we saw in @sec-two-prop-boot-ci, we will use bootstrapping to estimate the variability associated with the difference in sample means when taking repeated samples.\nIn a method akin to two proportions, a *separate* sample is taken with replacement from each group (here ESCs and control), the sample means are calculated, and their difference is taken.\nThe entire process is repeated multiple times to produce a bootstrap distribution of the difference in sample means (*without* the null hypothesis assumption).\n\n@fig-bootexamsci displays the variability of the differences in means with the 90% percentile and SE CIs super imposed.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Histogram of differences in means after 1,000 bootstrap samples from each\nof the two groups. The observed difference is plotted as a black vertical line at\n7.83. The blue dashed and red dotted lines provide the bootstrap percentile and\nboostrap SE confidence intervals, respectively, for the difference in true population\nmeans.\n](20-inference-two-means_files/figure-html/fig-bootexamsci-1.png){#fig-bootexamsci fig-alt='Histogram of differences in means after 1,000 bootstrap samples from each\nof the two groups. The observed difference is plotted as a black vertical line at\n7.83. The blue dashed and red dotted lines provide the bootstrap percentile and\nboostrap SE confidence intervals, respectively, for the difference in true population\nmeans.' width=90%}\n:::\n:::\n\n\n::: {.guidedpractice data-latex=\"\"}\nUsing the histogram of bootstrapped difference in means, estimate the standard error of the differences in sample means, $\\bar{x}_{ESC} - \\bar{x}_{Control}.$[^20-inference-two-means-3] \n:::\n\n[^20-inference-two-means-3]: The point estimate of the population difference ($\\bar{x}_{ESC} - \\bar{x}_{Control}$) is 7.83.\n\n::: {.workedexample data-latex=\"\"}\nChoose one of the bootstrap confidence intervals for the true difference in average pumping capacity, $\\mu_{ESC} - \\mu_{Control}.$ Does the interval show that there is a difference across the two treatments?\n\n------------------------------------------------------------------------\n\nBecause neither of the 90% intervals (either percentile or SE) above overlap zero (note that zero is never one of the bootstrapped differences so 95% and 99% intervals would have given the same conclusion!), we conclude that the ESC treatment is substantially better with respect to heart pumping capacity than the treatment.\n\nBecause the study is a randomized controlled experiment, we can conclude that it is the treatment (ESC) which is causing the change in pumping capacity.\n:::\n\n## Mathematical model for testing the difference in means {#sec-math2samp}\n\nEvery year, the US releases to the public a large dataset containing information on births recorded in the country.\nThis dataset has been of interest to medical researchers who are studying the relation between habits and practices of expectant mothers and the birth of their children.\nWe will work with a random sample of 1,000 cases from the dataset released in 2014.\n\n::: {.data data-latex=\"\"}\nThe [`births14`](http://openintrostat.github.io/openintro/reference/births14.html) data can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.\n:::\n\n### Observed data\n\nFour cases from this dataset are represented in @tbl-babySmokeDF.\nWe are particularly interested in two variables: `weight` and `smoke`.\nThe `weight` variable represents the weights of the newborns and the `smoke` variable describes which mothers smoked during pregnancy.\n\n\n::: {#tbl-babySmokeDF .cell tbl-cap='Four cases from the `births14` dataset. The emoty cells indicate missing data.'}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n
fage mage weeks visits gained weight sex habit
34 34 37 14 28 6.96 male nonsmoker
36 31 41 12 41 8.86 female nonsmoker
37 36 37 10 28 7.51 female nonsmoker
16 38 29 6.19 male nonsmoker
\n\n`````\n:::\n:::\n\n\nWe would like to know, is there convincing evidence that newborns from mothers who smoke have a different average birth weight than newborns from mothers who do not smoke?\nWe will use data from this sample to try to answer this question.\n\n::: {.workedexample data-latex=\"\"}\nSet up appropriate hypotheses to evaluate whether there is a relationship between a mother smoking and average birth weight.\n\n------------------------------------------------------------------------\n\nThe null hypothesis represents the case of no difference between the groups.\n\n- $H_0:$ There is no difference in average birth weight for newborns from mothers who did and did not smoke. In statistical notation: $\\mu_{n} - \\mu_{s} = 0,$ where $\\mu_{n}$ represents non-smoking mothers and $\\mu_s$ represents mothers who smoked.\n- $H_A:$ There is some difference in average newborn weights from mothers who did and did not smoke $(\\mu_{n} - \\mu_{s} \\neq 0).$\n:::\n\n@tbl-births14-summary-stats displays sample statistics from the data.\nWe can see that the average birth weight of babies born to smoker moms is lower than those born to nonsmoker moms.\n\n\n::: {#tbl-births14-summary-stats .cell tbl-cap='Summary statistics for the `births14` dataset.'}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n\n
Habit n Mean SD
nonsmoker 867 7.27 1.23
smoker 114 6.68 1.60
\n\n`````\n:::\n:::\n\n\n### Variability of the statistic\n\nWe check the two conditions necessary to model the difference in sample means using the $t$-distribution.\n\n- Because the data come from a simple random sample, the observations are independent, both within and between samples.\n- With both groups over 30 observations, we inspect the data in @fig-babySmokePlotOfTwoGroupsToExamineSkew for any particularly extreme outliers and find none.\n\nSince both conditions are satisfied, the difference in sample means may be modeled using a $t$-distribution.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![The top panel represents birth weights for infants whose mothers smoked during\npregnancy. The bottom panel represents the birth weights for infants whose mothers\nwho did not smoke during pregnancy.\n](20-inference-two-means_files/figure-html/fig-babySmokePlotOfTwoGroupsToExamineSkew-1.png){#fig-babySmokePlotOfTwoGroupsToExamineSkew fig-alt='The top panel represents birth weights for infants whose mothers smoked during\npregnancy. The bottom panel represents the birth weights for infants whose mothers\nwho did not smoke during pregnancy.' width=90%}\n:::\n:::\n\n\n::: {.guidedpractice data-latex=\"\"}\nThe summary statistics in @tbl-births14-summary-stats may be useful for this Guided Practice.\nWhat is the point estimate of the population difference, $\\mu_{n} - \\mu_{s}$?[^20-inference-two-means-4]\n:::\n\n[^20-inference-two-means-4]: The point estimate of the population difference ($\\bar{x}_{n} - \\bar{x}_{s}$) is 0.59.\n\n### Observed statistic vs. null statistics\n\n::: {.important data-latex=\"\"}\n**The test statistic for comparing two means is a T.**\n\nThe T score is a ratio of how the groups differ as compared to how the observations within a group vary.\n\n$$T = \\frac{(\\bar{x}_1 - \\bar{x}_2) - 0}{\\sqrt{s_1^2/n_1 + s_2^2/n_2}}$$\n\nWhen the null hypothesis is true and the conditions are met, T has a t-distribution with $df = min(n_1 - 1, n_2 -1).$\n\nConditions:\n\n- Independent observations within and between groups.\n- Large samples and no extreme outliers.\n:::\n\n\n\n\n\n::: {.guidedpractice data-latex=\"\"}\nCompute the standard error of the point estimate for the average difference between the weights of babies born to nonsmoker and smoker mothers.[^20-inference-two-means-5]\n:::\n\n[^20-inference-two-means-5]: $SE(\\bar{x}_{n} - \\bar{x}_{s}) = \\sqrt{s^2_{n}/ n_{n} + s^2_{s}/n_{s}}\\\\ = \\sqrt{1.23^2/867 + 1.60^2/114} = 0.16$\n\n::: {.workedexample data-latex=\"\"}\nComplete the hypothesis test started in the previous Example and Guided Practice on `births14` dataset and research question.\nUse a discernibility level of $\\alpha=0.05.$ For reference, $\\bar{x}_{n} - \\bar{x}_{s} = 0.59,$ $SE = 0.16,$ and the sample sizes were $n_n = 867$ and $n_s = 114.$\n\n------------------------------------------------------------------------\n\nWe can find the test statistic for this test using the previous information:\n\n$$T = \\frac{\\ 0.59 - 0\\ }{0.16} = 3.69$$\n\nWe find the single tail area using software.\nWe'll use the smaller of $n_n - 1 = 866$ and $n_s - 1 = 113$ as the degrees of freedom: $df = 113.$ The one tail area is roughly 0.00017; doubling this value gives the two-tail area and p-value, 0.00034.\n\nThe p-value is much smaller than the discernibility level, 0.05, so we reject the null hypothesis.\nThe data provide is convincing evidence of a difference in the average weights of babies born to mothers who smoked during pregnancy and those who did not.\n:::\n\nThis result is likely not surprising.\nWe all know that smoking is bad for you and you've probably also heard that smoking during pregnancy is not just bad for the mother but also for the baby as well.\nIn fact, some in the tobacco industry actually had the audacity to tout that as a *benefit* of smoking:\n\n> *It's true. The babies born from women who smoke are smaller, but they're just as healthy as the babies born from women who do not smoke. And some women would prefer having smaller babies.* - Joseph Cullman, Philip Morris' Chairman of the Board on CBS' *Face the Nation*, Jan 3, 1971\n\nFurthermore, health differences between babies born to mothers who smoke and those who do not are not limited to weight differences.[^20-inference-two-means-6]\n\n[^20-inference-two-means-6]: You can watch an episode of John Oliver on [*Last Week Tonight*](youtu.be/6UsHHOCH4q8) to explore the present day offenses of the tobacco industry.\n Please be aware that there is some adult language.\n\nA small note on the power of the independent t-test (recall the discussion of power in @sec-pow). It turns out that the independent t-test given here is often less powerful than the paired t-test discussed in @sec-mathpaired. That said, depending on how the data are collected, we don't always have mechanism for pairing the data and reducing the inherent variability across observations.\n\n## Mathematical model for estimating the difference in means\n\n### Observed data\n\nAs with hypothesis testing, for the question of whether we can model the difference using a $t$-distribution, we'll need to check new conditions.\nLike the 2-proportion cases, we will require a more robust version of independence so we are confident the two groups are also independent.\nSecondly, we also check for normality in each group separately, which in practice is a check for outliers.\n\n\n\n\n\n\\index{point estimate}\n\n::: {.important data-latex=\"\"}\n**Using the** $t$**-distribution for a difference in means.**\n\nThe $t$-distribution can be used for inference when working with the standardized difference of two means if\n\n- *Independence* (extended). The data are independent within and between the two groups, e.g., the data come from independent random samples or from a randomized experiment.\n- *Normality*. We check the outliers for each group separately.\n\nThe standard error may be computed as\n\n$$SE = \\sqrt{\\frac{\\sigma_1^2}{n_1} + \\frac{\\sigma_2^2}{n_2}}$$\n\nThe official formula for the degrees of freedom is quite complex and is generally computed using software, so instead you may use the smaller of $n_1 - 1$ and $n_2 - 1$ for the degrees of freedom if software isn't readily available.\n:::\n\nRecall that the margin of error is defined by the standard error.\nThe margin of error for $\\bar{x}_1 - \\bar{x}_2$ can be directly obtained from $SE(\\bar{x}_1 - \\bar{x}_2).$\n\n::: {.important data-latex=\"\"}\n**Margin of error for** $\\bar{x}_1 - \\bar{x}_2.$\n\nThe margin of error is $t^\\star_{df} \\times \\sqrt{\\frac{s_1^2}{n_1} + \\frac{s_2^2}{n_2}}$ where $t^\\star_{df}$ is calculated from a specified percentile on the t-distribution with *df* degrees of freedom.\n:::\n\n\n\n\n\n\\index{standard error (SE)!difference in means}\n\n### Variability of the statistic\n\n::: {.workedexample data-latex=\"\"}\nCan the $t$-distribution be used to make inference using the point estimate, $\\bar{x}_{esc} - \\bar{x}_{control} = 7.83$?\n\n------------------------------------------------------------------------\n\nFirst, we check for independence.\nBecause the sheep were randomized into the groups, independence within and between groups is satisfied.\n\n@fig-stem-cell-histograms does not reveal any clear outliers in either group.\n(The ESC group does look a bit more variable, but this is not the same as having clear outliers.)\n\nWith both conditions met, we can use the $t$-distribution to model the difference of sample means.\n:::\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Histograms for the difference in heart pumping function after a heart attack\nfor both the treatment group (ESC, which received an the embryonic stem cell\ntreatment) and the control group (which did not receive the treatment).\n](20-inference-two-means_files/figure-html/fig-stem-cell-histograms-1.png){#fig-stem-cell-histograms fig-alt='Histograms for the difference in heart pumping function after a heart attack\nfor both the treatment group (ESC, which received an the embryonic stem cell\ntreatment) and the control group (which did not receive the treatment).' width=90%}\n:::\n:::\n\n\nGenerally, we use statistical software to find the appropriate degrees of freedom, or if software isn't available, we can use the smaller of $n_1 - 1$ and $n_2 - 1$ for the degrees of freedom, e.g., if using a $t$-table to find tail areas.\nFor transparency in the Examples and Guided Practice, we'll use the latter approach for finding $df$; in the case of the ESC example, this means we'll use $df = 8.$\n\n::: {.workedexample data-latex=\"\"}\nCalculate a 95% confidence interval for the effect of ESCs on the change in heart pumping capacity of sheep after they've suffered a heart attack.\n\n------------------------------------------------------------------------\n\nWe will use the sample difference and the standard error that we computed earlier:\n\n$$\n\\begin{aligned}\n\\bar{x}_{esc} - \\bar{x}_{control} &= 7.83 \\\\\nSE &= \\sqrt{\\frac{5.17^2}{9} + \\frac{2.76^2}{9}} = 1.95\n\\end{aligned}\n$$\n\nUsing $df = 8,$ we can identify the critical value of $t^{\\star}_{8} = 2.31$ for a 95% confidence interval.\nFinally, we can enter the values into the confidence interval formula:\n\n$$\n\\begin{aligned}\n\\text{point estimate} \\ &\\pm\\ t^{\\star} \\times SE \\\\\n7.83 \\ &\\pm\\ 2.31\\times 1.95 \\\\\n(3.32 \\ &, \\ 12.34)\n\\end{aligned} \n$$\n\nWe are 95% confident that the heart pumping function in sheep that received embryonic stem cells is between 3.32% and 12.34% higher than for sheep that did not receive the stem cell treatment.\n:::\n\n\\clearpage\n\n## Chapter review {#sec-chp20-review}\n\n### Summary\n\nIn this chapter we extended the single mean inferential methods to questions of differences in means.\nYou may have seen parallels from the chapters that extended a single proportion (Chapter \\@ref(inference-one-prop)) to differences in proportions (Chapter \\@ref(inference-two-props)).\nWhen considering differences in sample means (indeed, when considering many quantitative statistics), we use the t-distribution to describe the sampling distribution of the T score (the standardized difference in sample means).\nIdeas of confidence level and type of error which might occur from a hypothesis test conclusion are similar to those seen in other chapters (see [Chapter -@sec-foundations-decision-errors]).\n\n### Terms\n\nWe introduced the following terms in the chapter.\nIf you're not sure what some of these terms mean, we recommend you go back in the text and review their definitions.\nWe are purposefully presenting them in alphabetical order, instead of in order of appearance, so they will be a little more challenging to locate.\nHowever, you should be able to easily spot them as **bolded text**.\n\n\n::: {.cell}\n::: {.cell-output-display}\n`````{=html}\n\n\n \n \n \n \n \n \n \n \n \n \n\n
difference in means SE difference in means t-CI
point estimate T score t-test
\n\n`````\n:::\n:::\n\n\n\\clearpage\n\n## Exercises {#sec-chp20-exercises}\n\nAnswers to odd-numbered exercises can be found in [Appendix -@sec-exercise-solutions-20].\n\n::: {.exercises data-latex=\"\"}\n1. **Experimental baker.** \nA baker working on perfecting their bagel recipe is experimenting with active dry (AD) and instant (I) yeast. \nThey bake a dozen bagels with each type of yeast and score each bagel on a scale of 1 to 10 on how well the bagels rise.\nThey come up with the following set of hypotheses for evaluating whether there is a difference in the average rise of bagels baked with active dry and instant yeast.\nWhat is wrong with the hypotheses as stated?\n\n $$H_0: \\bar{x}_{AD} \\leq \\bar{x}_{I} \\quad \\quad H_A: \\bar{x}_{AD} > \\bar{x}_{I}$$\n\n1. **Fill in the blanks.** \nWe use a \\_\\_\\_ to evaluate if data provide convincing evidence of a difference between two population means and we use a \\_\\_\\_ to estimate this difference.\n\n1. **Diamonds, randomization test.**\nThe prices of diamonds go up as the carat weight increases, but the increase is not smooth. \nFor example, the difference between the size of a 0.99 carat diamond and a 1 carat diamond is undetectable to the naked human eye, but the price of a 1 carat diamond tends to be much higher than the price of a 0.99 diamond. \nIn this question we use two random samples of diamonds, 0.99 carats and 1 carat, each sample of size 23, and randomize the carat weight to the price values in order compare the average prices of the diamonds to a null distribution.\nIn order to be able to compare equivalent units, we first divide the price for each diamond by 100 times its weight in carats. \nThat is, for a 0.99 carat diamond, we divide the price by 99. or a 1 carat diamond, we divide the price by 100. \nThe randomization distribution (with 1,000 repetitions) below describes the null distribution of the difference in sample means (of price per carat) if there really was no difference in the population from which these diamonds came.^[The [`diamonds`](https://ggplot2.tidyverse.org/reference/diamonds.html) data used in this exercise can be found in the [**ggplot2**](http://ggplot2.tidyverse.org/) R package.] [@ggplot2]\n\n ::: {.cell}\n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-21-1.png){width=90%}\n :::\n :::\n\n Using the randomization distribution of the difference in average price per carat (1,000 randomizations were run), conduct a hypothesis test to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat. Make sure to state your hypotheses clearly and interpret your results in context of the data. [@ggplot2]\n\n1. **Lizards running, randomization test.**\nIn order to assess physiological characteristics of common lizards, data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus).\nThe original observed difference in lizard speeds is $\\bar{x}_{Western fence} - \\bar{x}_{Sagebrush} = 0.7 \\mbox{m/sec}.$ The histogram below shows the distribution of average differences when speed has been randomly allocated across lizard species 1,000 times.^[The [`lizard_run`](http://openintrostat.github.io/openintro/reference/lizard_run.html) data used in this exercise can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.] [@Adolph:1987]\n\n ::: {.cell}\n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-22-1.png){width=90%}\n :::\n :::\n \n Using the randomization distribution, conduct a hypothesis test to evaluate if there is a difference between the average speed of the Western fence lizard as compared to the Sagebrush lizard. Make sure to state your hypotheses clearly and interpret your results in context of the data.\n\n1. **Diamonds, bootstrap interval.**\nWe have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. \nEach sample has 23 diamonds.\nProvided below is a histogram of bootstrap differences in means of price per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat.\n[@ggplot2]\n\n ::: {.cell}\n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-23-1.png){width=90%}\n :::\n :::\n \n a. Using the bootstrap distribution, create a (rough) 95% bootstrap percentile confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. \n \n b. Using the bootstrap distribution, create a (rough) 95% bootstrap SE confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. Note that the standard error of the bootstrap distribution is 4.64.\n\n1. **Lizards running, bootstrap interval.**\nWe have data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus).\nThe bootstrap distribution below describes the variability of difference in means captured from 1,000 bootstrap samples of the lizard data. [@Adolph:1987]\n \n ::: {.cell}\n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-24-1.png){width=90%}\n :::\n :::\n \n a. Using the bootstrap distribution, create a (rough) 90% percentile bootrap confidence interval for the true population difference in price per carat for Western fence lizard as compared with Sagebrush lizard.\n \n b. Using the bootstrap distribution, create a (rough) 90% bootstrap SE confidence interval for the true population difference in price per carat for Western fence lizard as compared with Sagebrush lizard.\n\n1. **Weight loss.**\nYou are reading an article in which the researchers have created a 95% confidence interval for the difference in average weight loss for two diets. \nThey are 95% confident that the true difference in average weight loss over 6 months for the two diets is somewhere between (1 lb, 25 lbs).\nThe authors claim that, \"therefore diet A ($\\bar{x}_A$ = 20 lbs average loss) results in a much larger average weight loss as compared to diet B ($\\bar{x}_B$ = 7 lbs average loss).\" Comment on the authors' claim.\n\n1. **Possible randomized means.**\nData were collected on data from two groups (A and B). There were 3 measurements taken on Group A and two measurements \n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Group Measurement 1 Measurement 2 Measurement 3
A 1 15 5
B 7 3
\n \n `````\n :::\n :::\n \n If the data are (repeatedly) randomly allocated across the two conditions, provide the following: (1) the values which are assigned to group A, (2) the values which are assigned to group B, and (3) the difference in averages $(\\bar{x}_A - \\bar{x}_B)$ for each of the following: \n\n a. When the randomized difference in averages is as big as possible.\n \n b. When the randomized difference in averages is as small as possible (a big in magnitude negative number).\n \n c. When the randomized difference in averages is as close to zero as possible.\n \n d. When the observed values are randomly assigned to the two groups, to which of the previous parts would you expect the difference in means to fall closest? Explain your reasoning.\n\n1. **Diamonds, mathematical test.** \nWe have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. \nEach sample has 23 diamonds.\nSample statistics for the price per carat of diamonds in each sample are provided below.\nConduct a hypothesis test using a mathematical model to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat \nMake sure to state your hypotheses clearly, check relevant conditions, and interpret your results in context of the data. [@ggplot2]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Mean SD n
0.99 carats $44.51 $13.32 23
1 carat $57.20 $18.19 23
\n \n `````\n :::\n \n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-26-1.png){width=90%}\n :::\n :::\n\n1. **A/B testing.** \nA/B testing is a user experience research methodology where two variants of a page are shown to users at random.\nA company wants to evaluate whether users will spend more time, on average, on Page A or Page B using an A/B test.\nTwo user experience designers at the company, Lucie and Müge, are tasked with conducting the analysis of the data collected.\nThey agree on how the null hypothesis should be set: on average, users spend the same amount of time on Page A and Page B.\nLucie believes that Page B will provide a better experience for users and hence wants to use a one-tailed test, Müge believes that a two-tailed test would be a better choice.\nWhich designer do you agree with, and why?\n\n1. **Diamonds, mathematical interval.** \nWe have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. \nEach sample has 23 diamonds. \nSample statistics for the price per carat of diamonds in each sample are provided below.\nAssuming that the conditions for conducting inference using a mathematical model are satisfied, construct a 95% confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. [@ggplot2]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Mean SD n
0.99 carats $44.51 $13.32 23
1 carat $57.20 $18.19 23
\n \n `````\n :::\n :::\n\n1. **True / False: comparing means.**\nDetermine if the following statements are true or false, and explain your reasoning for statements you identify as false.\n\n a. As the degrees of freedom increases, the $t$-distribution approaches normality.\n\n b. If a 95% confidence interval for the difference between two population means contains 0, a 99% confidence interval calculated based on the same two samples will also contain 0.\n \n c. If a 95% confidence interval for the difference between two population means contains 0, a 90% confidence interval calculated based on the same two samples will also contain 0.\n\n1. **Difference of means.** \nSuppose we will collect two random samples from the following distributions.\nIn each of the parts below, consider the sample means $\\bar{x}_1$ and $\\bar{x}_2$ that we might observe from these two samples.\n \n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Mean Standard deviation Sample size
Sample 1 15 20 50
Sample 2 20 10 30
\n \n `````\n :::\n :::\n\n a. What is the associated mean and standard deviation of $\\bar{x}_1$?\n\n b. What is the associated mean and standard deviation of $\\bar{x}_2$?\n\n c. Calculate and interpret the mean and standard deviation associated with the difference in sample means for the two groups, $\\bar{x}_2 - \\bar{x}_1$.\n\n d. How are the standard deviations from parts (a), (b), and (c) related?\n\n1. **Mindfulness intervention for nurses.** \nIn order to address extremely challenging and stressful situations for nurses in intensive care units, a group of researchers ran a mindfulness-based intervention (MBI) study on 60 nurses working in three hospitals in El-Beheira, Egypt.\nThe participants were randomly allocated to one of the two groups: the treatment group (MBI) received 8 MBI sessions and the control group received no intervention. \nThe nurses' emotional exhaustion was measured using 9 items from a questionnaire of the Maslach Burnout Inventory-Human Services Survey for Medical Personnel; the questions are recorded on a Likert scale where 0 indicated \"Never\" and 6 indicates \"Every day\".\nNurses in the treatment group had an emotional exhaustion score of 15.47, with a standard deviation of 4.44, and nurses in the control group had an emotional exhaustion score of 32.43, with a standard deviation of 8.87. \nDo these data provide convincing evidence that the emotional exhaustion decrease is different for the patients in the treatment group compared to the control group? \nAssume that conditions for conducting inference using mathematical models are satisfied. [@Othman:2023]\n\n1. **Chicken diet: horsebean vs. linseed.** \nChicken farming is a multi-billion dollar industry, and any methods that increase the growth rate of young chicks can reduce consumer costs while increasing company profits, possibly by millions of dollars. \nAn experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens. \nNewly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement. \nIn this exercise we consider chicks that were fed horsebean and linseed.\nBelow are some summary statistics from this dataset along with box plots showing the distribution of weights by feed type.^[The [`chickwts`](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/chickwts.html) data used in this exercise can be found in the [**datasets**](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html) R package.] [@data:chickwts]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Feed type Mean SD n
horsebean 160.20 38.63 10
linseed 218.75 52.24 12
\n \n `````\n :::\n \n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-29-1.png){width=100%}\n :::\n :::\n\n a. Describe the distributions of weights of chickens that were fed horsebean and linseed.\n\n b. Do these data provide strong evidence that the average weights of chickens that were fed linseed and horsebean are different? Use a 5% discernibility level.\n\n c. What type of error might we have committed? Explain.\n\n d. Would your conclusion change if we used $\\alpha = 0.01$?\n\n1. **Fuel efficiency in the city.** \nEach year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. \nBelow are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021. \nDo these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average city mileage?^[The [`epa2021`](http://openintrostat.github.io/openintro/reference/epa2021.html) data used in this exercise can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.] [@data:epa2021]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
CITY Mean SD n
Automatic 17.4 3.44 25
Manual 22.7 4.58 25
\n \n `````\n :::\n \n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-30-1.png){width=90%}\n :::\n :::\n\n1. **Chicken diet: casein vs. soybean.** \nCasein is a common weight gain supplement for humans. \nDoes it have an effect on chickens? \nAn experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens. \nNewly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement. \nIn this exercise we consider chicks that were fed casein and soybean.\nAssume that the conditions for conducting inference using mathematical models are met, and using the data provided below, test the hypothesis that the average weight of chickens that were fed casein is different than the average weight of chickens that were fed soybean. \nIf your hypothesis test yields a statistically discernible result, discuss whether or not the higher average weight of chickens can be attributed to the casein diet. [@data:chickwts]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Feed type Mean SD n
casein 323.58 64.43 12
soybean 246.43 54.13 14
\n \n `````\n :::\n :::\n\n1. **Fuel efficiency on the highway.** \nEach year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. \nBelow are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021. \nDo these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average highway mileage? [@data:epa2021]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
HIGHWAY Mean SD n
Automatic 23.7 3.90 25
Manual 30.9 5.13 25
\n \n `````\n :::\n \n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-32-1.png){width=90%}\n :::\n :::\n\n1. **Gaming, distracted eating, and intake.** \nA group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups. \nThe treatment group ate lunch while playing solitaire, and the control group ate lunch without any added distractions. \nPatients in the treatment group ate 52.1 grams of biscuits, with a standard deviation of 45.1 grams, and patients in the control group ate 27.1 grams of biscuits, with a standard deviation of 26.4 grams. \nDo these data provide convincing evidence that the average food intake (measured in amount of biscuits consumed) is different for the patients in the treatment group compared to the control group? \nAssume that conditions for conducting inference using mathematical models are satisfied. [@Oldham:2011]\n\n1. **Gaming, distracted eating, and recall.** \nA group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups. \nThe 22 patients in the treatment group who ate their lunch while playing solitaire were asked to do a serial-order recall of the food lunch items they ate. \nThe average number of items recalled by the patients in this group was 4. 9, with a standard deviation of 1.8. \nThe average number of items recalled by the patients in the control group (no distraction) was 6.1, with a standard deviation of 1.8. \nDo these data provide strong evidence that the average numbers of food items recalled by the patients in the treatment and control groups are different?\nAssume that conditions for conducting inference using mathematical models are satisfied. [@Oldham:2011]\n\n\n:::\n", + "markdown": "# Inference for comparing two independent means {#sec-inference-two-means}\n\n\n\n\n\n::: {.chapterintro data-latex=\"\"}\nWe now extend the methods from [Chapter -@sec-inference-one-mean] to apply confidence intervals and hypothesis tests to differences in population means that come from two groups, Group 1 and Group 2: $\\mu_1 - \\mu_2.$\n\nIn our investigations, we'll identify a reasonable point estimate of $\\mu_1 - \\mu_2$ based on the sample, and you may have already guessed its form: $\\bar{x}_1 - \\bar{x}_2.$ \\index{point estimate!difference of means} Then we'll look at the inferential analysis in three different ways: using a randomization test, applying bootstrapping for interval estimates, and, if we verify that the point estimate can be modeled using a normal distribution, we compute the estimate's standard error and apply the mathematical framework.\n:::\n\n\n\n\n\nIn this section we consider a difference in two population means, $\\mu_1 - \\mu_2,$ under the condition that the data are not paired.\nJust as with a single sample, we identify conditions to ensure we can use the $t$-distribution with a point estimate of the difference, $\\bar{x}_1 - \\bar{x}_2,$ and a new standard error formula.\n\nThe details for working through inferential problems in the two independent means setting are strikingly similar to those applied to the two independent proportions setting.\nWe first cover a randomization test where the observations are shuffled under the assumption that the null hypothesis is true.\nThen we bootstrap the data (with no imposed null hypothesis) to create a confidence interval for the true difference in population means, $\\mu_1 - \\mu_2.$ The mathematical model, here the $t$-distribution, is able to describe both the randomization test and the bootstrapping as long as the conditions are met.\n\nThe inferential tools are applied to three different data contexts: determining whether stem cells can improve heart function, exploring the relationship between pregnant women's smoking habits and birth weights of newborns, and exploring whether there is convincing evidence that one variation of an exam is harder than another variation.\nThis section is motivated by questions like \"Is there convincing evidence that newborns from mothers who smoke have a different average birth weight than newborns from mothers who do not smoke?\"\n\n## Randomization test for the difference in means {#sec-rand2mean}\n\nAn instructor decided to run two slight variations of the same exam.\nPrior to passing out the exams, they shuffled the exams together to ensure each student received a random version.\nAnticipating complaints from students who took Version B, they would like to evaluate whether the difference observed in the groups is so large that it provides convincing evidence that Version B was more difficult (on average) than Version A.\n\n::: {.data data-latex=\"\"}\nThe [`classdata`](http://openintrostat.github.io/openintro/reference/classdata.html) data can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.\n:::\n\n### Observed data\n\nSummary statistics for how students performed on these two exams are shown in @tbl-summaryStatsForTwoVersionsOfExams and plotted in @fig-boxplotTwoVersionsOfExams.\n\n\n::: {#tbl-summaryStatsForTwoVersionsOfExams .cell tbl-cap='Summary statistics of scores for each exam version.'}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n
Group n Mean SD Min Max
A 58 75.1 13.9 44 100
B 55 72.0 13.8 38 100
\n\n`````\n:::\n:::\n\n::: {.cell}\n::: {.cell-output-display}\n![Exam scores for students given one of two different exams.](20-inference-two-means_files/figure-html/fig-boxplotTwoVersionsOfExams-1.png){#fig-boxplotTwoVersionsOfExams fig-alt='Boxplot of exam score broken down by version of exam.' width=90%}\n:::\n:::\n\n\n::: {.guidedpractice data-latex=\"\"}\nConstruct hypotheses to evaluate whether the observed difference in sample means, $\\bar{x}_A - \\bar{x}_B=3.1,$ is likely to have happened due to chance, if the null hypothesis is true.\nWe will later evaluate these hypotheses using $\\alpha = 0.01.$[^20-inference-two-means-1]\n:::\n\n[^20-inference-two-means-1]: $H_0:$ the exams are equally difficult, on average.\n $\\mu_A - \\mu_B = 0.$ $H_A:$ one exam was more difficult than the other, on average.\n $\\mu_A - \\mu_B \\neq 0.$\n\n::: {.guidedpractice data-latex=\"\"}\nBefore moving on to evaluate the hypotheses in the previous Guided Practice, let's think carefully about the dataset.\nAre the observations across the two groups independent?\nAre there any concerns about outliers?[^20-inference-two-means-2]\n:::\n\n[^20-inference-two-means-2]: Since the exams were shuffled, the \"treatment\" in this case was randomly assigned, so independence within and between groups is satisfied.\n The summary statistics suggest the data are roughly symmetric about the mean, and the min/max values do not suggest any outliers of concern.\n\n### Variability of the statistic\n\nIn @sec-foundations-randomization, the variability of the statistic (previously: $\\hat{p}_1 - \\hat{p}_2)$ was visualized after shuffling the observations across the two treatment groups many times.\nThe shuffling process implements the null hypothesis model (that there is no effect of the treatment).\nIn the exam example, the null hypothesis is that exam A and exam B are equally difficult, so the average scores across the two tests should be the same.\nIf the exams were equally difficult, *due to natural variability*, we would sometimes expect students to do slightly better on exam A $(\\bar{x}_A > \\bar{x}_B)$ and sometimes expect students to do slightly better on exam B $(\\bar{x}_B > \\bar{x}_A).$ The question at hand is: does $\\bar{x}_A - \\bar{x}_B=3.1$ indicate that exam A is easier than exam B.\n\n@fig-rand2means shows the process of randomizing the exam to the observed exam scores.\nIf the null hypothesis is true, then the score on each exam should represent the true student ability on that material.\nIt shouldn't matter whether they were given exam A or exam B.\nBy reallocating which student got which exam, we are able to understand how the difference in average exam scores changes due only to natural variability.\nThere is only one iteration of the randomization process in @fig-rand2means, leading to one simulated difference in average scores.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![The version of the test (A or B) is randomly allocated to the test scores,\nunder the null assumption that the tests are equally difficult.\n](images/rand2means.png){#fig-rand2means fig-alt='Four panels representing four different orientations of a toy dataset of\n9 exam scores. The first panel provides the observed data; 4 of the exams were\nversion A and the average score was 77.25; 5 of the exams were version B and the\naverage score was 75.8, a difference of 1.45. The second panel shows the shuffled\nreassignment of the exam versions (4 of the scores are randomly reassigned to A,\n5 of the scores are randomly reassigned to B). The third panel shows which score\nis connected with which new reassigned version of the exam. And the fourth panel\nsorts the exams so that version A exams are together and version B exams are\ntogether. In the randomly reassigned versions, the average score for\nversion A is 74.25 and the average score for version B is 78.2, a difference of -3.95.' width=75%}\n:::\n:::\n\n\nBuilding on @fig-rand2means, @fig-randexams shows the values of the simulated statistics $\\bar{x}_{1, sim} - \\bar{x}_{2, sim}$ over 1,000 random simulations.\nWe see that, just by chance, the difference in scores can range anywhere from -10 points to +10 points.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Histogram of differences in means, calculated from 1,000 different randomizations\nof the exam types.\n](20-inference-two-means_files/figure-html/fig-randexams-1.png){#fig-randexams fig-alt='Histogram of differences in means, calculated from 1,000 different randomizations\nof the exam types.' width=90%}\n:::\n:::\n\n\n### Observed statistic vs. null statistics\n\nThe goal of the randomization test is to assess the observed data, here the statistic of interest is $\\bar{x}_A - \\bar{x}_B=3.1.$ The randomization distribution allows us to identify whether a difference of 3.1 points is more than one would expect by natural variability of the scores if the two tests were equally difficult.\nBy plotting the value of 3.1 on @fig-randexamspval, we can measure how different or similar 3.1 is to the randomized differences which were generated under the null hypothesis.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Histogram of differences in means, calculated from 1,000 different randomizations\nof the exam types. The observed difference of 3.1 points is plotted as a vertical\nline, and the area more extreme than 3.1 is shaded to represent the p-value.\n](20-inference-two-means_files/figure-html/fig-randexamspval-1.png){#fig-randexamspval fig-alt='Histogram of differences in means, calculated from 1,000 different randomizations\nof the exam types. The observed difference of 3.1 points is plotted as a vertical\nline, and the area more extreme than 3.1 is shaded to represent the p-value.' width=90%}\n:::\n:::\n\n\n::: {.workedexample data-latex=\"\"}\nApproximate the p-value depicted in @fig-randexamspval, and provide a conclusion in the context of the case study.\n\n------------------------------------------------------------------------\n\nUsing software, we can find the number of shuffled differences in means that are less than the observed difference (of 3.14) is 900 (out of 1,000 randomizations).\nSo 10% of the simulations are larger than the observed difference.\nTo get the p-value, we double the proportion of randomized differences which are larger than the observed difference, p-value = 0.2.\n\nPreviously, we specified that we would use $\\alpha = 0.01.$ Since the p-value is larger than $\\alpha,$ we do not reject the null hypothesis.\nThat is, the data do not convincingly show that one exam version is more difficult than the other, and the teacher should not be convinced that they should add points to the Version B exam scores.\n:::\n\n\n::: {.cell}\n\n:::\n\n\nThe large p-value and consistency of $\\bar{x}_A - \\bar{x}_B=3.1$ with the randomized differences leads us to *not reject the null hypothesis*.\nSaid differently, there is no evidence to think that one of the tests is easier than the other.\nOne might be inclined to conclude that the tests have the same level of difficulty, but that conclusion would be wrong.\nThe hypothesis testing framework is set up only to reject a null claim, it is not set up to validate a null claim.\nAs we concluded, the data are consistent with exams A and B being equally difficult, but the data are also consistent with exam A being 3.1 points \"easier\" than exam B.\nThe data are not able to adjudicate on whether the exams are equally hard or whether one of them is slightly easier.\nIndeed, conclusions where the null hypothesis is not rejected often seem unsatisfactory.\nHowever, in this case, the teacher and class are probably all relieved that there is no evidence to demonstrate that one of the exams is more difficult than the other.\n\n## Bootstrap confidence interval for the difference in means\n\nBefore providing a full example working through a bootstrap analysis on actual data, we return to the fictional Awesome Auto example as a way to visualize the two sample bootstrap setting.\nConsider an expanded scenario where the research question centers on comparing the average price of a car at one Awesome Auto franchise (Group 1) to the average price of a car at a different Awesome Auto franchise (Group 2).\nThe process of bootstrapping can be applied to *each* Group separately, and the differences of means recalculated each time.\n@fig-bootmeans2means visually describes the bootstrap process when interest is in a statistic computed on two separate samples.\nThe analysis proceeds as in the one sample case, but now the (single) statistic of interest is the *difference in sample means*.\nThat is, a bootstrap resample is done on each of the groups separately, but the results are combined to have a single bootstrapped difference in means.\nRepetition will produce $k$ bootstrapped differences in means, and the histogram will describe the natural sampling variability associated with the difference in means.\n\n\n\n\n::: {.cell}\n::: {.cell-output-display}\n![For the two group comparison, the bootstrap resampling is done separately\non each group, but the statistic is calculated as a difference. The set of\nk differences is then analyzed as the statistic of interest with\nconclusions drawn on the parameter of interest.\n](images/bootmeans2means.png){#fig-bootmeans2means fig-alt='Samples are shown as separately coming from two independent, large, unknown\npopulations. Direcly from each of the two observed samples, bootstrap\nresamples can be taken (with replacement). Bootstrap resample 1 from sample\n1 is compared to bootstrap resample 1 from sample 2 by comparing the difference\nin bootstrapped averages. A histogram of differences in bootstrapped\naverages displays the differences ranging from roughly -20000 dollars to\n+10000 dollars.' width=75%}\n:::\n:::\n\n\nIn the following sections, we leave the fictional setting of Awesome Auto and apply the boostrap method to actual datasets investigating whether or not embryonic stem cells help improve heart function and later to investigate characteristics of births. Note that the fictional setting allowed us to visualize the bootstrap method because we had samples of size five. The visualization was important in understanding how the bootstrap method works. However, the bootstrap relies heavily on the sample being an outstanding proxy for the population, and five observations are almost never enough to truly represent the nuances of a full population. To that end, we apply bootstrap methods with much larger sample sizes, as seen in the 1000 random samples provided in the births data.\n\n### Observed data\n\nDoes treatment using embryonic stem cells (ESCs) help improve heart function following a heart attack?\n@tbl-statsSheepEscStudy contains summary statistics for an experiment to test ESCs in sheep that had a heart attack.\nEach of these sheep was randomly assigned to the ESC or control group, and the change in their hearts' pumping capacity was measured in the study.\n[@Menard:2005] @fig-stem-cell-histograms provides histograms of the two datasets.\nA positive value corresponds to increased pumping capacity, which generally suggests a stronger recovery.\nOur goal will be to identify a 95% confidence interval for the effect of ESCs on the change in heart pumping capacity relative to the control group.\n\n::: {.data data-latex=\"\"}\nThe [`stem_cell`](http://openintrostat.github.io/openintro/reference/stem_cell.html) data can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.\n:::\n\n\n::: {#tbl-statsSheepEscStudy .cell tbl-cap='Summary statistics of the embryonic stem cell study.'}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n\n
Group n Mean SD
ESC 9 3.50 5.17
Control 9 -4.33 2.76
\n\n`````\n:::\n:::\n\n\nThe point estimate of the difference in the heart pumping variable is straightforward to find: it is the difference in the sample means.\n\n$$\\bar{x}_{esc} - \\bar{x}_{control}\\ =\\ 3.50 - (-4.33)\\ =\\ 7.83$$\n\n### Variability of the statistic\n\nAs we saw in @sec-two-prop-boot-ci, we will use bootstrapping to estimate the variability associated with the difference in sample means when taking repeated samples.\nIn a method akin to two proportions, a *separate* sample is taken with replacement from each group (here ESCs and control), the sample means are calculated, and their difference is taken.\nThe entire process is repeated multiple times to produce a bootstrap distribution of the difference in sample means (*without* the null hypothesis assumption).\n\n@fig-bootexamsci displays the variability of the differences in means with the 90% percentile and SE CIs super imposed.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Histogram of differences in means after 1,000 bootstrap samples from each\nof the two groups. The observed difference is plotted as a black vertical line at\n7.83. The blue dashed and red dotted lines provide the bootstrap percentile and\nboostrap SE confidence intervals, respectively, for the difference in true population\nmeans.\n](20-inference-two-means_files/figure-html/fig-bootexamsci-1.png){#fig-bootexamsci fig-alt='Histogram of differences in means after 1,000 bootstrap samples from each\nof the two groups. The observed difference is plotted as a black vertical line at\n7.83. The blue dashed and red dotted lines provide the bootstrap percentile and\nboostrap SE confidence intervals, respectively, for the difference in true population\nmeans.' width=90%}\n:::\n:::\n\n\n::: {.guidedpractice data-latex=\"\"}\nUsing the histogram of bootstrapped difference in means, estimate the standard error of the differences in sample means, $\\bar{x}_{ESC} - \\bar{x}_{Control}.$[^20-inference-two-means-3] \n:::\n\n[^20-inference-two-means-3]: The point estimate of the population difference ($\\bar{x}_{ESC} - \\bar{x}_{Control}$) is 7.83.\n\n::: {.workedexample data-latex=\"\"}\nChoose one of the bootstrap confidence intervals for the true difference in average pumping capacity, $\\mu_{ESC} - \\mu_{Control}.$ Does the interval show that there is a difference across the two treatments?\n\n------------------------------------------------------------------------\n\nBecause neither of the 90% intervals (either percentile or SE) above overlap zero (note that zero is never one of the bootstrapped differences so 95% and 99% intervals would have given the same conclusion!), we conclude that the ESC treatment is substantially better with respect to heart pumping capacity than the treatment.\n\nBecause the study is a randomized controlled experiment, we can conclude that it is the treatment (ESC) which is causing the change in pumping capacity.\n:::\n\n## Mathematical model for testing the difference in means {#sec-math2samp}\n\nEvery year, the US releases to the public a large dataset containing information on births recorded in the country.\nThis dataset has been of interest to medical researchers who are studying the relation between habits and practices of expectant mothers and the birth of their children.\nWe will work with a random sample of 1,000 cases from the dataset released in 2014.\n\n::: {.data data-latex=\"\"}\nThe [`births14`](http://openintrostat.github.io/openintro/reference/births14.html) data can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.\n:::\n\n### Observed data\n\nFour cases from this dataset are represented in @tbl-babySmokeDF.\nWe are particularly interested in two variables: `weight` and `smoke`.\nThe `weight` variable represents the weights of the newborns and the `smoke` variable describes which mothers smoked during pregnancy.\n\n\n::: {#tbl-babySmokeDF .cell tbl-cap='Four cases from the `births14` dataset. The emoty cells indicate missing data.'}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n
fage mage weeks visits gained weight sex habit
34 34 37 14 28 6.96 male nonsmoker
36 31 41 12 41 8.86 female nonsmoker
37 36 37 10 28 7.51 female nonsmoker
16 38 29 6.19 male nonsmoker
\n\n`````\n:::\n:::\n\n\nWe would like to know, is there convincing evidence that newborns from mothers who smoke have a different average birth weight than newborns from mothers who do not smoke?\nWe will use data from this sample to try to answer this question.\n\n::: {.workedexample data-latex=\"\"}\nSet up appropriate hypotheses to evaluate whether there is a relationship between a mother smoking and average birth weight.\n\n------------------------------------------------------------------------\n\nThe null hypothesis represents the case of no difference between the groups.\n\n- $H_0:$ There is no difference in average birth weight for newborns from mothers who did and did not smoke. In statistical notation: $\\mu_{n} - \\mu_{s} = 0,$ where $\\mu_{n}$ represents non-smoking mothers and $\\mu_s$ represents mothers who smoked.\n- $H_A:$ There is some difference in average newborn weights from mothers who did and did not smoke $(\\mu_{n} - \\mu_{s} \\neq 0).$\n:::\n\n@tbl-births14-summary-stats displays sample statistics from the data.\nWe can see that the average birth weight of babies born to smoker moms is lower than those born to nonsmoker moms.\n\n\n::: {#tbl-births14-summary-stats .cell tbl-cap='Summary statistics for the `births14` dataset.'}\n::: {.cell-output-display}\n`````{=html}\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n\n
Habit n Mean SD
nonsmoker 867 7.27 1.23
smoker 114 6.68 1.60
\n\n`````\n:::\n:::\n\n\n### Variability of the statistic\n\nWe check the two conditions necessary to model the difference in sample means using the $t$-distribution.\n\n- Because the data come from a simple random sample, the observations are independent, both within and between samples.\n- With both groups over 30 observations, we inspect the data in @fig-babySmokePlotOfTwoGroupsToExamineSkew for any particularly extreme outliers and find none.\n\nSince both conditions are satisfied, the difference in sample means may be modeled using a $t$-distribution.\n\n\n::: {.cell}\n::: {.cell-output-display}\n![The top panel represents birth weights for infants whose mothers smoked during\npregnancy. The bottom panel represents the birth weights for infants whose mothers\nwho did not smoke during pregnancy.\n](20-inference-two-means_files/figure-html/fig-babySmokePlotOfTwoGroupsToExamineSkew-1.png){#fig-babySmokePlotOfTwoGroupsToExamineSkew fig-alt='The top panel represents birth weights for infants whose mothers smoked during\npregnancy. The bottom panel represents the birth weights for infants whose mothers\nwho did not smoke during pregnancy.' width=90%}\n:::\n:::\n\n\n::: {.guidedpractice data-latex=\"\"}\nThe summary statistics in @tbl-births14-summary-stats may be useful for this Guided Practice.\nWhat is the point estimate of the population difference, $\\mu_{n} - \\mu_{s}$?[^20-inference-two-means-4]\n:::\n\n[^20-inference-two-means-4]: The point estimate of the population difference ($\\bar{x}_{n} - \\bar{x}_{s}$) is 0.59.\n\n### Observed statistic vs. null statistics\n\n::: {.important data-latex=\"\"}\n**The test statistic for comparing two means is a T.**\n\nThe T score is a ratio of how the groups differ as compared to how the observations within a group vary.\n\n$$T = \\frac{(\\bar{x}_1 - \\bar{x}_2) - 0}{\\sqrt{s_1^2/n_1 + s_2^2/n_2}}$$\n\nWhen the null hypothesis is true and the conditions are met, T has a t-distribution with $df = min(n_1 - 1, n_2 -1).$\n\nConditions:\n\n- Independent observations within and between groups.\n- Large samples and no extreme outliers.\n:::\n\n\n\n\n\n::: {.guidedpractice data-latex=\"\"}\nCompute the standard error of the point estimate for the average difference between the weights of babies born to nonsmoker and smoker mothers.[^20-inference-two-means-5]\n:::\n\n[^20-inference-two-means-5]: $SE(\\bar{x}_{n} - \\bar{x}_{s}) = \\sqrt{s^2_{n}/ n_{n} + s^2_{s}/n_{s}}\\\\ = \\sqrt{1.23^2/867 + 1.60^2/114} = 0.16$\n\n::: {.workedexample data-latex=\"\"}\nComplete the hypothesis test started in the previous Example and Guided Practice on `births14` dataset and research question.\nUse a discernibility level of $\\alpha=0.05.$ For reference, $\\bar{x}_{n} - \\bar{x}_{s} = 0.59,$ $SE = 0.16,$ and the sample sizes were $n_n = 867$ and $n_s = 114.$\n\n------------------------------------------------------------------------\n\nWe can find the test statistic for this test using the previous information:\n\n$$T = \\frac{\\ 0.59 - 0\\ }{0.16} = 3.69$$\n\nWe find the single tail area using software.\nWe'll use the smaller of $n_n - 1 = 866$ and $n_s - 1 = 113$ as the degrees of freedom: $df = 113.$ The one tail area is roughly 0.00017; doubling this value gives the two-tail area and p-value, 0.00034.\n\nThe p-value is much smaller than the discernibility level, 0.05, so we reject the null hypothesis.\nThe data provide is convincing evidence of a difference in the average weights of babies born to mothers who smoked during pregnancy and those who did not.\n:::\n\nThis result is likely not surprising.\nWe all know that smoking is bad for you and you've probably also heard that smoking during pregnancy is not just bad for the mother but also for the baby as well.\nIn fact, some in the tobacco industry actually had the audacity to tout that as a *benefit* of smoking:\n\n> *It's true. The babies born from women who smoke are smaller, but they're just as healthy as the babies born from women who do not smoke. And some women would prefer having smaller babies.* - Joseph Cullman, Philip Morris' Chairman of the Board on CBS' *Face the Nation*, Jan 3, 1971\n\nFurthermore, health differences between babies born to mothers who smoke and those who do not are not limited to weight differences.[^20-inference-two-means-6]\n\n[^20-inference-two-means-6]: You can watch an episode of John Oliver on [*Last Week Tonight*](youtu.be/6UsHHOCH4q8) to explore the present day offenses of the tobacco industry.\n Please be aware that there is some adult language.\n\nA small note on the power of the independent t-test (recall the discussion of power in @sec-pow). It turns out that the independent t-test given here is often less powerful than the paired t-test discussed in @sec-mathpaired. That said, depending on how the data are collected, we don't always have mechanism for pairing the data and reducing the inherent variability across observations.\n\n## Mathematical model for estimating the difference in means\n\n### Observed data\n\nAs with hypothesis testing, for the question of whether we can model the difference using a $t$-distribution, we'll need to check new conditions.\nLike the 2-proportion cases, we will require a more robust version of independence so we are confident the two groups are also independent.\nSecondly, we also check for normality in each group separately, which in practice is a check for outliers.\n\n\n\n\n\n\\index{point estimate}\n\n::: {.important data-latex=\"\"}\n**Using the** $t$**-distribution for a difference in means.**\n\nThe $t$-distribution can be used for inference when working with the standardized difference of two means if\n\n- *Independence* (extended). The data are independent within and between the two groups, e.g., the data come from independent random samples or from a randomized experiment.\n- *Normality*. We check the outliers for each group separately.\n\nThe standard error may be computed as\n\n$$SE = \\sqrt{\\frac{\\sigma_1^2}{n_1} + \\frac{\\sigma_2^2}{n_2}}$$\n\nThe official formula for the degrees of freedom is quite complex and is generally computed using software, so instead you may use the smaller of $n_1 - 1$ and $n_2 - 1$ for the degrees of freedom if software isn't readily available.\n:::\n\nRecall that the margin of error is defined by the standard error.\nThe margin of error for $\\bar{x}_1 - \\bar{x}_2$ can be directly obtained from $SE(\\bar{x}_1 - \\bar{x}_2).$\n\n::: {.important data-latex=\"\"}\n**Margin of error for** $\\bar{x}_1 - \\bar{x}_2.$\n\nThe margin of error is $t^\\star_{df} \\times \\sqrt{\\frac{s_1^2}{n_1} + \\frac{s_2^2}{n_2}}$ where $t^\\star_{df}$ is calculated from a specified percentile on the t-distribution with *df* degrees of freedom.\n:::\n\n\n\n\n\n\\index{standard error (SE)!difference in means}\n\n### Variability of the statistic\n\n::: {.workedexample data-latex=\"\"}\nCan the $t$-distribution be used to make inference using the point estimate, $\\bar{x}_{esc} - \\bar{x}_{control} = 7.83$?\n\n------------------------------------------------------------------------\n\nFirst, we check for independence.\nBecause the sheep were randomized into the groups, independence within and between groups is satisfied.\n\n@fig-stem-cell-histograms does not reveal any clear outliers in either group.\n(The ESC group does look a bit more variable, but this is not the same as having clear outliers.)\n\nWith both conditions met, we can use the $t$-distribution to model the difference of sample means.\n:::\n\n\n::: {.cell}\n::: {.cell-output-display}\n![Histograms for the difference in heart pumping function after a heart attack\nfor both the treatment group (ESC, which received an the embryonic stem cell\ntreatment) and the control group (which did not receive the treatment).\n](20-inference-two-means_files/figure-html/fig-stem-cell-histograms-1.png){#fig-stem-cell-histograms fig-alt='Histograms for the difference in heart pumping function after a heart attack\nfor both the treatment group (ESC, which received an the embryonic stem cell\ntreatment) and the control group (which did not receive the treatment).' width=90%}\n:::\n:::\n\n\nGenerally, we use statistical software to find the appropriate degrees of freedom, or if software isn't available, we can use the smaller of $n_1 - 1$ and $n_2 - 1$ for the degrees of freedom, e.g., if using a $t$-table to find tail areas.\nFor transparency in the Examples and Guided Practice, we'll use the latter approach for finding $df$; in the case of the ESC example, this means we'll use $df = 8.$\n\n::: {.workedexample data-latex=\"\"}\nCalculate a 95% confidence interval for the effect of ESCs on the change in heart pumping capacity of sheep after they've suffered a heart attack.\n\n------------------------------------------------------------------------\n\nWe will use the sample difference and the standard error that we computed earlier:\n\n$$\n\\begin{aligned}\n\\bar{x}_{esc} - \\bar{x}_{control} &= 7.83 \\\\\nSE &= \\sqrt{\\frac{5.17^2}{9} + \\frac{2.76^2}{9}} = 1.95\n\\end{aligned}\n$$\n\nUsing $df = 8,$ we can identify the critical value of $t^{\\star}_{8} = 2.31$ for a 95% confidence interval.\nFinally, we can enter the values into the confidence interval formula:\n\n$$\n\\begin{aligned}\n\\text{point estimate} \\ &\\pm\\ t^{\\star} \\times SE \\\\\n7.83 \\ &\\pm\\ 2.31\\times 1.95 \\\\\n(3.32 \\ &, \\ 12.34)\n\\end{aligned} \n$$\n\nWe are 95% confident that the heart pumping function in sheep that received embryonic stem cells is between 3.32% and 12.34% higher than for sheep that did not receive the stem cell treatment.\n:::\n\n\\clearpage\n\n## Chapter review {#sec-chp20-review}\n\n### Summary\n\nIn this chapter we extended the single mean inferential methods to questions of differences in means.\nYou may have seen parallels from the chapters that extended a single proportion (Chapter \\@ref(inference-one-prop)) to differences in proportions (Chapter \\@ref(inference-two-props)).\nWhen considering differences in sample means (indeed, when considering many quantitative statistics), we use the t-distribution to describe the sampling distribution of the T score (the standardized difference in sample means).\nIdeas of confidence level and type of error which might occur from a hypothesis test conclusion are similar to those seen in other chapters (see [Chapter -@sec-foundations-decision-errors]).\n\n### Terms\n\nWe introduced the following terms in the chapter.\nIf you're not sure what some of these terms mean, we recommend you go back in the text and review their definitions.\nWe are purposefully presenting them in alphabetical order, instead of in order of appearance, so they will be a little more challenging to locate.\nHowever, you should be able to easily spot them as **bolded text**.\n\n\n::: {.cell}\n::: {.cell-output-display}\n`````{=html}\n\n\n \n \n \n \n \n \n \n \n \n \n\n
difference in means SE difference in means t-CI
point estimate T score t-test
\n\n`````\n:::\n:::\n\n\n\\clearpage\n\n## Exercises {#sec-chp20-exercises}\n\nAnswers to odd-numbered exercises can be found in [Appendix -@sec-exercise-solutions-20].\n\n::: {.exercises data-latex=\"\"}\n1. **Experimental baker.** A baker working on perfecting their bagel recipe is experimenting with active dry (AD) and instant (I) yeast.\n They bake a dozen bagels with each type of yeast and score each bagel on a scale of 1 to 10 on how well the bagels rise.\n They come up with the following set of hypotheses for evaluating whether there is a difference in the average rise of bagels baked with active dry and instant yeast.\n What is wrong with the hypotheses as stated?\n\n $$H_0: \\bar{x}_{AD} \\leq \\bar{x}_{I} \\quad \\quad H_A: \\bar{x}_{AD} > \\bar{x}_{I}$$\n\n2. **Fill in the blanks.** We use a \\_\\_\\_ to evaluate if data provide convincing evidence of a difference between two population means and we use a \\_\\_\\_ to estimate this difference.\n\n3. **Diamonds, randomization test.** The prices of diamonds go up as the carat weight increases, but the increase is not smooth.\n For example, the difference between the size of a 0.99 carat diamond and a 1 carat diamond is undetectable to the naked human eye, but the price of a 1 carat diamond tends to be much higher than the price of a 0.99 diamond.\n In this question we use two random samples of diamonds, 0.99 carats and 1 carat, each sample of size 23, and randomize the carat weight to the price values in order compare the average prices of the diamonds to a null distribution.\n In order to be able to compare equivalent units, we first divide the price for each diamond by 100 times its weight in carats.\n That is, for a 0.99 carat diamond, we divide the price by 99.\n or a 1 carat diamond, we divide the price by 100.\n The randomization distribution (with 1,000 repetitions) below describes the null distribution of the difference in sample means (of price per carat) if there really was no difference in the population from which these diamonds came.[^_20-ex-inference-two-means-1]\n [@ggplot2]\n\n ::: {.cell}\n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-21-1.png){width=90%}\n :::\n :::\n\n Using the randomization distribution of the difference in average price per carat (1,000 randomizations were run), conduct a hypothesis test to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat.\n Make sure to state your hypotheses clearly and interpret your results in context of the data.\n [@ggplot2]\n\n4. **Lizards running, randomization test.** In order to assess physiological characteristics of common lizards, data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus).\n The original observed difference in lizard speeds is $\\bar{x}_{Western fence} - \\bar{x}_{Sagebrush} = 0.7 \\mbox{m/sec}.$ The histogram below shows the distribution of average differences when speed has been randomly allocated across lizard species 1,000 times.[^_20-ex-inference-two-means-2]\n [@Adolph:1987]\n\n ::: {.cell}\n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-22-1.png){width=90%}\n :::\n :::\n\n Using the randomization distribution, conduct a hypothesis test to evaluate if there is a difference between the average speed of the Western fence lizard as compared to the Sagebrush lizard.\n Make sure to state your hypotheses clearly and interpret your results in context of the data.\n\n5. **Diamonds, bootstrap interval.** We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat.\n Each sample has 23 diamonds.\n Provided below is a histogram of bootstrap differences in means of price per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat.\n [@ggplot2]\n\n ::: {.cell}\n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-23-1.png){width=90%}\n :::\n :::\n\n a. Using the bootstrap distribution, create a (rough) 95% bootstrap percentile confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat.\n\n b. Using the bootstrap distribution, create a (rough) 95% bootstrap SE confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat.\n Note that the standard error of the bootstrap distribution is 4.64.\n\n6. **Lizards running, bootstrap interval.** We have data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus).\n The bootstrap distribution below describes the variability of difference in means captured from 1,000 bootstrap samples of the lizard data.\n [@Adolph:1987]\n\n ::: {.cell}\n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-24-1.png){width=90%}\n :::\n :::\n\n a. Using the bootstrap distribution, create a (rough) 90% percentile bootrap confidence interval for the true population difference in price per carat for Western fence lizard as compared with Sagebrush lizard.\n\n b. Using the bootstrap distribution, create a (rough) 90% bootstrap SE confidence interval for the true population difference in price per carat for Western fence lizard as compared with Sagebrush lizard.\n\n7. **Weight loss.** You are reading an article in which the researchers have created a 95% confidence interval for the difference in average weight loss for two diets.\n They are 95% confident that the true difference in average weight loss over 6 months for the two diets is somewhere between (1 lb, 25 lbs).\n The authors claim that, \"therefore diet A ($\\bar{x}_A$ = 20 lbs average loss) results in a much larger average weight loss as compared to diet B ($\\bar{x}_B$ = 7 lbs average loss).\" Comment on the authors' claim.\n\n8. **Possible randomized means.** Data were collected on data from two groups (A and B).\n There were 3 measurements taken on Group A and two measurements\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Group Measurement 1 Measurement 2 Measurement 3
A 1 15 5
B 7 3
\n \n `````\n :::\n :::\n\n If the data are (repeatedly) randomly allocated across the two conditions, provide the following: (1) the values which are assigned to group A, (2) the values which are assigned to group B, and (3) the difference in averages $(\\bar{x}_A - \\bar{x}_B)$ for each of the following:\n\n a. When the randomized difference in averages is as big as possible.\n\n b. When the randomized difference in averages is as small as possible (a big in magnitude negative number).\n\n c. When the randomized difference in averages is as close to zero as possible.\n\n d. When the observed values are randomly assigned to the two groups, to which of the previous parts would you expect the difference in means to fall closest?\n Explain your reasoning.\n\n9. **Diamonds, mathematical test.** We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat.\n Each sample has 23 diamonds.\n Sample statistics for the price per carat of diamonds in each sample are provided below.\n Conduct a hypothesis test using a mathematical model to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat Make sure to state your hypotheses clearly, check relevant conditions, and interpret your results in context of the data.\n [@ggplot2]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Mean SD n
0.99 carats $44.51 $13.32 23
1 carat $57.20 $18.19 23
\n \n `````\n :::\n \n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-26-1.png){width=90%}\n :::\n :::\n\n10. **A/B testing.** A/B testing is a user experience research methodology where two variants of a page are shown to users at random.\n A company wants to evaluate whether users will spend more time, on average, on Page A or Page B using an A/B test.\n Two user experience designers at the company, Lucie and Müge, are tasked with conducting the analysis of the data collected.\n They agree on how the null hypothesis should be set: on average, users spend the same amount of time on Page A and Page B. Lucie believes that Page B will provide a better experience for users and hence wants to use a one-tailed test, Müge believes that a two-tailed test would be a better choice.\n Which designer do you agree with, and why?\n\n11. **Diamonds, mathematical interval.** We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat.\n Each sample has 23 diamonds.\n Sample statistics for the price per carat of diamonds in each sample are provided below.\n Assuming that the conditions for conducting inference using a mathematical model are satisfied, construct a 95% confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat.\n [@ggplot2]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Mean SD n
0.99 carats $44.51 $13.32 23
1 carat $57.20 $18.19 23
\n \n `````\n :::\n :::\n\n12. **True / False: comparing means.** Determine if the following statements are true or false, and explain your reasoning for statements you identify as false.\n\n a. As the degrees of freedom increases, the $t$-distribution approaches normality.\n\n b. If a 95% confidence interval for the difference between two population means contains 0, a 99% confidence interval calculated based on the same two samples will also contain 0.\n\n c. If a 95% confidence interval for the difference between two population means contains 0, a 90% confidence interval calculated based on the same two samples will also contain 0.\n\n13. **Difference of means.** Suppose we will collect two random samples from the following distributions.\n In each of the parts below, consider the sample means $\\bar{x}_1$ and $\\bar{x}_2$ that we might observe from these two samples.\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Mean Standard deviation Sample size
Sample 1 15 20 50
Sample 2 20 10 30
\n \n `````\n :::\n :::\n\n a. What is the associated mean and standard deviation of $\\bar{x}_1$?\n\n b. What is the associated mean and standard deviation of $\\bar{x}_2$?\n\n c. Calculate and interpret the mean and standard deviation associated with the difference in sample means for the two groups, $\\bar{x}_2 - \\bar{x}_1$.\n\n d. How are the standard deviations from parts (a), (b), and (c) related?\n\n14. **Mindfulness intervention for nurses.** In order to address extremely challenging and stressful situations for nurses in intensive care units, a group of researchers ran a mindfulness-based intervention (MBI) study on 60 nurses working in three hospitals in El-Beheira, Egypt.\n The participants were randomly allocated to one of the two groups: the treatment group (MBI) received 8 MBI sessions and the control group received no intervention.\n The nurses' emotional exhaustion was measured using 9 items from a questionnaire of the Maslach Burnout Inventory-Human Services Survey for Medical Personnel; the questions are recorded on a Likert scale where 0 indicated \"Never\" and 6 indicates \"Every day\".\n Nurses in the treatment group had an emotional exhaustion score of 15.47, with a standard deviation of 4.44, and nurses in the control group had an emotional exhaustion score of 32.43, with a standard deviation of 8.87.\n Do these data provide convincing evidence that the emotional exhaustion decrease is different for the patients in the treatment group compared to the control group?\n Assume that conditions for conducting inference using mathematical models are satisfied.\n [@Othman:2023]\n\n15. **Chicken diet: horsebean vs. linseed.** Chicken farming is a multi-billion dollar industry, and any methods that increase the growth rate of young chicks can reduce consumer costs while increasing company profits, possibly by millions of dollars.\n An experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens.\n Newly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement.\n In this exercise we consider chicks that were fed horsebean and linseed.\n Below are some summary statistics from this dataset along with box plots showing the distribution of weights by feed type.[^_20-ex-inference-two-means-3]\n [@data:chickwts]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Feed type Mean SD n
horsebean 160.20 38.63 10
linseed 218.75 52.24 12
\n \n `````\n :::\n \n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-29-1.png){width=100%}\n :::\n :::\n\n a. Describe the distributions of weights of chickens that were fed horsebean and linseed.\n\n b. Do these data provide strong evidence that the average weights of chickens that were fed linseed and horsebean are different?\n Use a 5% discernibility level.\n\n c. What type of error might we have committed?\n Explain.\n\n d. Would your conclusion change if we used $\\alpha = 0.01$?\n\n16. **Fuel efficiency in the city.** Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year.\n Below are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021.\n Do these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average city mileage?[^_20-ex-inference-two-means-4]\n [@data:epa2021]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
CITY Mean SD n
Automatic 17.4 3.44 25
Manual 22.7 4.58 25
\n \n `````\n :::\n \n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-30-1.png){width=90%}\n :::\n :::\n\n17. **Chicken diet: casein vs. soybean.** Casein is a common weight gain supplement for humans.\n Does it have an effect on chickens?\n An experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens.\n Newly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement.\n In this exercise we consider chicks that were fed casein and soybean.\n Assume that the conditions for conducting inference using mathematical models are met, and using the data provided below, test the hypothesis that the average weight of chickens that were fed casein is different than the average weight of chickens that were fed soybean.\n If your hypothesis test yields a statistically discernible result, discuss whether or not the higher average weight of chickens can be attributed to the casein diet.\n [@data:chickwts]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Feed type Mean SD n
casein 323.58 64.43 12
soybean 246.43 54.13 14
\n \n `````\n :::\n :::\n\n18. **Fuel efficiency on the highway.** Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year.\n Below are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021.\n Do these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average highway mileage?\n [@data:epa2021]\n\n ::: {.cell}\n ::: {.cell-output-display}\n `````{=html}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
HIGHWAY Mean SD n
Automatic 23.7 3.90 25
Manual 30.9 5.13 25
\n \n `````\n :::\n \n ::: {.cell-output-display}\n ![](20-inference-two-means_files/figure-html/unnamed-chunk-32-1.png){width=90%}\n :::\n :::\n\n19. **Gaming, distracted eating, and intake.** A group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups.\n The treatment group ate lunch while playing solitaire, and the control group ate lunch without any added distractions.\n Patients in the treatment group ate 52.1 grams of biscuits, with a standard deviation of 45.1 grams, and patients in the control group ate 27.1 grams of biscuits, with a standard deviation of 26.4 grams.\n Do these data provide convincing evidence that the average food intake (measured in amount of biscuits consumed) is different for the patients in the treatment group compared to the control group?\n Assume that conditions for conducting inference using mathematical models are satisfied.\n [@Oldham:2011]\n\n20. **Gaming, distracted eating, and recall.** A group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups.\n The 22 patients in the treatment group who ate their lunch while playing solitaire were asked to do a serial-order recall of the food lunch items they ate.\n The average number of items recalled by the patients in this group was 4.\n 9, with a standard deviation of 1.8.\n The average number of items recalled by the patients in the control group (no distraction) was 6.1, with a standard deviation of 1.8.\n Do these data provide strong evidence that the average numbers of food items recalled by the patients in the treatment and control groups are different?\n Assume that conditions for conducting inference using mathematical models are satisfied.\n [@Oldham:2011]\n\n[^_20-ex-inference-two-means-1]: The [`diamonds`](https://ggplot2.tidyverse.org/reference/diamonds.html) data used in this exercise can be found in the [**ggplot2**](http://ggplot2.tidyverse.org/) R package.\n\n[^_20-ex-inference-two-means-2]: The [`lizard_run`](http://openintrostat.github.io/openintro/reference/lizard_run.html) data used in this exercise can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.\n\n[^_20-ex-inference-two-means-3]: The [`chickwts`](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/chickwts.html) data used in this exercise can be found in the [**datasets**](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html) R package.\n\n[^_20-ex-inference-two-means-4]: The [`epa2021`](http://openintrostat.github.io/openintro/reference/epa2021.html) data used in this exercise can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.\n\n\n:::\n", "supporting": [ "20-inference-two-means_files" ], diff --git a/_freeze/20-inference-two-means/figure-html/fig-bootexamsci-1.png b/_freeze/20-inference-two-means/figure-html/fig-bootexamsci-1.png index f8c496cc..f957c95d 100644 Binary files a/_freeze/20-inference-two-means/figure-html/fig-bootexamsci-1.png and b/_freeze/20-inference-two-means/figure-html/fig-bootexamsci-1.png differ diff --git a/exercises/_20-ex-inference-two-means.qmd b/exercises/_20-ex-inference-two-means.qmd index 9eaad60f..c7001494 100644 --- a/exercises/_20-ex-inference-two-means.qmd +++ b/exercises/_20-ex-inference-two-means.qmd @@ -1,27 +1,26 @@ -1. **Experimental baker.** -A baker working on perfecting their bagel recipe is experimenting with active dry (AD) and instant (I) yeast. -They bake a dozen bagels with each type of yeast and score each bagel on a scale of 1 to 10 on how well the bagels rise. -They come up with the following set of hypotheses for evaluating whether there is a difference in the average rise of bagels baked with active dry and instant yeast. -What is wrong with the hypotheses as stated? +1. **Experimental baker.** A baker working on perfecting their bagel recipe is experimenting with active dry (AD) and instant (I) yeast. + They bake a dozen bagels with each type of yeast and score each bagel on a scale of 1 to 10 on how well the bagels rise. + They come up with the following set of hypotheses for evaluating whether there is a difference in the average rise of bagels baked with active dry and instant yeast. + What is wrong with the hypotheses as stated? $$H_0: \bar{x}_{AD} \leq \bar{x}_{I} \quad \quad H_A: \bar{x}_{AD} > \bar{x}_{I}$$ -1. **Fill in the blanks.** -We use a \_\_\_ to evaluate if data provide convincing evidence of a difference between two population means and we use a \_\_\_ to estimate this difference. +2. **Fill in the blanks.** We use a \_\_\_ to evaluate if data provide convincing evidence of a difference between two population means and we use a \_\_\_ to estimate this difference. -1. **Diamonds, randomization test.** -The prices of diamonds go up as the carat weight increases, but the increase is not smooth. -For example, the difference between the size of a 0.99 carat diamond and a 1 carat diamond is undetectable to the naked human eye, but the price of a 1 carat diamond tends to be much higher than the price of a 0.99 diamond. -In this question we use two random samples of diamonds, 0.99 carats and 1 carat, each sample of size 23, and randomize the carat weight to the price values in order compare the average prices of the diamonds to a null distribution. -In order to be able to compare equivalent units, we first divide the price for each diamond by 100 times its weight in carats. -That is, for a 0.99 carat diamond, we divide the price by 99. or a 1 carat diamond, we divide the price by 100. -The randomization distribution (with 1,000 repetitions) below describes the null distribution of the difference in sample means (of price per carat) if there really was no difference in the population from which these diamonds came.^[The [`diamonds`](https://ggplot2.tidyverse.org/reference/diamonds.html) data used in this exercise can be found in the [**ggplot2**](http://ggplot2.tidyverse.org/) R package.] [@ggplot2] +3. **Diamonds, randomization test.** The prices of diamonds go up as the carat weight increases, but the increase is not smooth. + For example, the difference between the size of a 0.99 carat diamond and a 1 carat diamond is undetectable to the naked human eye, but the price of a 1 carat diamond tends to be much higher than the price of a 0.99 diamond. + In this question we use two random samples of diamonds, 0.99 carats and 1 carat, each sample of size 23, and randomize the carat weight to the price values in order compare the average prices of the diamonds to a null distribution. + In order to be able to compare equivalent units, we first divide the price for each diamond by 100 times its weight in carats. + That is, for a 0.99 carat diamond, we divide the price by 99. + or a 1 carat diamond, we divide the price by 100. + The randomization distribution (with 1,000 repetitions) below describes the null distribution of the difference in sample means (of price per carat) if there really was no difference in the population from which these diamonds came.[^_20-ex-inference-two-means-1] + [@ggplot2] ```{r} library(tidyverse) library(openintro) library(infer) - + set.seed(47) diamonds_sample <- diamonds %>% filter(carat %in% c(1, 0.99)) %>% @@ -31,7 +30,7 @@ The randomization distribution (with 1,000 repetitions) below describes the null ppc = price/carat/100, carat = if_else(carat == 1, paste(carat, "carat"), paste(carat, "carats")) ) - + diamonds_sample %>% specify(ppc ~ carat) %>% hypothesize(null = "independence") %>% @@ -47,16 +46,18 @@ The randomization distribution (with 1,000 repetitions) below describes the null ) ``` - Using the randomization distribution of the difference in average price per carat (1,000 randomizations were run), conduct a hypothesis test to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat. Make sure to state your hypotheses clearly and interpret your results in context of the data. [@ggplot2] + Using the randomization distribution of the difference in average price per carat (1,000 randomizations were run), conduct a hypothesis test to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat. + Make sure to state your hypotheses clearly and interpret your results in context of the data. + [@ggplot2] -1. **Lizards running, randomization test.** -In order to assess physiological characteristics of common lizards, data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus). -The original observed difference in lizard speeds is $\bar{x}_{Western fence} - \bar{x}_{Sagebrush} = 0.7 \mbox{m/sec}.$ The histogram below shows the distribution of average differences when speed has been randomly allocated across lizard species 1,000 times.^[The [`lizard_run`](http://openintrostat.github.io/openintro/reference/lizard_run.html) data used in this exercise can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.] [@Adolph:1987] +4. **Lizards running, randomization test.** In order to assess physiological characteristics of common lizards, data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus). + The original observed difference in lizard speeds is $\bar{x}_{Western fence} - \bar{x}_{Sagebrush} = 0.7 \mbox{m/sec}.$ The histogram below shows the distribution of average differences when speed has been randomly allocated across lizard species 1,000 times.[^_20-ex-inference-two-means-2] + [@Adolph:1987] ```{r} library(tidyverse) library(openintro) - + set.seed(47) lizard_run %>% specify(top_speed ~ common_name) %>% @@ -72,21 +73,21 @@ The original observed difference in lizard speeds is $\bar{x}_{Western fence} - y = "Count" ) ``` - - Using the randomization distribution, conduct a hypothesis test to evaluate if there is a difference between the average speed of the Western fence lizard as compared to the Sagebrush lizard. Make sure to state your hypotheses clearly and interpret your results in context of the data. -1. **Diamonds, bootstrap interval.** -We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. -Each sample has 23 diamonds. -Provided below is a histogram of bootstrap differences in means of price per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat. -[@ggplot2] + Using the randomization distribution, conduct a hypothesis test to evaluate if there is a difference between the average speed of the Western fence lizard as compared to the Sagebrush lizard. + Make sure to state your hypotheses clearly and interpret your results in context of the data. + +5. **Diamonds, bootstrap interval.** We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. + Each sample has 23 diamonds. + Provided below is a histogram of bootstrap differences in means of price per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat. + [@ggplot2] ```{r} library(tidyverse) library(kableExtra) library(openintro) library(infer) - + set.seed(47) diamonds_100_99_sample <- diamonds %>% filter(carat %in% c(1, 0.99)) %>% @@ -109,20 +110,21 @@ Provided below is a histogram of bootstrap differences in means of price per car y = "Count" ) ``` - - a. Using the bootstrap distribution, create a (rough) 95% bootstrap percentile confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. - - b. Using the bootstrap distribution, create a (rough) 95% bootstrap SE confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. Note that the standard error of the bootstrap distribution is 4.64. - -1. **Lizards running, bootstrap interval.** -We have data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus). -The bootstrap distribution below describes the variability of difference in means captured from 1,000 bootstrap samples of the lizard data. [@Adolph:1987] - + + a. Using the bootstrap distribution, create a (rough) 95% bootstrap percentile confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. + + b. Using the bootstrap distribution, create a (rough) 95% bootstrap SE confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. + Note that the standard error of the bootstrap distribution is 4.64. + +6. **Lizards running, bootstrap interval.** We have data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus). + The bootstrap distribution below describes the variability of difference in means captured from 1,000 bootstrap samples of the lizard data. + [@Adolph:1987] + ```{r} library(tidyverse) library(openintro) library(infer) - + set.seed(47) lizard_run %>% specify(top_speed ~ common_name) %>% @@ -136,24 +138,23 @@ The bootstrap distribution below describes the variability of difference in mean y = "Count" ) ``` - - a. Using the bootstrap distribution, create a (rough) 90% percentile bootrap confidence interval for the true population difference in price per carat for Western fence lizard as compared with Sagebrush lizard. - - b. Using the bootstrap distribution, create a (rough) 90% bootstrap SE confidence interval for the true population difference in price per carat for Western fence lizard as compared with Sagebrush lizard. -1. **Weight loss.** -You are reading an article in which the researchers have created a 95% confidence interval for the difference in average weight loss for two diets. -They are 95% confident that the true difference in average weight loss over 6 months for the two diets is somewhere between (1 lb, 25 lbs). -The authors claim that, "therefore diet A ($\bar{x}_A$ = 20 lbs average loss) results in a much larger average weight loss as compared to diet B ($\bar{x}_B$ = 7 lbs average loss)." Comment on the authors' claim. + a. Using the bootstrap distribution, create a (rough) 90% percentile bootrap confidence interval for the true population difference in price per carat for Western fence lizard as compared with Sagebrush lizard. + + b. Using the bootstrap distribution, create a (rough) 90% bootstrap SE confidence interval for the true population difference in price per carat for Western fence lizard as compared with Sagebrush lizard. + +7. **Weight loss.** You are reading an article in which the researchers have created a 95% confidence interval for the difference in average weight loss for two diets. + They are 95% confident that the true difference in average weight loss over 6 months for the two diets is somewhere between (1 lb, 25 lbs). + The authors claim that, "therefore diet A ($\bar{x}_A$ = 20 lbs average loss) results in a much larger average weight loss as compared to diet B ($\bar{x}_B$ = 7 lbs average loss)." Comment on the authors' claim. -1. **Possible randomized means.** -Data were collected on data from two groups (A and B). There were 3 measurements taken on Group A and two measurements +8. **Possible randomized means.** Data were collected on data from two groups (A and B). + There were 3 measurements taken on Group A and two measurements ```{r} library(knitr) library(kableExtra) library(tidyverse) - + tribble( ~Group, ~`Measurement 1`, ~`Measurement 2`, ~`Measurement 3`, "A", 1, 15, 5, @@ -164,30 +165,30 @@ Data were collected on data from two groups (A and B). There were 3 measurements latex_options = "HOLD_position", full_width = FALSE) ``` - - If the data are (repeatedly) randomly allocated across the two conditions, provide the following: (1) the values which are assigned to group A, (2) the values which are assigned to group B, and (3) the difference in averages $(\bar{x}_A - \bar{x}_B)$ for each of the following: - - a. When the randomized difference in averages is as big as possible. - - b. When the randomized difference in averages is as small as possible (a big in magnitude negative number). - - c. When the randomized difference in averages is as close to zero as possible. - - d. When the observed values are randomly assigned to the two groups, to which of the previous parts would you expect the difference in means to fall closest? Explain your reasoning. - -1. **Diamonds, mathematical test.** -We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. -Each sample has 23 diamonds. -Sample statistics for the price per carat of diamonds in each sample are provided below. -Conduct a hypothesis test using a mathematical model to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat -Make sure to state your hypotheses clearly, check relevant conditions, and interpret your results in context of the data. [@ggplot2] + + If the data are (repeatedly) randomly allocated across the two conditions, provide the following: (1) the values which are assigned to group A, (2) the values which are assigned to group B, and (3) the difference in averages $(\bar{x}_A - \bar{x}_B)$ for each of the following: + + a. When the randomized difference in averages is as big as possible. + + b. When the randomized difference in averages is as small as possible (a big in magnitude negative number). + + c. When the randomized difference in averages is as close to zero as possible. + + d. When the observed values are randomly assigned to the two groups, to which of the previous parts would you expect the difference in means to fall closest? + Explain your reasoning. + +9. **Diamonds, mathematical test.** We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. + Each sample has 23 diamonds. + Sample statistics for the price per carat of diamonds in each sample are provided below. + Conduct a hypothesis test using a mathematical model to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat Make sure to state your hypotheses clearly, check relevant conditions, and interpret your results in context of the data. + [@ggplot2] ```{r} #| fig-asp: 0.4 library(tidyverse) library(scales) library(kableExtra) - + set.seed(47) diamonds_100_99_sample <- diamonds %>% filter(carat %in% c(1, 0.99)) %>% @@ -197,7 +198,7 @@ Make sure to state your hypotheses clearly, check relevant conditions, and inter ppc = price/carat/100, carat = if_else(carat == 1, paste(carat, "carat"), paste(carat, "carats")) ) - + diamonds_100_99_summary <- diamonds_100_99_sample %>% group_by(carat) %>% summarise( @@ -216,32 +217,30 @@ Make sure to state your hypotheses clearly, check relevant conditions, and inter latex_options = "HOLD_position", full_width = FALSE) %>% column_spec(1:4, width = "6em") - + ggplot(diamonds_100_99_sample, aes(y = fct_rev(carat), x = ppc)) + geom_boxplot() + labs(y = NULL, x = "Price per carat (USD)") + scale_x_continuous(labels = label_dollar()) ``` -1. **A/B testing.** -A/B testing is a user experience research methodology where two variants of a page are shown to users at random. -A company wants to evaluate whether users will spend more time, on average, on Page A or Page B using an A/B test. -Two user experience designers at the company, Lucie and Müge, are tasked with conducting the analysis of the data collected. -They agree on how the null hypothesis should be set: on average, users spend the same amount of time on Page A and Page B. -Lucie believes that Page B will provide a better experience for users and hence wants to use a one-tailed test, Müge believes that a two-tailed test would be a better choice. -Which designer do you agree with, and why? +10. **A/B testing.** A/B testing is a user experience research methodology where two variants of a page are shown to users at random. + A company wants to evaluate whether users will spend more time, on average, on Page A or Page B using an A/B test. + Two user experience designers at the company, Lucie and Müge, are tasked with conducting the analysis of the data collected. + They agree on how the null hypothesis should be set: on average, users spend the same amount of time on Page A and Page B. Lucie believes that Page B will provide a better experience for users and hence wants to use a one-tailed test, Müge believes that a two-tailed test would be a better choice. + Which designer do you agree with, and why? -1. **Diamonds, mathematical interval.** -We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. -Each sample has 23 diamonds. -Sample statistics for the price per carat of diamonds in each sample are provided below. -Assuming that the conditions for conducting inference using a mathematical model are satisfied, construct a 95% confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. [@ggplot2] +11. **Diamonds, mathematical interval.** We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. + Each sample has 23 diamonds. + Sample statistics for the price per carat of diamonds in each sample are provided below. + Assuming that the conditions for conducting inference using a mathematical model are satisfied, construct a 95% confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. + [@ggplot2] ```{r} library(tidyverse) library(scales) library(kableExtra) - + set.seed(47) diamonds_100_99_sample <- diamonds %>% filter(carat %in% c(1, 0.99)) %>% @@ -251,7 +250,7 @@ Assuming that the conditions for conducting inference using a mathematical model ppc = price/carat/100, carat = if_else(carat == 1, paste(carat, "carat"), paste(carat, "carats")) ) - + diamonds_100_99_summary <- diamonds_100_99_sample %>% group_by(carat) %>% summarise( @@ -272,29 +271,27 @@ Assuming that the conditions for conducting inference using a mathematical model column_spec(1:4, width = "6em") ``` -1. **True / False: comparing means.** -Determine if the following statements are true or false, and explain your reasoning for statements you identify as false. +12. **True / False: comparing means.** Determine if the following statements are true or false, and explain your reasoning for statements you identify as false. a. As the degrees of freedom increases, the $t$-distribution approaches normality. b. If a 95% confidence interval for the difference between two population means contains 0, a 99% confidence interval calculated based on the same two samples will also contain 0. - + c. If a 95% confidence interval for the difference between two population means contains 0, a 90% confidence interval calculated based on the same two samples will also contain 0. -1. **Difference of means.** -Suppose we will collect two random samples from the following distributions. -In each of the parts below, consider the sample means $\bar{x}_1$ and $\bar{x}_2$ that we might observe from these two samples. - +13. **Difference of means.** Suppose we will collect two random samples from the following distributions. + In each of the parts below, consider the sample means $\bar{x}_1$ and $\bar{x}_2$ that we might observe from these two samples. + ```{r} library(tidyverse) library(kableExtra) - + sample_stats <- tribble( ~` `, ~Mean, ~`Standard deviation`, ~`Sample size`, "Sample 1", 15, 20, 50, "Sample 2", 20, 10, 30, ) - + sample_stats %>% kbl(linesep = "", booktabs = TRUE, align = "lccc") %>% kable_styling(bootstrap_options = c("striped", "condensed"), @@ -310,20 +307,20 @@ In each of the parts below, consider the sample means $\bar{x}_1$ and $\bar{x}_2 d. How are the standard deviations from parts (a), (b), and (c) related? -1. **Mindfulness intervention for nurses.** -In order to address extremely challenging and stressful situations for nurses in intensive care units, a group of researchers ran a mindfulness-based intervention (MBI) study on 60 nurses working in three hospitals in El-Beheira, Egypt. -The participants were randomly allocated to one of the two groups: the treatment group (MBI) received 8 MBI sessions and the control group received no intervention. -The nurses' emotional exhaustion was measured using 9 items from a questionnaire of the Maslach Burnout Inventory-Human Services Survey for Medical Personnel; the questions are recorded on a Likert scale where 0 indicated "Never" and 6 indicates "Every day". -Nurses in the treatment group had an emotional exhaustion score of 15.47, with a standard deviation of 4.44, and nurses in the control group had an emotional exhaustion score of 32.43, with a standard deviation of 8.87. -Do these data provide convincing evidence that the emotional exhaustion decrease is different for the patients in the treatment group compared to the control group? -Assume that conditions for conducting inference using mathematical models are satisfied. [@Othman:2023] - -1. **Chicken diet: horsebean vs. linseed.** -Chicken farming is a multi-billion dollar industry, and any methods that increase the growth rate of young chicks can reduce consumer costs while increasing company profits, possibly by millions of dollars. -An experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens. -Newly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement. -In this exercise we consider chicks that were fed horsebean and linseed. -Below are some summary statistics from this dataset along with box plots showing the distribution of weights by feed type.^[The [`chickwts`](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/chickwts.html) data used in this exercise can be found in the [**datasets**](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html) R package.] [@data:chickwts] +14. **Mindfulness intervention for nurses.** In order to address extremely challenging and stressful situations for nurses in intensive care units, a group of researchers ran a mindfulness-based intervention (MBI) study on 60 nurses working in three hospitals in El-Beheira, Egypt. + The participants were randomly allocated to one of the two groups: the treatment group (MBI) received 8 MBI sessions and the control group received no intervention. + The nurses' emotional exhaustion was measured using 9 items from a questionnaire of the Maslach Burnout Inventory-Human Services Survey for Medical Personnel; the questions are recorded on a Likert scale where 0 indicated "Never" and 6 indicates "Every day". + Nurses in the treatment group had an emotional exhaustion score of 15.47, with a standard deviation of 4.44, and nurses in the control group had an emotional exhaustion score of 32.43, with a standard deviation of 8.87. + Do these data provide convincing evidence that the emotional exhaustion decrease is different for the patients in the treatment group compared to the control group? + Assume that conditions for conducting inference using mathematical models are satisfied. + [@Othman:2023] + +15. **Chicken diet: horsebean vs. linseed.** Chicken farming is a multi-billion dollar industry, and any methods that increase the growth rate of young chicks can reduce consumer costs while increasing company profits, possibly by millions of dollars. + An experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens. + Newly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement. + In this exercise we consider chicks that were fed horsebean and linseed. + Below are some summary statistics from this dataset along with box plots showing the distribution of weights by feed type.[^_20-ex-inference-two-means-3] + [@data:chickwts] ```{r} #| out-width: 100% @@ -331,10 +328,10 @@ Below are some summary statistics from this dataset along with box plots showing library(tidyverse) library(kableExtra) library(patchwork) - + chickwts_h_l <- chickwts %>% filter(feed %in% c("horsebean", "linseed")) - + chickwts_h_l %>% group_by(feed) %>% summarise( @@ -348,46 +345,48 @@ Below are some summary statistics from this dataset along with box plots showing latex_options = "HOLD_position", full_width = FALSE) %>% column_spec(1:4, width = "6em") - + p_box <- chickwts_h_l %>% ggplot(aes(y = fct_rev(feed), x = weight)) + geom_boxplot() + labs(y = "Feed type", x = "Weight (in grams)") - + p_hist <- chickwts_h_l %>% ggplot(aes(x = weight)) + geom_histogram(binwidth = 25) + facet_wrap(~feed, ncol = 1) + labs(y = "Feed type", x = "Weight (in grams)") - + p_box + p_hist - ```` + ``` a. Describe the distributions of weights of chickens that were fed horsebean and linseed. - b. Do these data provide strong evidence that the average weights of chickens that were fed linseed and horsebean are different? Use a 5% discernibility level. + b. Do these data provide strong evidence that the average weights of chickens that were fed linseed and horsebean are different? + Use a 5% discernibility level. - c. What type of error might we have committed? Explain. + c. What type of error might we have committed? + Explain. d. Would your conclusion change if we used $\alpha = 0.01$? -1. **Fuel efficiency in the city.** -Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. -Below are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021. -Do these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average city mileage?^[The [`epa2021`](http://openintrostat.github.io/openintro/reference/epa2021.html) data used in this exercise can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.] [@data:epa2021] +16. **Fuel efficiency in the city.** Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. + Below are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021. + Do these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average city mileage?[^_20-ex-inference-two-means-4] + [@data:epa2021] ```{r} #| fig-asp: 0.4 library(tidyverse) library(kableExtra) library(openintro) - + set.seed(1234) epa2021_sample <- epa2021 %>% filter(transmission_desc %in% c("Manual", "Automatic")) %>% group_by(transmission_desc) %>% sample_n(size = 25) - + epa2021_sample %>% group_by(transmission_desc) %>% summarise( @@ -399,25 +398,25 @@ Do these data provide strong evidence of a difference between the average fuel e kable_styling(bootstrap_options = c("striped", "condensed"), latex_options = "HOLD_position", full_width = FALSE) - + ggplot(epa2021_sample, aes(y = fct_rev(transmission_desc), x = city_mpg)) + geom_boxplot() + labs(y = NULL, x = "City mileage (MPG)") ``` -1. **Chicken diet: casein vs. soybean.** -Casein is a common weight gain supplement for humans. -Does it have an effect on chickens? -An experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens. -Newly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement. -In this exercise we consider chicks that were fed casein and soybean. -Assume that the conditions for conducting inference using mathematical models are met, and using the data provided below, test the hypothesis that the average weight of chickens that were fed casein is different than the average weight of chickens that were fed soybean. -If your hypothesis test yields a statistically discernible result, discuss whether or not the higher average weight of chickens can be attributed to the casein diet. [@data:chickwts] +17. **Chicken diet: casein vs. soybean.** Casein is a common weight gain supplement for humans. + Does it have an effect on chickens? + An experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens. + Newly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement. + In this exercise we consider chicks that were fed casein and soybean. + Assume that the conditions for conducting inference using mathematical models are met, and using the data provided below, test the hypothesis that the average weight of chickens that were fed casein is different than the average weight of chickens that were fed soybean. + If your hypothesis test yields a statistically discernible result, discuss whether or not the higher average weight of chickens can be attributed to the casein diet. + [@data:chickwts] ```{r} library(tidyverse) library(kableExtra) - + chickwts %>% filter(feed %in% c("casein", "soybean")) %>% group_by(feed) %>% @@ -431,25 +430,25 @@ If your hypothesis test yields a statistically discernible result, discuss wheth kable_styling(bootstrap_options = c("striped", "condensed"), latex_options = "HOLD_position", full_width = FALSE) - ```` + ``` -1. **Fuel efficiency on the highway.** -Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. -Below are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021. -Do these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average highway mileage? [@data:epa2021] +18. **Fuel efficiency on the highway.** Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. + Below are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021. + Do these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average highway mileage? + [@data:epa2021] ```{r} #| fig-asp: 0.4 library(tidyverse) library(kableExtra) library(openintro) - + set.seed(1234) epa2021_sample <- epa2021 %>% filter(transmission_desc %in% c("Manual", "Automatic")) %>% group_by(transmission_desc) %>% sample_n(size = 25) - + epa2021_sample %>% group_by(transmission_desc) %>% summarise( @@ -461,23 +460,32 @@ Do these data provide strong evidence of a difference between the average fuel e kable_styling(bootstrap_options = c("striped", "condensed"), latex_options = "HOLD_position", full_width = FALSE) - + ggplot(epa2021_sample, aes(y = fct_rev(transmission_desc), x = city_mpg)) + geom_boxplot() + labs(y = NULL, x = "Highway mileage (MPG)") ``` -1. **Gaming, distracted eating, and intake.** -A group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups. -The treatment group ate lunch while playing solitaire, and the control group ate lunch without any added distractions. -Patients in the treatment group ate 52.1 grams of biscuits, with a standard deviation of 45.1 grams, and patients in the control group ate 27.1 grams of biscuits, with a standard deviation of 26.4 grams. -Do these data provide convincing evidence that the average food intake (measured in amount of biscuits consumed) is different for the patients in the treatment group compared to the control group? -Assume that conditions for conducting inference using mathematical models are satisfied. [@Oldham:2011] - -1. **Gaming, distracted eating, and recall.** -A group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups. -The 22 patients in the treatment group who ate their lunch while playing solitaire were asked to do a serial-order recall of the food lunch items they ate. -The average number of items recalled by the patients in this group was 4. 9, with a standard deviation of 1.8. -The average number of items recalled by the patients in the control group (no distraction) was 6.1, with a standard deviation of 1.8. -Do these data provide strong evidence that the average numbers of food items recalled by the patients in the treatment and control groups are different? -Assume that conditions for conducting inference using mathematical models are satisfied. [@Oldham:2011] +19. **Gaming, distracted eating, and intake.** A group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups. + The treatment group ate lunch while playing solitaire, and the control group ate lunch without any added distractions. + Patients in the treatment group ate 52.1 grams of biscuits, with a standard deviation of 45.1 grams, and patients in the control group ate 27.1 grams of biscuits, with a standard deviation of 26.4 grams. + Do these data provide convincing evidence that the average food intake (measured in amount of biscuits consumed) is different for the patients in the treatment group compared to the control group? + Assume that conditions for conducting inference using mathematical models are satisfied. + [@Oldham:2011] + +20. **Gaming, distracted eating, and recall.** A group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups. + The 22 patients in the treatment group who ate their lunch while playing solitaire were asked to do a serial-order recall of the food lunch items they ate. + The average number of items recalled by the patients in this group was 4. + 9, with a standard deviation of 1.8. + The average number of items recalled by the patients in the control group (no distraction) was 6.1, with a standard deviation of 1.8. + Do these data provide strong evidence that the average numbers of food items recalled by the patients in the treatment and control groups are different? + Assume that conditions for conducting inference using mathematical models are satisfied. + [@Oldham:2011] + +[^_20-ex-inference-two-means-1]: The [`diamonds`](https://ggplot2.tidyverse.org/reference/diamonds.html) data used in this exercise can be found in the [**ggplot2**](http://ggplot2.tidyverse.org/) R package. + +[^_20-ex-inference-two-means-2]: The [`lizard_run`](http://openintrostat.github.io/openintro/reference/lizard_run.html) data used in this exercise can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package. + +[^_20-ex-inference-two-means-3]: The [`chickwts`](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/chickwts.html) data used in this exercise can be found in the [**datasets**](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html) R package. + +[^_20-ex-inference-two-means-4]: The [`epa2021`](http://openintrostat.github.io/openintro/reference/epa2021.html) data used in this exercise can be found in the [**openintro**](http://openintrostat.github.io/openintro) R package.