UC R Worksheet
#INSTRUCTIONS
#Type the codes for each question
#Include answers to ALL questions in the script as a comment (with a #).
#Questions with a * next to it will ALSO require you to input the answer in Canvas.
#Lastly, upload this R script AND input the corresponding answers to Canvas.
#If you are missing codes or answers in this script, points will be deducted.
#Download and call each package from library
install.packages(“openintro”)
install.packages(“dplyr”)
install.packages(“ggplot2”)
library(openintro)
library(dplyr)
library(ggplot2)
#Run data and view the name of variables
data(acs12)
names(acs12)
#The data is named “acs12”
View(acs12)
###CONFIDENCE INTERVALS
###EXAMPLE, solve the problems using this guideline###
#1. Construct a 95% CI for the average commute time for Americans (the variable we’re looking at is caled “time_to_work”)
#What is the interval for the average commute time? What does this mean?
#The average commute time is 24.4, 27.6 minutes. This means that we can be 95% confident that the average commute time is between these values.
t.test(acs12$time_to_work)
#*2. Construct a 95% CI for the average income and explain your results. The variable is called “income”
#*3. Construct a 95% CI for the average hours worked and explain your results. This variable is called “hrs_work”
#*4. Construct a 95% CI for the average age and explain your results. This variable is called “age”
### T-Tests HYPOTHESIS TESTS
###REMEMBER we REJECT the Ho if the p-value is LESS than alpha of 0.05
###EXAMPLE BELOW, solve the problems using this question
#5. Assume the average commute time of Americans is thought to be 26 min.
#Write the null hypothesis and the conclusion
#***This is a two-sided test, meaning we are not looking at greater or less than
#Ho: average commute = 26
#Ha: average commute NOT equal to 26
t.test(acs12$time_to_work, mu=26, alternative = “two.sided”)
#The p-value is 1 which is GREATER than alpha of 0.05. Therefore we FAIL TO REJECT the HO. The average commute is equal to 26
# *6. Assume that the average age is thought to be GREATER than 30.
#Write the null hypothesis and the conclusion
#*** This is a one-sided test, we are looking at GREATER than 30 as the alternative
#Ho:
#Ha:
# P-value and conclusion:
# *7. Assume that the average age is thought to be LESS than 50.
#Write the null hypothesis and the conclusion
#*** This is a one-sided test, we are looking at LESS than 50 as the alternative
#Ho:
#Ha:
# P-value and conclusion:
# *8. Assume that the average age is thought to be EQUAL TO 30.
#Write the null hypothesis and the conclusion
#*** This is a two-sided test, we are looking at “two.sided” as the alternative
#Ho:
#Ha:
# P-value and conclusion: