due Thursday, 9/20 at 11:59p

Introduction

This homework covers Analysis of Variance (ANOVA) in Chapter 5 of the textbook. The exercise and page numbers refer to The Statistical Sleuth (3rd Edition) by Ramsey and Schafer. You may discuss the assignment with others; however, you must write and submit your own answers.

Please use the STA 210: HW 2 template to write up your assignment and submit your work as a PDF under the Assignments tab in Sakai. To ensure you have the updated template, run the R code below to update and load the STA210 package in R Studio.

devtools::install_github("matackett/sta210/STA210") 
library("STA210")


You will need the following libraries to complete the assignment:

library("tibble")
library("dplyr")
library("ggplot2")
library("broom")
library("Sleuth3") #data sets from the book 

Homework Tip

Using distributions in R

You can use the t distribution function in R to calculate critical values or p-values for one- and two-sample t inference. Use the functions below to calculate p-values:

# P(t < test)
pt(test,df) #test: test statistic, df: degrees of freedom
# P(t > test)
1- pt(test,df) #test: test statistic, df: degrees of freedom


To calculate the critical value for a confidence interval, you will need to input the cumulative probability associated with that critical value. The cumulative probability is the probability a random variable is less than or equal to a specified value. For example, the cumulative probability associated with the critical value for a 95% confidence interval is 0.975. For a given confidence level C, the associated cumulative probability is \[\frac{C+1}{2}\].

#cumulative probability associated with critical value for a 95% CI
(cumulative_prob <-  (0.95 + 1)/2)
## [1] 0.975
#critical value for a 95% confidence interval from a t distribution with 10 DF
(critical_val = qt(cumulative_prob,10))  #df: degrees of freedom
## [1] 2.228139


Calculating p-values from the F distribution

# P(F < test)
pf(test,df1,df2) #test: test statistic, df1, df2: degrees of freedom
# P(t > test)
1- pf(test,df1,df2) #test: test statistic, df1, df2: degrees of freedom

Questions

Question 1. Ex. #5.14

Use the code below to create a data frame called judges that contains the summary statistics shown in the book.

avg <- c(14.62,34.12,33.61,29.1,27,26.97,26.8)
sd <- c(5.039,11.942,6.582,4.593,3.818,9.010,5.969)
n <- c(9,5,6,9,2,6,9)
judges <- bind_cols(avg=avg,sd=sd,n=n)


Question 2. Ex. #5.17

The following values are provided in the textbook:

dfw <- 24 #DF within 
dft <- 31 #DF total
ssw <- 35088 #Sum of squares within 
sst <- 70907 #Sum of squares total 


Use the values provided by the book to fill in the values for the remainder of the table.

dfb <-  #DF between
ssb <-  #Sum of squares between
msb <-  #Mean square between 
msw <-  #Mean square within 
f_stat <- #F -statistic 
p_val <- # p-value


Use the code below to combine all of the values and print an ANOVA table.

#create each column of the ANOVA table
#each column must have same number of rows, 
#use NA to hold a space for the blank parts of the ANOVA table
source <- c("Between Groups", "Within Groups", "Total")
df <- c(dfb, dfw,dft)
ss <- c(ssb, ssw, sst)
ms <- c(msb, msw,NA)  
f.statistic <- c(f_stat, NA, NA)
p.value <- c(p_val,NA,NA)

# combine the columns to make a table called "anova"
anova <- bind_cols("Source"=source,"df"=df,"Sum of squares"=ss,
            "Mean square"=ms,"F-statistic"=f.statistic,"p-value"=p.value)

# print the table 
kable(anova) 


Question 3. Ex. #5.23
Use the ex0523 data set in the Sleuth3 package. Note: The sample sizes for each group are very small. Keep this in mind as you consider the assumptions for ANOVA.

Submitting Your Assignment

Once you complete the assignment, you’re ready to Knit the file to create the PDF document. Click the Knit button in the menu bar.


Once you click Knit, your PDF will appear in a new window. If you don’t see a PDF, check the pop-up blockers on your web browser.

Once you knit the file, you should see the written text along with any R code and the resulting output and/or plots. If you want to change anything in your write-up, you can make changes in the R Markdown file and knit the document to generate the updated PDF.

Once you have created the PDF file, you can export it from the Docker container to your local machine. To export the file, click the Download button in the upper right-hand corner.



You can now submit the downloaded PDF under the Assignments tab on Sakai.