使用R完成均值檢驗_R

來源:互聯網
上載者:User
t檢驗和 Z檢驗都可用於均值檢驗。

單樣本均值檢驗
當樣本容量小於30時使用t檢驗,當樣本容量大於30時使用Z檢驗
Z檢驗使用例子:
library(UsingR)x<-rnorm(50,0,5)simple.z.test(x,5)
運行結果:
[1] -2.947929 3.250022
結果說明在信賴度為95%的情況下總體的均值區間為[-2.947929 3.250022]
t檢驗使用例子:
x<-rnorm(20,0,5)t.test(x)
運行結果:
        One Sample t-test


data: x
t = -0.1736, df = 19, p-value = 0.864
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 -2.886276 2.444247
sample estimates:
 mean of x 
-0.2210147

------------------------------------------------------------------------------------

雙樣本均值檢驗
對t.test函數,R的協助文檔有很好的例子:
require(graphics)t.test(1:10, y = c(7:20))      # P = .00001855t.test(1:10, y = c(7:20, 200)) # P = .1245    -- NOT significant anymore## Classical example: Student's sleep dataplot(extra ~ group, data = sleep)## Traditional interfacewith(sleep, t.test(extra[group == 1], extra[group == 2]))## Formula interfacet.test(extra ~ group, data = sleep)
此外《統計建模與R語言》從P206頁開始有討論正太總體均值的建設檢驗,書中作者編寫了自己的均值檢驗函數mean.test1(針對單個總體)和mean.test2(針對兩個總體),也有相對應的使用t.test函數進行檢驗的例子,具體應用時可以參考。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.