Independent samples t-test¶
In a independent samples t-test we compare means of two populations that are independent of eachother. First we formulate a null hypothesis, assume the null hypothesis is true, and then test that. The t-test looks at mean, standard deviation, and sample size of two populations in order to calculate a t-value and the number of degrees of freedom. Based on that we obtain a p-value. The p-value tells us what the chances are that the observed differences are explained by random occurrence.
import pandas as pd
from scipy.stats import ttest_ind
df = pd.read_csv('Gaming and Mental Health.csv')
t, p = ttest_ind(df[df['gender']=='Male']['daily_gaming_hours'], df[df['gender']=='Female']['daily_gaming_hours'], equal_var=False)
print(f't-stat: {round(t, 2)}, p-value: {round(p, 2)}')
The p-value we obtain here is 0.17, meaning there is a 17% chance that observed differences between means are explained by random occurrence. If we turn this around we can say that there is a 83% chance that the difference between the means of the two populations are statistically significant.
Some more reading: https://www.geeksforgeeks.org/maths/t-test-in-statistics/
This tutorial uses the “Gaming and Mental Health” licensed under the Apache License 2.0. © Shaista Shahid. License: http://www.apache.org/licenses/LICENSE-2.0 source: https://www.kaggle.com/datasets/shaistashahid/gaming-and-mental-health?resource=download