簡體   English   中英

為什么R的t檢驗函數存在錯誤和/或不一致的自由度?

[英]Why are there wrong and/or inconsistent degrees of freedom from R's t-test function?

我有一個簡單的問題。 我已經在R中看到了t檢驗和相關性的這種行為。

我做了一個簡單的配對t檢驗(在這種情況下,兩個長度為100的向量)。 所以配對t檢驗的df應該是99.但是這不是t檢驗結果輸出中出現的。

dataforTtest.x <- rnorm(100,3,1)
dataforTtest.y <- rnorm(100,1,1)
t.test(dataforTtest.x, dataforTtest.y,paired=TRUE)

這個輸出是:

Paired t-test

data:  dataforTtest.x and dataforTtest.y
t = 10, df = 100, p-value <2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
1.6 2.1
sample estimates:
mean of the differences 
                1.8 

但是,如果我實際查看結果對象,則df是正確的。

> t.test(dataforTtest.x, dataforTtest.y,paired=TRUE)[["parameter"]]

df 
99 

我錯過了一些非常愚蠢的東西嗎? 我正在運行R版本3.3.0(2016-05-03)

如果舍入數字的全局設置在R中發生變化,則可能會發生此問題,這可以通過選項(數字= 2)來完成。

在更改此設置之前,請注意t檢驗的結果:

    Paired t-test

data:  dataforTtest.x and dataforTtest.y
t = 13.916, df = 99, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 1.700244 2.265718
sample estimates:
mean of the differences 
               1.982981 

設置選項(數字= 2)后:

Paired t-test

data:  dataforTtest.x and dataforTtest.y
t = 13.916, df = 100, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 1.700244 2.265718
sample estimates:
mean of the differences 
                      2 

在R中,出於這個原因更改全局設置可能很危險。 在用戶不知情的情況下,它可以完全改變統計分析的結果。 相反,我們可以直接在數字上使用round()函數,或者對於這樣的測試結果,我們可以將它與掃帚包結合使用。

round(2.949,2)
[1] 2.95

#and

require(broom)

glance(t.test(dataforTtest.x, dataforTtest.y,paired=TRUE))

estimate statistic      p.value parameter cnf.low cnf.high       method alternative
1.831433  11.31853 1.494257e-19        99 1.51037 2.152496 Paired t-test  two.sided

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM