99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀R語言用于數(shù)據(jù)分析的基本統(tǒng)計(jì)函數(shù)與基礎(chǔ)可視化
R語言用于數(shù)據(jù)分析的基本統(tǒng)計(jì)函數(shù)與基礎(chǔ)可視化
2017-12-17
收藏

R語言用于數(shù)據(jù)分析的基本統(tǒng)計(jì)函數(shù)與基礎(chǔ)可視化

1.函數(shù)的基本用法

#將數(shù)據(jù)導(dǎo)入R中
> data(iris)   
#平均數(shù)
> mean(iris$Sepal.Length)
[1] 5.843333
#標(biāo)準(zhǔn)差
> sd(iris$Sepal.Length)
[1] 0.8280661
#方差
> var(iris$Sepal.Length)
[1] 0.6856935
#最小值
> min(iris$Sepal.Length)
[1] 4.3
#最大值
> max(iris$Sepal.Length)
[1] 7.9
#中位數(shù)
> median(iris$Sepal.Length)
[1] 5.8
#值的范圍
> range(iris$Sepal.Length)
[1] 4.3 7.9
#分位點(diǎn)
> quantile(iris$Sepal.Length)
  0%  25%  50%  75% 100%
 4.3  5.1  5.8  6.4  7.9
sapply()函數(shù)

#忽略缺失值(na.rm=TRUE),求iris數(shù)據(jù)框前4個(gè)屬性的平均值
> sapply(iris[1:4],mean,na.rm=TRUE)
Sepal.Length  Sepal.Width Petal.Length  Petal.Width
    5.843333     3.057333     3.758000     1.199333
#此處也可以用summary(iris)
> summary(iris)
  Sepal.Length    Sepal.Width     Petal.Length    Petal.Width          Species 
 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100   setosa    :50 
 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300   versicolor:50 
 Median :5.800   Median :3.000   Median :4.350   Median :1.300   virginica :50 
 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199                 
 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800                 
 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500
變量間的關(guān)聯(lián)進(jìn)行分析

             Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length    1.0000000  -0.1175698    0.8717538   0.8179411
Sepal.Width    -0.1175698   1.0000000   -0.4284401  -0.3661259
Petal.Length    0.8717538  -0.4284401    1.0000000   0.9628654
Petal.Width     0.8179411  -0.3661259    0.9628654   1.0000000
每一個(gè)屬性對的協(xié)方差系數(shù)cov(iris[,1:4])

> cov(iris[,1:4])
             Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length    0.6856935  -0.0424340    1.2743154   0.5162707
Sepal.Width    -0.0424340   0.1899794   -0.3296564  -0.1216394
Petal.Length    1.2743154  -0.3296564    3.1162779   1.2956094
Petal.Width     0.5162707  -0.1216394    1.2956094   0.5810063
統(tǒng)計(jì)檢驗(yàn)可用來評估結(jié)果的顯著性,下例用t檢驗(yàn)來分析樣本之間的差異,具體任務(wù)是用t檢驗(yàn)判斷setosa與versicolor兩類鳶尾花的花萼寬度的差別。如果p<0.5,說明這兩類花的花萼寬度差別非常明顯:

> t.test(iris$Petal.Width[iris$Species=="setosa"],
+ iris$Petal.Width[iris$Species=="versicolor"])

    Welch Two Sample t-test

data:  iris$Petal.Width[iris$Species == "setosa"] and iris$Petal.Width[iris$Species == "versicolor"]
t = -34.08, df = 74.755, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -1.143133 -1.016867
sample estimates:
mean of x mean of y
    0.246     1.326
同樣也可以對鳶尾花的花萼寬度與花萼長度進(jìn)行進(jìn)行關(guān)聯(lián)性檢驗(yàn),評分越接近1,正向相關(guān)越強(qiáng),反之亦然。

> cor.test(iris$Sepal.Length[iris$Species=="setosa"],
+        + iris$Sepal.Width[iris$Species=="setosa"])

    Pearson's product-moment correlation

data:  iris$Sepal.Length[iris$Species == "setosa"] and +iris$Sepal.Width[iris$Species == "setosa"]
t = 7.6807, df = 48, p-value = 6.71e-10
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.5851391 0.8460314
sample estimates:
      cor
0.7425467
基礎(chǔ)可視化

> data(iris)
> table.iris = table(iris$Species)
> table.iris

    setosa versicolor  virginica
        50         50      50
> pie(table.iris)

花萼分布的直方圖

> hist(iris$Sepal.Length)

盒圖,也稱箱圖

boxplot(Petal.Width ~ Species,data = iris)

散點(diǎn)圖,用在同一個(gè)圖中比較兩個(gè)變量關(guān)系的圖

plot(x=iris$Petal.Length,y=iris$Ptal.Width,col=iris$Species)

繪制所有有兩兩之間的關(guān)系圖
> pairs(iris[1:4],main = "IRIS DATE",pch=21,bg=c("red","green","blue")[unclass(iris$Species)])

數(shù)據(jù)分析咨詢請掃描二維碼

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

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }