因為我都是看的英語的資料所以中文的術語肯定會有些問題,歡迎指正
以下來自維基
In the t-test comparing the means of two independent samples, the following assumptions should be met:
The means of the two populations being compared should follow normal distributions. Under weak assumptions, this follows in large samples from the central limit theorem, even when the distribution of observations in each group is non-normal.[18]
If using Student's original definition of the t-test, the two populations being compared should have the same variance (testable using <a href="wikiwand.com/en/F-test_">F-test, Levene's test, Bartlett's test, or the Brown–Forsythe test; or assessable graphically using a Q–Q plot). If the sample sizes in the two groups being compared are equal, Student's original t-test is highly robust to the presence of unequal variances.[19]Welch's t-test is insensitive to equality of the variances regardless of whether the sample sizes are similar.
The data used to carry out the test should either be sampled independently from the two populations being compared or be fully paired. This is in general not testable from the data, but if the data are known to be dependent (e.g. paired by test design), a dependent test has to be applied. For partially paired data, the classical independent t-tests may give invalid results as the test statistic might not follow a t distribution, while the dependent t-test is sub-optimal as it discards the unpaired data.[20]
意思就是做t test之前一般要確保數據分布滿足normal distribution和same variance (Homoscedasticity),當然了也有Heteroscedastic t-tests,按下不表
那麼如何看數據分布是否是normal distributionlibrary("tidyverse")
library("ggpubr")
library("readr")
library("rstatix")
看density plot
ggdensity(ToothGrowth$len, fill = "lightgray")看qqplot
ggqqplot(ToothGrowth$len)ToothGrowth %>% shapiro_test(len)<chr> <dbl> <dbl>
1 len 0.967 0.109
三項測試都顯示數據分布接近正態
iris %>% shapiro_test(Sepal.Length, Petal.Width)variable statistic p
<chr> <dbl> <dbl>
1 Petal.Width 0.902 0.0000000168
2 Sepal.Length 0.976 0.0102
ToothGrowth %>% group_by(dose) %>% shapiro_test(len) dose variable statistic p<dbl> <chr> <dbl> <dbl>
1 0.5 len 0.941 0.247
2 1 len 0.931 0.164
3 2 len 0.978 0.902
有用的R包install.packages('tidyverse')
install.packages('broom')
install.packages('gridExtra')
install.packages('car')
install.packages('MASS')
install.packages('pscl')
install.packages('effsize')
install.packages('lme4')
install.packages('afex')
install.packages('brms')
install.packages('MuMIn')
install.packages('swirl')
install.packages('languageR')
install.packages('emmeans')
install.packages("ggpubr")
install.packages("rstatix")
install.packages("datarium")