Null Hypothesis H₀: The distribution of car type preferences matches the expected equal distribution (33.3% each).
Alternate Hypothesis H₁: The distribution of car type preferences does not match the expected equal distribution.
Importing Dataset
Install required package (only once) install.packages(“readxl”) Load the package
library(readxl)
Import Excel dataset (update file path)
dataset <- read_excel(“C:/Users/Poojitha Dibbamadugu/Downloads/RQ1.xlsx”) head(dataset)
📊 Visualize the Data
We first create a frequency table (observed counts) for our categorical variable.
Replace ‘Variable’ with your dataset’s categorical variable
observed <- table(dataset$Variable)
Display observed frequencies
print(observed)
View category names
names(observed)
⚙ Define Expected Proportions
Expected proportions are based on your hypothesis or prior knowledge. They must be written as decimals and must sum to 1.
Writing Example: Equal distribution among three categories
expected <- c(0.33, 0.33, 0.34)
🔍 Conduct the Chi-Square Goodness-of-Fit Test Writing Perform test
chisq_gfit <- chisq.test(observed, p = expected)
View results
chisq_gfit
Interpretation:
If p < 0.05, reject H₀ → observed frequencies differ significantly from expected ones.
If p > 0.05, fail to reject H₀ → no significant difference.
📈 Effect Size (Cohen’s W)
Effect size quantifies how strong the difference is between observed and expected frequencies.
Writing Calculate Cohen’s W
W <- sqrt(chisq_gfit$statistic / sum(observed)) W Interpretation:
If p < 0.05, reject H₀ → observed frequencies differ significantly from expected ones.
If p > 0.05, fail to reject H₀ → no significant difference.
📈 Effect Size (Cohen’s W)
Effect size quantifies how strong the difference is between observed and expected frequencies.
Results paragraph
A Chi-Square Goodness-of-Fit Test was conducted to determine whether car type preference (Sedan, SUV, Truck) was different from an equal distribution (33.33%, 33.33%, 33.33%) among 90 participants. There was a statistically significant difference in car type preferences, χ²(2, N = 90) = 9.67, p = .008. Participants preferred SUVs more than sedans or trucks. The effect size was medium (Cohen’s W = 0.33).
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the plo