Lab 8 - Shell
Lab 8 - Shell
2023-03-22
Learning Objectives
By the end of this lab, you should have a grasp on the following concepts:
Instructions
To complete this worksheet, add code as needed into the R code chunks given below. Do not delete the
question text. All text should be in complete English sentences. Be sure to change the author of this file to
reflect your name and student number.
To properly see the questions, knit this .Rmd file to .pdf and view the output. You will have a link in your
email that takes you to the Crowdmark submission page. Once you have completed the worksheet, knit it
to .pdf and upload your output to Crowdmark.
1
Exercises
Import the React1000 dataset, which contains various measurements on a sample of 1000 Grade 12 students
across the United States, including their Region, Gender, Age, Handedness, Height (cm), Foot Length (cm),
and Armspan (cm).
str(React1000)
In 1992, a well-known study estimated that 11.1% of Americans aged 10 to 86 are left- or mixed-handed
(LMH). Suppose that we wish to test at the α = 0.01 level whether the proportion of Americans who are
LMH has changed since this estimate, using React1000 as our sample.
Give the hypotheses for this test.
H0 : p = 0.111 vs Ha : p ̸= 0.111
Use the table function to find the number of students in this sample who are LMH.
table(React1000$Handed)
##
## Ambidextrous Left-Handed Right-Handed
## 44 80 876
## [1] 1.308673
2 * pnorm(-z.stat)
## [1] 0.1906453
2
What is your decision regarding this test?
As the value of p is more than level of significance , we fail to reject H0.
Repeat the above test using the prop.test function.
##
## 1-sample proportions test without continuity correction
##
## data: 124 out of 1000, null probability 0.111
## X-squared = 1.7126, df = 1, p-value = 0.1906
## alternative hypothesis: true p is not equal to 0.111
## 95 percent confidence interval:
## 0.1050000 0.1458777
## sample estimates:
## p
## 0.124
Use the prop.test function to produce a 99% confidence interval for the true proportion of American citizens
who are LMH.
##
## 1-sample proportions test without continuity correction
##
## data: 124 out of 1000, null probability 0.111
## X-squared = 1.7126, df = 1, p-value = 0.1906
## alternative hypothesis: true p is not equal to 0.111
## 99 percent confidence interval:
## 0.09960635 0.15335021
## sample estimates:
## p
## 0.124
Exercise: Load in the Company500 dataset. This dataset contains various measurements on
a sample of 500 employees from a large company, including their age bracket (Age.Bracket:
either over or under 40), employment status (Status: either salaried or hourly), department,
and earnings bracket. Use the table function to obtain a count of how many employees are
hourly vs. salaried.
##
## Hourly Salaried
## 351 149
3
Exercise: Perform a test at the 5% level of significance to determine whether the proportion
of employees who are salaried is below one-third, which is known to be the rate in a competing
company. Give whether you reject or fail to reject H0 .
##
## 1-sample proportions test without continuity correction
##
## data: 149 out of 500, null probability 1/3
## X-squared = 2.809, df = 1, p-value = 0.04687
## alternative hypothesis: true p is less than 0.3333333
## 95 percent confidence interval:
## 0.000000 0.332659
## sample estimates:
## p
## 0.298
As the value of p is below the level of significance , we reject H0. We have sufficient evidence at the 5% level
of significance that the proportion of employees who are salaried are less than at the competing company.
Exercise: Calculate a 99% interval for the true proportion of employees who are salaried at
this company. Print out the confidence interval below.
##
## 1-sample proportions test without continuity correction
##
## data: 149 out of 500, null probability 1/3
## X-squared = 2.809, df = 1, p-value = 0.09374
## alternative hypothesis: true p is not equal to 0.3333333
## 99 percent confidence interval:
## 0.2482371 0.3530537
## sample estimates:
## p
## 0.298
c( 0.2482371, 0.3530537)
The p value is above 1% level of significance so we fail to reject H0 and the confidence interval is [0.2482,
0.3531]
The 1992 study referenced earlier also found that the proportion of boys who are LMH is greater than
the proportion of girls who are LMH. Suppose that we wish to test this on our sample, at the 2% level of
significance.
Give the hypotheses for this test.
4
H0 : pM = pF vs Ha : pM > pF
table(React1000$Gender,React1000$Handed)
##
## Ambidextrous Left-Handed Right-Handed
## Female 13 40 464
## Male 31 40 412
Use table to count the number of girls and boys in this sample:
table(React1000$Gender)
##
## Female Male
## 517 483
##
## 2-sample test for equality of proportions without continuity correction
##
## data: c(71, 53) out of c(483, 517)
## X-squared = 4.5489, df = 1, p-value = 0.01647
## alternative hypothesis: greater
## 95 percent confidence interval:
## 0.01007626 1.00000000
## sample estimates:
## prop 1 prop 2
## 0.1469979 0.1025145
##
## 2-sample test for equality of proportions without continuity correction
##
## data: c(71, 53) out of c(483, 517)
## X-squared = 4.5489, df = 1, p-value = 0.03294
5
## alternative hypothesis: two.sided
## 98 percent confidence interval:
## -0.004179282 0.093146127
## sample estimates:
## prop 1 prop 2
## 0.1469979 0.1025145
table(Company500$Age.Bracket,Company500$Status)
##
## Hourly Salaried
## Over 40 105 59
## Under 40 246 90
Exercise: Perform a test at the 1% level of significance to determine whether the proportion of
employees who are over 40 differs between the salaried and hourly workers. Mention whether
you reject or fail to reject H0 .
##
## 2-sample test for equality of proportions without continuity correction
##
## data: c(105, 59) out of c(351, 149)
## X-squared = 4.4492, df = 1, p-value = 0.03492
## alternative hypothesis: two.sided
## 99 percent confidence interval:
## -0.21771465 0.02405894
## sample estimates:
## prop 1 prop 2
## 0.2991453 0.3959732