Filling the Blank Answers

  1. 정규성
  2. 등분산
  3. Studnet t-test
  4. Welch t-test
  5. Paired t-test
library(readxl)
dat <- read_excel("/Users/nabinwon/Downloads/hair_pain1.xlsx")

library(stringr)
dat$t1<-ifelse(str_detect(dat$Hair_color,"Blond"),"Blond",
               ifelse(str_detect(dat$Hair_color,"Brunette"),"Brunette",NA))

dat$t1<-as.factor(dat$t1)

귀무가설/대립가설 세우기

Null Hypothesis: There is no difference between the mean values of the pain threshold between Blond and Brunette Alternative Hypothesis: There is a difference between the mean values of the pain threshold between Blond and Brunette

library(magrittr)
library(ggplot2)
dat %>%
  ggplot(aes(t1,Pain_threshold))+
  geom_boxplot()

## Drawing the Box Plot

I drew the box plots that portray the relationship between the hair colors and their respective thresholds by executing the code above. Here, we can observe that the median value and the standard deviation of the blond hair color is higher than the brunette, seen by the way that the box plot of the former is situated higher on the graph and its greater distance between the interquartile ranges and the median.

result <- lapply(split(dat$Pain_threshold, dat$t1), shapiro.test)
result
## $Blond
## 
##  Shapiro-Wilk normality test
## 
## data:  X[[i]]
## W = 0.97519, p-value = 0.9343
## 
## 
## $Brunette
## 
##  Shapiro-Wilk normality test
## 
## data:  X[[i]]
## W = 0.94025, p-value = 0.5846

Normality Test

The p-value from the normality test was 0.9343 and 0.5846 respectively, signifying that both of the data follows the normal distribution.

library(car)
## Loading required package: carData
leveneTest(Pain_threshold~t1, data=dat)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  1   0.677  0.422
##       17

Homogeneity Test

The p-value derived from the homogeneity test is 0.422, signifying that the distribution between the two samples are equal.

t.test(data=dat,
  Pain_threshold~t1,
  var.equal=T)
## 
##  Two Sample t-test
## 
## data:  Pain_threshold by t1
## t = 3.9914, df = 17, p-value = 0.0009447
## alternative hypothesis: true difference in means between group Blond and group Brunette is not equal to 0
## 95 percent confidence interval:
##   7.322556 23.744111
## sample estimates:
##    mean in group Blond mean in group Brunette 
##               55.20000               39.66667

Comparing the Mean of Blond and Brunette

The derived p-value from the following code is 0.0009447, signifying that the mean of the two samples are different since the value is less than 0.05 (유의수준).

dat$t1<-ifelse(str_detect(dat$Hair_color,"Dark"),"Dark",
               ifelse(str_detect(dat$Hair_color,"Light"),"Light",NA))

dat$t1<-as.factor(dat$t1)

귀무가설/대립가설 세우기

Null Hypothesis: There is no difference between the mean values of the pain threshold between Bright and Dark hair color.
Alternative Hypothesis: There is a difference between the mean values of the pain threshold between Bright and Dark hair color.

library(magrittr)
library(ggplot2)
dat %>%
  ggplot(aes(t1,Pain_threshold))+
  geom_boxplot()

## Drawing the Box Plot

I drew the box plots that portray the relationship between the hair colors and their respective thresholds by executing the code above. Here, we can observe that the median value of the light hair color is higher than the dark, seen by the way that the box plot of the former is situated higher on the graph than the latter. However, the standard deviation between the models seem relatively similar.

result <- lapply(split(dat$Pain_threshold, dat$t1), shapiro.test)
result
## $Dark
## 
##  Shapiro-Wilk normality test
## 
## data:  X[[i]]
## W = 0.95329, p-value = 0.7075
## 
## 
## $Light
## 
##  Shapiro-Wilk normality test
## 
## data:  X[[i]]
## W = 0.96498, p-value = 0.8487

Normality Test

The p-value from the normality test is 0.7075 and 0.8487 respectively, signifying that the data follows the normal distribution as both values are greater than 0.05. (유의수준)

leveneTest(Pain_threshold~t1, data=dat)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  1       0  0.997
##       17

Homogenity Test

The p-value derived from the homogenity test is 0.997, signifying that the distribution between the two samples are equal.

t.test(data=dat,
  Pain_threshold~t1,
  var.equal=T)
## 
##  Two Sample t-test
## 
## data:  Pain_threshold by t1
## t = -1.4651, df = 17, p-value = 0.1611
## alternative hypothesis: true difference in means between group Dark and group Light is not equal to 0
## 95 percent confidence interval:
##  -18.245967   3.290411
## sample estimates:
##  mean in group Dark mean in group Light 
##            44.30000            51.77778

Comparing the Mean of Bright Hair and Dark Hair

Since the p-value of 0.1611 is greater than the significance level of 0.05, we fail to reject the null hypothesis. Therefore, we can conclude that there is insufficient to state that a difference exists between the mean of the two data sets.