##
#
# MEBn5033 Assignment 03 - t-tests and ANOVA
#
##

### Instructions ###

# Save this script under the new name with your surname appended 
# E.g.: MVZn5033_01_Assignment_Ocelik.R

# Write the commands directly to this newly saved script
# It sufficient to use just one solution to each task
# Each task is awarded by 1 point when done correctly
# Upload the script into the corresponding Homework Vault when you are finished 

# ?function_names gives you a hint what function to use
# It also opens, often a quite comprehensive, documentation of the function
# Do not copy paste the complete function description, typically we are OK with 1-4 arguments 


#
# read in dataset "states.csv" and save as object named "states"
#

?read.table

# attach the dataset, so you can directly access its variables
attach(states)

#
# use one-sample t-test to compare 
# whether the ratio of workforce organized in unions  (variable union10)
# HA: is different from value 15 (known population mean)
# set the significance level to 0.05
# 

# before application of the test, use summary function to describe union10 variable
?summary
summary(union10)

?t.test

# briefly interpret the restuls 
# focus on the value of the test statistic, p-value, and decision on H0 and HA




#
# use two-sample independent t-test to compare whether there is difference in
# mean proportion of prolife (against abortion) attitudes (var: prolife) 
# between the U.S. states where Obama lost and won in 2012 (var: obama_win12) presidential elections
# HA: let's assume that there is a higher mean proportion of prolife attitudes in states where Obama lost
# set the significance level to 0.05
#

# before application of the test, use summary function to describe prolife variable


# HINT: you need to subset prolife variables into two groups, one group represents
# states where Obama lost, the other represents states where Obama won
# use [] to subset prolife variable according to vales of obama_win12 variable
# there are, of course, also different ways how to do subsetting

?t.test

# briefly interpret the restuls 
# focus on the value of the test statistic, p-value, and decision on H0 and HA




#
# use paired t-test to compare whether there is difference in
# mean proportion of workforce union oranization in 2010 and 2004
# variables: union10 and union04
# HA: let's assume that there is a lower mean proportion of union oranization in 2010
# set the significance level to 0.05
#

# first, explore the distribution of the variables through boxplots
?boxplot

?t.test


# briefly interpret the restuls 
# focus on the value of the test statistic, p-value, and decision on H0 and HA

#
# read in the "regions.turnout.txt" dataset and save it into object called "data" 
#

?read.table

# attach the data to direcly access the variables
attach(data)

#
# use boxplots to explore the distirbution of the vep12_turnout variable for each region
# plot boxplots for all the 4 regions within one window/graph
#

?boxplot

#
# use anova to model (aov function) to compare whether the three means are equal or not
# svae the tests results into a separate object and summary function to present the results
#

?aov
?summary

# What is the null hypothesis of the test?

# What is the alternative hypothesis of the test? 

# Interpret the results in terms of the value of test statistic and its p-value


