R語言-配對(duì)t檢驗(yàn)

準(zhǔn)備data demo

rm(list=ls())
install.packages("datarium")
data("mice2", package = "datarium")
# Transform into long data: 
# gather the before and after values in the same column
library(tidyr)
mice2.long <- mice2 %>%
  gather(key = "group", value = "weight", before, after)
head(mice2.long, 3)

方法一:把配對(duì)的數(shù)據(jù)分別保存在兩個(gè)數(shù)值型向量里(確保數(shù)值的配對(duì)位置)

before <- mice2$before
after <- mice2$after
# Compute t-test
res <- t.test(before, after, paired = TRUE)
res

方法二:把配對(duì)的數(shù)據(jù)分別保存在一個(gè)數(shù)據(jù)框里(確保數(shù)值的配對(duì)位置)

# Compute t-test
res <- t.test(weight ~ group, data = mice2.long, paired = TRUE)
res
mice2_dataframe.png

結(jié)果解析

Paired t-test

data:  weight by group
t = 25.546, df = 9, p-value = 1.039e-09   #檢驗(yàn)統(tǒng)計(jì)量,自由度,P值
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:  #95%可信區(qū)間
 181.8158 217.1442
sample estimates:
mean of the differences 
                 199.48 

https://www.datanovia.com/en/lessons/how-to-do-a-t-test-in-r-calculation-and-reporting/how-to-do-paired-t-test-in-r/
https://www.statology.org/paired-samples-t-test-r/

此處加個(gè)私貨推薦,果子老師的統(tǒng)計(jì)方法整理,看了之后能解決大部分問題

https://mp.weixin.qq.com/s?__biz=MzIyMzA2MTcwMg==&mid=2650733796&idx=1&sn=76b2b657f96290be622337c4a10d3036&scene=21#wechat_redirect
https://mp.weixin.qq.com/s/IF4F0W2ghWRq4ILVP3T49A

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容