library(ggstatsplot)
library(ggplot2)
library(dplyr)
data("diamonds")
diamonds2 <- diamonds %>%
filter(color == c('J', 'H', 'F'), clarity %in% c('SI2', 'VS1', 'IF'))#篩選出diamonds中顏色為J喳张、H、F镀裤,清晰度為SI2穷当、VS1、IF的數(shù)據(jù)淹禾,并保存為diamonds2馁菜。
ggbarstats(diamonds2, color, clarity, palette = 'Set2')
#以下為統(tǒng)計(jì)結(jié)果
Note: 95% CI for effect size estimate was computed with 100 bootstrap samples.
Note: Results from one-sample proportion tests for each level of the variable
clarity testing for equal proportions of the variable color.
# A tibble: 3 x 9
condition N F H J `Chi-squared` df `p-value` significance
<ord> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr>
1 SI2 (n = 1208) 45.20% 41.72% 13.08% 225. 2 0 ***
2 VS1 (n = 966) 46.38% 38.20% 15.42% 149. 2 0 ***
3 IF (n = 251) 53.39% 39.44% 7.17% 84.6 2 0 ***
-如圖所示,卡方值為15.01铃岔,p = 0.005 < 檢驗(yàn)水準(zhǔn)0.05汪疮,可認(rèn)為鉆石的顏色與分類不獨(dú)立,即存在關(guān)聯(lián)毁习。
-各個(gè)clarity的組內(nèi)比較智嚷,不同顏色鉆石的數(shù)量的差異均具有顯著性(每個(gè)柱子上面為三顆星“*”,卡方值分別為225纺且, 149盏道, 84.6,均大于卡方分布在自由度為2载碌,α為0.05時(shí)的值5.99猜嘱,即p < 0.05, 所以都具有顯著性)。
ggpiestats(diamonds2, color, clarity, palette = 'Set3')
#以下為統(tǒng)計(jì)結(jié)果
Note: 95% CI for effect size estimate was computed with 100 bootstrap samples.
Note: Results from one-sample proportion tests for each level of the variable
clarity testing for equal proportions of the variable color.
# A tibble: 3 x 9
condition N F H J `Chi-squared` df `p-value` significance
<ord> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr>
1 SI2 (n = 1208) 45.20% 41.72% 13.08% 225. 2 0 ***
2 VS1 (n = 966) 46.38% 38.20% 15.42% 149. 2 0 ***
3 IF (n = 251) 53.39% 39.44% 7.17% 84.6 2 0 ***
-此圖統(tǒng)計(jì)結(jié)果與上面柱狀圖的結(jié)果一樣嫁艇,只是將柱狀圖換成餅圖朗伶。
-這種些圖形能夠方便快速的將統(tǒng)計(jì)數(shù)據(jù)快速可視化,不僅能得到基本的卡方統(tǒng)計(jì)量步咪,P值论皆,還可以得到各分組內(nèi)的分布狀況,如顏色為J的鉆石在分類為SI2的組內(nèi)占比為13%猾漫,占比最大的為顏色F点晴,占比45%。在分類VS1和IF組內(nèi)悯周,占比最大的也是顏色F粒督,分別占比46%和53%。
grouped_ggpiestats(diamonds2[diamonds2$cut != 'Very Good',], color, clarity, grouping.var = cut, simulate.p.value = T) #diamonds2[diamonds2$cut != 'Very Good',]表示去掉數(shù)據(jù)中cut為Very Good的數(shù)據(jù)队橙,simulate.p.value = T表示對(duì)P值進(jìn)行調(diào)整坠陈,因?yàn)閏ut為Fair的數(shù)據(jù)內(nèi),顏色為J和H的數(shù)量為0捐康。
#以下為統(tǒng)計(jì)結(jié)果
Note: 95% CI for effect size estimate was computed with 100 bootstrap samples.
Note: Results from one-sample proportion tests for each level of the variable
clarity testing for equal proportions of the variable color.
# A tibble: 3 x 9
condition N F H J `Chi-squared` df `p-value` significance
<ord> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr>
1 SI2 (n =~ 47.7~ 41.7~ 10.4~ 16.1 2 0 ***
2 VS1 (n =~ 42.8~ 35.7~ 21.4~ 2 2 0.368 ns
3 IF (n =~ 100.~ NA NA 6 2 0.05 ns
Note: 95% CI for effect size estimate was computed with 100 bootstrap samples.
Note: Results from one-sample proportion tests for each level of the variable
clarity testing for equal proportions of the variable color.
# A tibble: 3 x 9
condition N F H J `Chi-squared` df `p-value` significance
<ord> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr>
1 SI2 (n =~ 49.6~ 35.7~ 14.6~ 25.6 2 0 ***
2 VS1 (n =~ 48.1~ 31.3~ 20.4~ 9.71 2 0.008 **
3 IF (n =~ 69.2~ 15.3~ 15.3~ 7.54 2 0.023 *
Note: 95% CI for effect size estimate was computed with 100 bootstrap samples.
Note: Results from one-sample proportion tests for each level of the variable
clarity testing for equal proportions of the variable color.
# A tibble: 3 x 9
condition N F H J `Chi-squared` df `p-value` significance
<ord> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr>
1 SI2 (n =~ 44.5~ 42.0~ 13.3~ 71.7 2 0 ***
2 VS1 (n =~ 41.5~ 41.5~ 16.8~ 29.6 2 0 ***
3 IF (n =~ 40.0~ 48.0~ 12.0~ 5.36 2 0.069 ns
Note: 95% CI for effect size estimate was computed with 100 bootstrap samples.
Note: Results from one-sample proportion tests for each level of the variable
clarity testing for equal proportions of the variable color.
# A tibble: 3 x 9
condition N F H J `Chi-squared` df `p-value` significance
<ord> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr>
1 SI2 (n =~ 45.4~ 44.6~ 9.91% 84.7 2 0 ***
2 VS1 (n =~ 49.0~ 38.5~ 12.5~ 84.7 2 0 ***
3 IF (n =~ 52.5~ 42.3~ 5.08% 66.3 2 0 ***
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者