1. A librarian wishes to determine if it is equally likely that a person will take a book out of the library each of the six days of the week the library is open (assume the library is closed on Sundays). She records the number of books signed out of the library during one week and obtains the following frequencies:
library(readxl)
Chi_square_for_goodness_of_fit <- read_excel("D:/MARV BS MATH/4th year, 2nd sem/Nonparametric Statistics/Final Exam/Chi-square for goodness-of-fit.xlsx")
Chi_square_for_goodness_of_fit
# A tibble: 6 × 2
  Day       Frequency
  <chr>         <dbl>
1 Monday           20
2 Tuesday          14
3 Wednesday        18
4 Thursday         17
5 Friday           22
6 Saturday         29
head(Chi_square_for_goodness_of_fit)
# A tibble: 6 × 2
  Day       Frequency
  <chr>         <dbl>
1 Monday           20
2 Tuesday          14
3 Wednesday        18
4 Thursday         17
5 Friday           22
6 Saturday         29
summary(Chi_square_for_goodness_of_fit)
     Day              Frequency    
 Length:6           Min.   :14.00  
 Class :character   1st Qu.:17.25  
 Mode  :character   Median :19.00  
                    Mean   :20.00  
                    3rd Qu.:21.50  
                    Max.   :29.00  

Null hypothesis : There is no significant difference between a person will take a book out of the library each of the six days of the week when the library is open and number of books signed out of the library during that week.

Alternative hypothesis : There is significant difference between a person will take a book out of the library each of the six days of the week when the library is open and number of books signed out of the library during that week.

res <- chisq.test(Chi_square_for_goodness_of_fit$Frequency, p = c(1/6, 1/6, 1/6, 1/6, 1/6, 1/6))
res

    Chi-squared test for given probabilities

data:  Chi_square_for_goodness_of_fit$Frequency
X-squared = 6.7, df = 5, p-value = 0.2439

Since the p value is 0.2439 which is greater than the significant level 0.05, we don’t have enough evidence to reject the null hypothesis. Thus, there is significant difference between a person will take a book out of the library each of the six days of the week when the library is open and number of books signed out of the library during that week.

res$expected
[1] 20 20 20 20 20 20