2024-02-18

Introduction about Hypothesis Test for Pair Data

  • Paired data is a natural matching between subjects in one sample and the subjects in the other sampleor when different individuals in the two samples are linked in some ways and are treated as a unit.
  • There are many method to conduct hypothesis test for pair data, but this slide only focus on t-test.

Paired t-tested.

  • To set up the Hypothesis Test, it is important to understand the Null Hypothesis, and Alternative hypothesis.

  • Null Hypothesis (\(H_0\)): This is a statement of no effect or no difference, and it is what we assume to be true before collecting data. For example, \(H_0: \mu_1 = \mu_2\) or \(\mu_1-\mu_2 =0\).

  • Alternative Hypothesis (\(H_1\) or \(H_a\)): This is what we want to test against the null hypothesis.

  • \(H_a: \mu_1 \neq \mu_0\) or \(\mu_1-\mu_2 \neq0\) for a two-tailed test

  • \(H_a: \mu_1 > \mu_2\) or \(\mu_1-\mu_2 >0\) for a right tail test

  • \(H_a: \mu < \mu_0\) or \(\mu_1-\mu_2 <0\) for a left tail test .

Test Statistic Formula

  • Test Statistic: \[t=\frac{\bar{d}}{\frac{s_d}{\sqrt{n_d}}}\]
  • \(\bar{d}\): mean of the difference
  • n: the size of sample
  • \(s_d=\sqrt{\frac{\sum{(x_i-\bar{x})^2}}{n-1}}\)
  • \(\bar{x}\): sample mean

Example of paired t-test

  • To understand more about how to perform a hypothesis test. Here is an example of using hypothesis test.
  • A private agency claims that the crash course it offers significantly increases the writing speed of secretaries. The following table gives the scores of eight secretaries before and after they attended this course. Assume that the population of paired differences is approximately normally distributed.
##   before after
## A     81    97
## B     74    72
## C     89    99
## D     91   110
## E     65    78
## F     70    69
## G     90   115
## H     64    72

Plotly Plot

grh=plot_ly(data,x=~name,width=600,height=300,
y=~before, type='bar',name='before',marker=list(color="blue"))
grh=grh%>% add_trace(y=~after,name='after',marker = list(color = "orange"))
grh=grh%>% layout(xaxis=list(title = "Students", tickangle = -45),
         yaxis = list(title = "Grades"),
         barmode = 'group')

Perform Hypothesis Test

  • At the 5% significance level, is there sufficient evidence to suggest attending this course increases the writing speed of secretaries
  • \(\mu_1\): Mean speed before attending the course; \(\mu_2\): Mean speed after sttending the course
  • \(H_0: \mu_1-\mu_2=0\);\(H_a: \mu_1-\mu_2<0\) \(\bar{d}=\frac{-16+3-4-19-13+1-25-8}{8}=-10.125\) \(s_d=\sqrt{\frac{(-16-(-10.125))^2+...+(-8-(-10.125)^2)}{8-1}}=9.862446813\) Test statistic = \(\frac{\bar{d}}{\frac{s_d}{\sqrt{n_d}}}=\frac{-10.125}{\frac{9.862446813}{\sqrt{7}}}=-2.716185195\)
  • The test statistic is inside the rejection region. Thus reject \(H_0\). There is enough evidence to suggest the mean speed has increased after the course.

GGplot

GGplot