===================================

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.

………………………………………………………..

QUESTION

What are the null and alternate hypotheses for your research?

H0: The distribution of dessert preferences matches the expected equal distribution

H1: The distribution of dessert preferences does not match the expected equal distribution

………………………………………………………..

======================

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/tsury/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## package 'readxl' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'readxl'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\tsury\AppData\Local\R\win-library\4.5\00LOCK\readxl\libs\x64\readxl.dll
## to C:\Users\tsury\AppData\Local\R\win-library\4.5\readxl\libs\x64\readxl.dll:
## Permission denied
## Warning: restored 'readxl'
## 
## The downloaded binary packages are in
##  C:\Users\tsury\AppData\Local\Temp\Rtmp4cRQCK\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.

rq1 <- read_excel("C:\\Users\\tsury\\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(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)

===============================

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

Result Report

A Chi-Square Goodness-of-Fit Test was conducted to determine whether Dessert preference (Tiramisu, Cheese cake , choco cake) was different from an equal distribution (33.33%, 33.33%, 33.33%) among 548 participants. There was a statistically significant difference in Dessert preferences, χ²(2, N = 548) = 54.004, p = 1.876e-12. Participants preferred cHOCOCAKE more than Cheesecake or tiramisu. The effect size was medium (Cohen’s W = 0.3139217).

………………………………………….