Thursday, October 22, 2020

Mod 9: T-Test for Independent Samples

Mod-9.utf8


Set environment

env <- c("dplyr","tibble")
lapply(env, library, character.only = 1)



The dataset is from a study whose research hypothesis was:

  • “There will be a difference between boys and girls in the number of times they raise their hand in class.”

For the purposes of this study, boys were coded as 2 on gender and girls were coded as 1.

The dataset:

classroom <- tribble(
    ~gender, ~handup,
    1,9,
    2,11,
    2,1,
    1,8,
    2,2,
    2,6,
    1,3,
    2,4,
    1,8,
    2,3,
    1,10,
    2,6
)
classroom
## # A tibble: 12 x 2
##    gender handup
##     <dbl>  <dbl>
##  1      1      9
##  2      2     11
##  3      2      1
##  4      1      8
##  5      2      2
##  6      2      6
##  7      1      3
##  8      2      4
##  9      1      8
## 10      2      3
## 11      1     10
## 12      2      6


Compute t-test.

boys <- classroom %>%
    filter( gender == 1 ) %>%
    select( -gender )
girls <- classroom %>%
    filter( gender == 2 ) %>%
    select( -gender )
res <- t.test( boys , girls )
res
## 
##  Welch Two Sample t-test
## 
## data:  boys and girls
## t = 1.6482, df = 9.7633, p-value = 0.1311
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.028259  6.799687
## sample estimates:
## mean of x mean of y 
##  7.600000  4.714286


1] The means:
x, boys: 7.6
y, girls: 4.7142857

2] Degree of freedom:
9.7633129

3] T-test statistic:
1.6481881

4] P-value:
0.1310716

5] At alpha value of 0.05
Is p-value \(\le\) 0.05? FALSE
Do NOT reject the null hypothesis. There is a difference.

6] What critical value would your obtained t-test value have to exceed to be significant at the 0.01 level? - assume a two-tailed test.

Formula: qt( 0.01/2 , 'degrees of freedom' , lower.tail=FALSE)

df <- res$parameter
t_crit <- qt( 0.01/2 , df , lower.tail = FALSE )

The critical value is 3.1865649.
Given a two-tailed test, the critical values would have to be: \(\lt\) -3.1865649 and \(\gt\) 3.1865649.



GitHub

Related file(s) can be found at Git Me

No comments:

Post a Comment