两个样本差异比较的方法。

    比如两个向量集:

    1. > head(boy)
    2. [1] 177.97 171.89 170.29 158.69 177.36 182.50
    3. > head(girl)
    4. [1] 151.11 158.74 155.47 158.62 176.03 153.65

    直接t 检验好了:

    1. > t.test(boy, girl)
    2. Welch Two Sample t-test
    3. data: boy and girl
    4. t = 6.3941, df = 97.71, p-value = 5.552e-09
    5. alternative hypothesis: true difference in means is not equal to 0
    6. 95 percent confidence interval:
    7. 7.506641 14.263359
    8. sample estimates:
    9. mean of x mean of y
    10. 170.0252 159.1402

    如果想要检测单边的,比如 x 是否显著大于 y,加个参数 alternative(greater 与 less) :

    1. > t.test(boy, girl, alternative = 'greater')
    2. Welch Two Sample t-test
    3. data: boy and girl
    4. t = 6.3941, df = 97.71, p-value = 2.776e-09
    5. alternative hypothesis: true difference in means is greater than 0
    6. 95 percent confidence interval:
    7. 8.058101 Inf
    8. sample estimates:
    9. mean of x mean of y
    10. 170.0252 159.1402

    如果想要做一般的t 检验(student-t-test):

    1. > t.test(boy, girl, alternative = 'greater', var.equal= T)
    2. Two Sample t-test
    3. data: boy and girl
    4. t = 6.3941, df = 98, p-value = 2.753e-09
    5. alternative hypothesis: true difference in means is greater than 0
    6. 95 percent confidence interval:
    7. 8.058181 Inf
    8. sample estimates:
    9. mean of x mean of y
    10. 170.0252 159.1402

    比较两个组之间的差异,箱线图是最好的可视化方法之一了:

    1. ggplot(data = clinical_info_final) +
    2. geom_boxplot(mapping = aes(x = condition_brca1, y = Age_at_surgery, fill = condition_brca1))
    3. ggplot(data = clinical_info_final) +
    4. geom_boxplot(mapping = aes(x = condition_brca2, y = Age_at_surgery, fill = condition_brca2))
    5. condition_brca2

    02. t检验与箱线图 - 图1