簡體   English   中英

我如何計算 t.-statistic 值並使用 R 找到兩側的 P 值?

[英]how do I calculate t.-statistic value and find two-sided P value using R?

下面是我的數據集

dput(ex0112)

數據集:

structure(list(BP = c(8L, 12L, 10L, 14L, 2L, 0L, 0L, -6L, 0L, 
1L, 2L, -3L, -4L, 2L), Diet = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("FishOil", "RegularOil"
), class = "factor")), class = "data.frame", row.names = c(NA, 
-14L))

為了找到整個(BP 列)的 t 統計量,我使用下面的 R 代碼實現了它。

library(Sleuth3)
t.test(BP~Diet, data=ex0112)

但是我如何計算對於 mu 為零的假設,並為(BP 列)構建 t 統計量,僅適用於常規油性飲食,以及如何找到兩側 p 值作為來自 t 分布的值的比例使用 R 比這個值離 0 更遠?

我會建議下一個方法。 您可以在t.test()使用一個變量,該變量具有mu參數和您想要的two-sided替代選項。 這里使用您的dput()數據作為df的代碼:

#Test
test <- t.test(df$BP[df$Diet=='RegularOil'], mu = 0, alternative = "two.sided")
test
#Extract p-value
test$p.value

輸出:

One Sample t-test

data:  df$BP[df$Diet == "RegularOil"]
t = -0.94943, df = 6, p-value = 0.3791
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 -4.088292  1.802578
sample estimates:
mean of x 
-1.142857 

和 p-val:

[1] 0.3790617

暫無
暫無

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

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