| ![]() |
For each of the following problems, write code in R or fill cells in an Excel worksheet with appropriate formulas to answer the question asked. Don't forget to include any calculations needed to verify the assumptions related to whatever tests are conducted. Include as comments in your code or on your worksheet, any analysis, conclusions and inferences made.
The following R functions might be useful in checking some assumptions:
outliers = function(data) {
lower.bound = quantile(data,0.25) - 1.5*IQR(data)
upper.bound = quantile(data,0.75) + 1.5*IQR(data)
return((data < lower.bound) | (data > upper.bound))
}
I = function(data) {
return(3*(mean(data)-median(data))/sd(data))
}
Listed below are times (seconds) that 10 animated Disney movies showed the use of tobacco and alcohol. Use a 0.05 significance level to test the claim that the mean of the differences is greater that 0 seconds, so that more time is devoted to showing tobacco than alcohol. Use the $p$-value method. $$\begin{array}{l|cccccccccc} \textrm{Tobacco} & 176 & 51 & 0 & 299 & 74 & 2 & 23 & 205 & 6 & 155\\\hline \textrm{Alcohol} & 88 & 33 & 113 & 51 & 0 & 3 & 46 & 73 & 5 & 74\\ \end{array}$$
R Code:
tobacco = c(176,51,0,299,74,2,23,205,6,155) alcohol = c(88,33,113,51,0,3,46,73,5,74) # data is paired, so find differences differences = tobacco - alcohol # We wish to do a one-sample means test on differences, so check assumptions. # Noting that n is not large enough to guarantee normality of the distribution # of sample means, we check to see if the sample taken seems normal (as this # is a reflection on the distribution of the population in question, # whose normality would assure the normality of the distribution of # sample means) # Are there any outliers? any(outliers(differences)) # returns TRUE differences = differences[!outliers(differences)] # throw out outliers # check for skewness I(differences) # returns 0.4294885 (no sig. skew) # we are testing if there is evidence tobacco use is shown more than # alcohol use, so alternative hypothesis of # differences = tobacco - alcohol > 0 (i.e., alternative="greater") # Assumptions appear to be met. # So we conduct the test with: t.test(differences,alternative="greater") # p.value = 0.1394 # Conclusion: fail to reject null at alpha = 0.05 # Inference: There is no significant evidence in a difference in times # in Disney movies.
The number of grams of carbohydrates contained in 1-ounce servings of randomly selected chocolate and non-chocolate candy is listed below. Assume samples are approximately normal. $$\begin{array}{ r|ccccccccccccc} \hbox{Chocolate: }&17&24&25&25&27&29&29&29&32&34&36&38&41\cr \hbox{Non-chocolate: }&10&12&29&29&30&37&38&39&41&41& \end{array}$$
R Code:
chocolate = c(17,24,25,25,27,29,29,29,32,34,36,38,41) nonchocolate = c(10,12,29,29,30,37,38,39,41,41) # We wish to do a two sample means test. Having been told that we # can assume the samples (and thus the populations they come from) # are approximately normal, the distribution of sample means should # be normal. Thus, it remains to check the assumption that the # variances agree # (part a): # We conduct the appropriate F test to this end: var.test(chocolate,nonchocolate,alternative="two.sided") # p.value = 0.07553 # Conclusion: fail to reject the null for this F test # Inference: There is no significant evidence the variances disagree # (part b): # All assumptions appear to be met, so we proceed with the two-sample # means test t.test(chocolate,nonchocolate,alternative="two.sided",var.equal = TRUE) # p.value = 0.8109 # Conclusion: fail to reject the null hypothesis # Inference: There is no significant evidence of a difference in # carbohydrates between chocolate and nonchocolate cookies
In the 1980s it was generally believed that autism affected about $5\%$ of the nation's children. Some people believe that the increase in the number of chemicals in the environment has led to an increase in the incidence of autism. A recent study examined 384 children and found that 46 of them showed signs of some form of autism. Is this strong evidence that the level of autism has increased? Perform the appropriate hypothesis test with a significance level of $\alpha = 0.05$.
R Code:
# We wish to perform a one sample proportion test # We check assumptions that np,nq >= 5: 384*(.05) # 19.2 > 5 384*(.95) # 364.8 > 5 # Assumptions are met, so we proceed with the test # Noting that we are interested in whether there is evidence # that autism has increased, our alternative hypothesis is p > 0.05, # so we conduct the test: binom.test(x=46,n=384,p=0.05,"greater") # p.value = 5.56e-08 # Conclusion: reject the null # Inference: there is highly significant evidence that the level of # autism has increased since the 1980s
The average 1-ounce chocolate chip cookie contains 110 calories. A random sample of 15 different brands of cookies resulted in the following calorie amounts. At the 0.01 significance level, is there sufficient evidence that the average caloric content is greater than 110 calories?
$$\begin{array}{cccccccc} 100 & 125 & 150 & 160 & 185 & 125 & 155 & 145\\ 160 & 100 & 150 & 140 & 135 & 120 & 110 & \end{array}$$R Code:
chips = c(100,125,150,160,185,125,155,145,160,100,150,140,135,120,110)
# We wish to do a one sample means test, so check assumptions.
# Noting that n is not large enough to guarantee normality of the distribution
# of sample means, we check to see if the sample taken seems normal (as this
# is a reflection on the distribution of the population in question,
# whose normality would assure the normality of the distribution of
# sample means)
any(outliers(chips)) # returns FALSE
I(chips) # returns -0.3317057 (no sig. skew)
# Assumptions appear to be met
# Alternative hypothesis is mu > 110, so conduct the test with:
t.test(chips,mu=110,alternative="greater") # p.value = 0.0003087
# Conclusion: reject null at alpha = 0.05,
# Inference: There is highly significant evidence the mean number of
# chips is greater than 110
A study is conducted as to whether there is a relationship between joggers and the frequency of consumption of nutritional supplements. A random sample of 210 subjects is selected, and they are classified as shown. At a 0.05 significance level, test the claim that jogging and the consumption of supplements are not related. $$\begin{array}{lccc} & \textrm{Daily} & \textrm{Weekly} & \textrm{As Needed}\\\hline \textrm{Joggers} & 34 & 52 & 23\\ \textrm{Non-joggers} & 18 & 65 & 18 \end{array}$$
We wish to conduct a chi-square test of independence. Checking the assumptions of the test, we verify that each expected count in the six categories are all greater than or equal to 5.
Excel Worksheet:

orange cell totals found using SUM() function on the appropriate row or column C9 : "=C$5*$F3/$F$5" (this is copied to C9:E10, and checked to see if all are >= 5) E12 : "=CHISQ.TEST(C3:E4,C9:E10)"
Conclusion: Reject the null hypothesis
Inference: There is significant evidence that jogging and the frequency of taking nutritional supplements are related.