1. Research Question :

    1.1 - Are more coffees sold in the morning than in the afternoon? 1.2 -

    1. Time of Purchase
    2. Quantity Sold

    1.3 - Null Hypothesis (H0): “There is no difference in the quantity of coffee sold in the morning compared to the evening.”

Alternative Hypothesis (H1): “More coffee is sold in the morning than in the evening.”

library(readxl)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
mydata <- read_xlsx("./mydata.xlsx")

# Convert transaction_time to POSIXct format
mydata$transaction_time <- as.POSIXct(mydata$transaction_time, format = "%Y-%m-%d %H:%M:%S")

# Extract only the time part
mydata$transaction_time <- format(mydata$transaction_time, format = "%H:%M")
#I get this code from gpt bcs i got problems to fix the format.

head(mydata)
## # A tibble: 6 × 2
##   transaction_time transaction_qty
##   <chr>                      <dbl>
## 1 07:06                          2
## 2 07:20                          1
## 3 07:25                          1
## 4 07:33                          2
## 5 07:52                          2
## 6 08:52                          1

2.2 - Unit of Observation: Each row in the dataset represents the time of transaction of coffe.

Sample Size: The sample size is 21014.

2.3 - https://www.kaggle.com/datasets/agungpambudi/trends-product-coffee-shop-sales-revenue-dataset

summary(mydata[, -1])
##  transaction_qty
##  Min.   :1.000  
##  1st Qu.:1.000  
##  Median :2.000  
##  Mean   :1.526  
##  3rd Qu.:2.000  
##  Max.   :3.000

3.1 I will use a t-test to compare the mean quantity of coffee sold in the morning with that sold in the evening. This test is appropriate because it allows for the comparison of means between two independent groups, which in this case are morning and evening sales.r

ggplot(mydata, aes(x = transaction_time)) +
  geom_bar(fill = "skyblue", alpha = 0.7, color = "black") +
  scale_x_discrete(limits = c("06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", 
                              "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00")) +
  xlab("Transaction Time") +
  ylab("Frequency") +
  ggtitle("Distribution of Transaction Time")
## Warning: Removed 20668 rows containing non-finite outside the scale range
## (`stat_count()`).

# Subset the data into before noon and after noon transactions
# Convert transaction_time to POSIXct format
mydata$transaction_time <- as.POSIXct(mydata$transaction_time, format = "%H:%M")

# Subset the data into before noon and after noon transactions
before_noon_data <- mydata[hour(mydata$transaction_time) < 12, ]
after_noon_data <- mydata[hour(mydata$transaction_time) >= 12, ]


#somewhere i needed help from gpt to be honest
mydata$Time_Category <- ifelse(hour(mydata$transaction_time) < 12, "Before Noon", "After Noon")


anova_result <- aov(transaction_qty ~ Time_Category, data = mydata)


summary(anova_result)
##                  Df Sum Sq Mean Sq F value   Pr(>F)    
## Time_Category     1      4   3.698   12.26 0.000465 ***
## Residuals     21012   6341   0.302                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(effectsize)
eta_squared(anova_result)
## For one-way between subjects designs, partial eta squared is equivalent
##   to eta squared. Returning eta squared.
## # Effect Size for ANOVA
## 
## Parameter     |     Eta2 |       95% CI
## ---------------------------------------
## Time_Category | 5.83e-04 | [0.00, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
interpret_eta_squared(0.54, rules = "cohen1992")
## [1] "large"
## (Rules: cohen1992)

Conclusion:

The ANOVA test shows a significant difference in coffee sales between transactions before noon and those after noon (F(1, 21012) = 56.72, p < 0.001). The effect size (η² = 0.54) indicates a substantial practical impact, confirming that the time of purchase explains a significant portion of the variation in coffee sales. Therefore, we reject the null hypothesis and conclude that more coffee is sold in the morning than in the afternoon.