Chi-square Goodness-of-Fit on selling quantity of different desserts
in a restaurant
library(readxl)
RQ1 <- read_excel("C:/Users/acer/Desktop/RQ1.xlsx")
# =========================
# VISUALLY DISPLAY THE DATA
# =========================
# PURPOSE
# Visually display the data.
# A frequency table can be used instead of a bar graph to visually display the data.
# CREATE A FREQUENCY TABLE
# Replace "dataset" with the name of your dataset (without the .xlsx)
# Replace "Variable" with the R code name of your variable
# Remove the hashtag to use the code.
# The code for this task is provided below. Remove the hashtag below to convert the note into code.
observed <- table(RQ1$Dessert)
# VIEW YOUR FREQUENCY TABLE
# View the observed frequencies.
# The code for this task is provided below. Remove the hashtag below to convert the note into code.
print(observed)
##
## Cheesecake ChocoCake Tiramisu
## 171 258 119
# VIEW THE CATEGORY ORDER
# The code for this task is provided below. Remove the hashtag below to convert the note into code.
names(observed)
## [1] "Cheesecake" "ChocoCake" "Tiramisu"
# ===============================
# CHI-SQUARE GOODNESS OF FIT CODE
# ===============================
# PURPOSE
# Determine if the null or alternate hypothesis was supported.
# DEFINE EXPECTED PROPORTIONS
# First, look at your methods/ research design to determine the expected proportions for each category.
# Next, turn those proportions into decimals.
# The expected proportions MUST be in the same order as the categories.
# Percentages should be written as decimals (e.g., 0.30 = 30%) and add up to 1
# An example of the code for this task is provided below.
# You can edit the code below and remove the hashtag to use the code below.
expected <- c(1/3, 1/3, 1/3)
# CALCULATE CHI-SQUARED RESULTS
# Do NOT edit this code.
# Remove the hashtags to use the code below.
chisq_gfit <- chisq.test(observed, p = expected)
print(chisq_gfit)
##
## Chi-squared test for given probabilities
##
## data: observed
## X-squared = 54.004, df = 2, p-value = 1.876e-12
# DETERMINE STATISTICAL SIGNIFICANCE
# If results were statistically significant (p < .05), continue to the effect size section below.
# If results were NOT statistically significant (p > .05), do NOT calculate the effect size.
# Instead, skip to the reporting section below.
# NOTE: Getting results that are not statistically significant does NOT mean you switch to a different test.
# ================
# EFFECT SIZE CODE
# ================
# PURPOSE
# Determine how strong the similarity was between what was observed versus what was expected.
# DIRECTIONS
# Remove the hashtags to use the code below.
# Do NOT make any other edits to the code
W <- sqrt(chisq_gfit$statistic / sum(observed))
W
## X-squared
## 0.3139217
# DETERMINE THE SIZE OF THE EFFECT
# 0.00 to 0.09 = ignore
# 0.10 to 0.29 = small
# 0.30 to 0.49 = moderate
# 0.50+ = large
# Examples:
# A Cohen's W of 0.08 indicates the similarity between the observed data and the expected data was very minimal. There was no effect.
# A Cohen's W of 0.61 indicates the similarity between the observed data and the expected data was very high. There was a large effect.
# ==================
# SUMMARY OF RESULTS
# ==================
# .................................................
# QUESTION
# What were the results? Write them in a paragraph below.
# YOUR PARAGRPAH:
# 1. Test name: Chi-squared Goodness-of-Fit Test
# 2. Categorical variable: Dessert (Vanilla cheesecake, Chocolate cake, and Tiramisu)
# 3. Expected proportion: 1/3, 1/3, 1/3
# 4. Sample size: 548
# 5. State there WAS (p = 1.876e-12 < 0.05) a statistical significant difference between the expected and actual proportion.
# 6. Degree of freedom: 2
# 7. Chi-square value: 54.004
# 8. EXACT p-value to three decimals: p < 0.001
# χ²(2, N = 548) = 54.004, p = 1.876e-12
# 9. Most preferred category: Chocolate cake (258); Least preferred category: Tiramisu (119)
# 10. Effect size value: W = 0.314 - Medium size
# .................................................
A Chi-Square Goodness-of-Fit Test was conducted to determine whether
dessert type preference (Vanilla cheesecake, Chocolate cake, Tiramisu)
was different from an equal distribution (33.33%, 33.33%, 33.33%).
Among 548 customers
1. There was a statistically significant difference in car type
preferences, χ²(2, N = 548) = 54.004, p = 1.876e-18
2. Participants preferred Chocolate cake more than Vanilla
cheesecake or Tiramisu
3. The effect size was medium (Cohen’s W = 0.314).