熱線電話:13121318867

登錄
首頁精彩閱讀使用R完成均值檢驗
使用R完成均值檢驗
2018-03-10
收藏

使用R完成均值檢驗

t檢驗和Z檢驗都可用于均值檢驗。
單樣本均值檢驗
當樣本容量小于30時使用t檢驗,當樣本容量大于30時使用Z檢驗

Z檢驗使用例子:
[plain] view plain copy

    library(UsingR)  
    x<-rnorm(50,0,5)  
    simple.z.test(x,5)  

運行結果:
[1] -2.947929 3.250022
結果說明在置信度為95%的情況下總體的均值區間為[-2.947929 3.250022]

t檢驗使用例子:
[plain] view plain copy

    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的幫助文檔有很好的例子:
[plain] view plain copy

    require(graphics)  
      
    t.test(1:10, y = c(7:20))      # P = .00001855  
    t.test(1:10, y = c(7:20, 200)) # P = .1245    -- NOT significant anymore  
      
    ## Classical example: Student's sleep data  
    plot(extra ~ group, data = sleep)  
    ## Traditional interface  
    with(sleep, t.test(extra[group == 1], extra[group == 2]))  
    ## Formula interface  
    t.test(extra ~ group, data = sleep)  

此外《統計建模與R語言》從P206頁開始有討論正太總體均值的建設檢驗,書中作者編寫了自己的均值檢驗函數mean.test1(針對單個總體)和mean.test2(針對兩個總體),也有相對應的使用t.test函數進行檢驗的例子,具體應用時可以參考。

數據分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數據分析師資訊
更多

OK
客服在線
立即咨詢
日韩人妻系列无码专区视频,先锋高清无码,无码免费视欧非,国精产品一区一区三区无码
客服在線
立即咨詢