===================================
CHI-SQUARE GOODNESS OF FIT OVERVIEW
===================================
CHI-SQUARE GOODNESS OF FIT
Compares observed categorical data from one variable to expected
proportions.
NOTES
Normality does not apply to Chi-Square tests because data is only
categorical.
==========
HYPOTHESES
==========
NULL HYPOTHESIS
The observed frequencies matches the expected frequencies.
ALTERNATE HYPOTHESIS
The observed frequencies do not match the expected frequencies.
======================
IMPORT EXCEL FILE CODE
======================
PURPOSE OF THIS CODE
Imports your Excel dataset automatically into R Studio.
You need to import your dataset every time you want to analyze your
data in R Studio.
INSTALL REQUIRED PACKAGE
The package only needs to be installed once.
The code for this task is provided below. Remove the hashtag below
to convert the note into code.
options(repos = c(CRAN = "https://cloud.r-project.org"))
install.packages("readxl")
## Installing package into 'C:/Users/manit/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## package 'readxl' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\manit\AppData\Local\Temp\RtmpAxG2g7\downloaded_packages
LOAD THE PACKAGE
You must always reload the package you want to use.
The code for this task is provided below. Remove the hashtag below
to convert the note into code.
library(readxl)
IMPORT THE EXCEL FILE INTO R STUDIO
Download the Excel file from One Drive and save it to your
desktop.
Right-click the Excel file and click “Copy as path” from the
menu.
In R Studio, replace the example path below with your actual
path.
Replace backslashes with forward slashes / or double them //:
✘ WRONG “C:.xlsx”
✔ CORRECT “C:/Users/Joseph/Desktop/mydata.xlsx”
✔ CORRECT “C:\Users\Joseph\Desktop\mydata.xlsx”
Replace “dataset” with the name of your excel data (without the
.xlsx)
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.
dataset <- read_excel("C:/Users/manit/Downloads/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(dataset$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.
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:
A Chi-Square Goodness-of-Fit Test was conducted to determine whether
dessert preference (Tiramisu, Chococake, cheesecake) was different from
an equal distribution (33.33%, 33.33%, 33.33%) among 548 participants.
There was a statistically significant difference in car type
preferences, χ²(2, N = 548) = 54.004, p = 1.876e-12. Participants
preferred Chococake more than tiramisu or cheesecake. The effect size
was medium (Cohen’s W = 0.3139217).