Independent and dependent t-tests

Hi there,

I am new to R and I'm having an assignment that requires the application of t-test (both independent and dependent ones). I just want to ask if the codes I used are correct or not, because the results I found were both of the hypotheses were NOT supported.

Synopsis: Suppose you have a student list with the following variables: gender (male/female), study_per_week (study hours per week), love_of_stat (love of statistics, rating 1-10), heart_rate_before (heart rate before exam), and heart_rate_after (heart rate after exam).

  1. You want to know if male students study significantly less hours per week than female students.

I use independent t-test with the following code:

t.test(study_per_week ~ gender, data = filtered_exams)

Here is the results for your reference:
#>
#> Welch Two Sample t-test
#>
#> data: study_per_week by gender
#> t = 1.6676, df = 55, p-value = 0.1011
#> alternative hypothesis: true difference in means between group female and group male is not equal to 0
#> 95 percent confidence interval:
#> -0.1178838 1.2866183
#> sample estimates:
#> mean in group female mean in group male
#> 3.423077 2.838710

  1. You want to know if students in general have significantly higher heart rate after exam compared to before exam.

I use dependent t-test with the following code:

t.test(
x = filtered_exams$heart_rate_before,
y = filtered_exams$heart_rate_after,
pair = TRUE )

here is the results for your reference:
#>
#> Paired t-test
#>
#> data: filtered_exams$heart_rate_before and filtered_exams$heart_rate_after
#> t = 16.706, df = 56, p-value < 2.2e-16
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#> 6.531164 8.310941
#> sample estimates:
#> mean of the differences
#> 7.421053

  1. You want to know if the mean of the students' love of statistics is significantly lower than 5.17.

I use single sample t-test with the following code:

t.test(filtered_exams$love_of_stats, mu = 5.17)

here is the results for your reference:
#>
#> One Sample t-test
#>
#> data: filtered_exams$love_of_stats
#> t = -1.3787, df = 56, p-value = 0.1735
#> alternative hypothesis: true mean is not equal to 5.17
#> 95 percent confidence interval:
#> 3.978344 5.390077
#> sample estimates:
#> mean of x
#> 4.684211

**Note: "filtered_exams" is my new data set after removing Outliners.

So, am I using the tests correctly, or am I misunderstanding any of their characteristics?
I'm sorry if my question is a bit too long, and thank you very much for your help!
Cheers,
Esther

This is an example of the questions being more difficult than the answers. Things get off on the wrong foot immediately by how they pose the questions.

You want to know if male students study significantly less hours per week than female students.

Significant in all its forms is a "term of art" in statistics, meaning that it does not mean what it means ordinarily. For example, using hours per week, it is possible that a difference of one hour is significant but a difference of 20 hours is not. So, the first thing is that the absolute size of a difference has no necessary relation to its statistical difference.

The first step to applying statistical tests that return a p-value or other result with a confidence level is to select a value, conventionally called \alpha that reflects the nature of the problem. Then 1-\alpha is the probability that a result as extreme as the statistical test is purely the result of random variation. So, for example, when comparing quality assurance for nuclear power plant containment systems, \alpha = 0.00000000001 might be appropriate. On the other hand, in assessing the plausibility of a hunch about social behavior of undergraduate subjects, \alpha = 0.05 to determine whether to spend more resources studying it, that level is appropriate and, indeed, is often the default. To avoid being carried away with results that are significant at the 95% confidence level consider that it may be equally likely that 19 other researchers attempting to replicate the analysis with other subjects may not find that the same threshold is met.

The next thing to do after deciding \alpha is to confirm the assignment of the null hypothesis and the alternate hypothesis. In the case of the t.test the null (conventionally called H_0) is that there is no difference in the mean of two groups at the selected \alpha. The *alternative (H_1) is that there is a difference.

In the case of study hours, the t-test value of 1.6676 on 55 degrees of freedom has a p-value of 0.1011. We say, therefore, that we cannot reject the null hypothesis and say that the difference between the means of 3.423077 and 2.838710 is "significant" and not merely due to chance.

Compare this with the other examples.

Finally, be careful about removing outliers in small populations.

1 Like

Thank you very much for your help! and I'm really sorry for the wording. I think the question had a better explanation than my paraphrase to avoid misunderstanding or errors.

Regarding your explanation of the result,
" In the case of study hours, the t-test value of 1.6676 on 55 degrees of freedom has a p-value of 0.1011. We say, therefore, that we cannot reject the null hypothesis and say that the difference between the means of 3.423077 and 2.838710 is "significant" and not merely due to chance."

I would like to double confirm that since p-value > 0.05, we cannot reject the null hypothesis, which states that the true mean difference is equal to 0, and thus can safely conclude that the hypothesis 1, that male students study significantly less hours per week than female, is NOT supported, is that correct?

Also, I would really appreciate it if you could also comment whether my codes for Question 2 are correct or not. The result I got show that we can reject the null hypothesis, but the mean of the heart rate before exam is significantly higher than the mean of the heart rate after exam, leading to Hypothesis 2 NOT supported either.

Cheers,
Esther

(I meant that in general questions are more difficult, only)

The codes return the values for the function that they are supposed to return. Whether those values are correct compared to the values that the data is supposed to represent depends on the quality of the data and, in many cases, the quantity.

If you are concerned with the results of the test, assuming data validity, a reprex would be helpful. See the FAQ: How to do a minimal reproducible example reprex for beginners. For know we can just focus on the results at hand.

Q1. The null hypothesis is that the difference between the means does differ from zero at the 0.05 significance (95% confidence interval) level. If the p-value is <= 0.05 *Here, I got the next part backwards, illustrating why it's always necessary to use a checklist. We reject the null and accept the alternatives that the difference does not differ from zero.

Q2. Here the p-value is very small. In fact it is equal to the floating point error in the computer's hardware. In this case we say that "we fail to reject the null" meaning that we cannot accept the alternative--that the the difference is non-zero.

Q3 is like Q1.

See this MIT handout.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.