library(ggplot2)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## âś” dplyr 1.1.4 âś” readr 2.1.6
## âś” forcats 1.0.1 âś” stringr 1.6.0
## âś” lubridate 1.9.4 âś” tibble 3.3.1
## âś” purrr 1.2.1 âś” tidyr 1.3.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## âś– dplyr::filter() masks stats::filter()
## âś– dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(moments)
library(effsize)
ex1 <- read.csv("Exercise3_1.csv")
ex2 <- read.csv("Exercise3_2.csv")
ggplot(ex1, aes(x = mathScore)) +
geom_histogram(bins = 6, color = "black")
The histogram looks balanced overall, not showing any outliers so the
data seems normal. ## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
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:
shapiro.test(ex1$mathScore)
##
## Shapiro-Wilk normality test
##
## data: ex1$mathScore
## W = 0.96297, p-value = 0.4767
t.test(ex1$mathScore, mu = 50)
##
## One Sample t-test
##
## data: ex1$mathScore
## t = 2.5336, df = 24, p-value = 0.01823
## alternative hypothesis: true mean is not equal to 50
## 95 percent confidence interval:
## 51.00849 59.87151
## sample estimates:
## mean of x
## 55.44
Since the p value was below o.o5, we reject the null hypothesis. This shows the students average math score is significantly different from the national average.
cohen.d(ex1$mathScore, rep(50, length(ex1$mathScore)), na.rm = TRUE)
##
## Cohen's d
##
## d estimate: 0.7166067 (medium)
## 95 percent confidence interval:
## lower upper
## 0.1299448 1.3032686
The effect was medium (d=0.72). This means the difference between the students’ average math score and national average is not very large.
A one sample t test showed that the students average matyh score (M=55.44) was significantly different from the national average of 50,T(24)=2.53, p=.018
## Problem 2 (Exercise3_2)
ex2 <- read.csv("Exercise3_2.csv")
head(ex2)
## score
## 1 2
## 2 4
## 3 2
## 4 3
## 5 3
## 6 5
ggplot(ex2, aes(x = factor(score))) +
geom_bar(color = "black") +
xlab("score")
shapiro.test(ex2$score)
##
## Shapiro-Wilk normality test
##
## data: ex2$score
## W = 0.89306, p-value = 0.0002857
Since the p-value is below 0.05, we reject normality assumption. So the scores do not look normally distributed.
t.test(ex2$score, mu = 3)
##
## One Sample t-test
##
## data: ex2$score
## t = 1.0706, df = 49, p-value = 0.2896
## alternative hypothesis: true mean is not equal to 3
## 95 percent confidence interval:
## 2.859673 3.460327
## sample estimates:
## mean of x
## 3.16
Since the p-value (0.2896) is above 0.05, we fail to reject the null. That means the average response is not significantly different from 3 (neutral)
d <- (mean(ex2$score) - 3) / sd(ex2$score)
d
## [1] 0.1514067
The effect sixcze (Cohens d) is about 0.15, so its small ***