确定一个数据集的数据分布情况:正态分布情况,QQ图,Shapiro-Wilk normality test, Kolmogorov-Smirnov test

最简单确认数据分布的方式是检查数据本身,两种相对不同的汇总:summary和fivenum以及通过图像呈现 a display of the numbers bystem(a “stem and leaf” plot)

> attach(faithful)

> summary(eruptions)

  Min. 1st Qu.  Median    Mean 3rd Qu.    Max.

  1.600  2.163  4.000  3.488  4.454  5.100

> fivenum(eruptions)

[1] 1.6000 2.1585 4.0000 4.4585 5.1000

> stem(eruptions)

  The decimal point is 1 digit(s) to the left of the |

  16 | 070355555588

  18 | 000022233333335577777777888822335777888

  20 | 00002223378800035778

  22 | 0002335578023578

  24 | 00228

  26 | 23

  28 | 080

  30 | 7

  32 | 2337

  34 | 250077

  36 | 0000823577

  38 | 2333335582225577

  40 | 0000003357788888002233555577778

  42 | 03335555778800233333555577778

  44 | 02222335557780000000023333357778888

  46 | 0000233357700000023578

  48 | 00000022335800333

  50 | 0370

直方图:

> hist(eruptions)

##x轴分箱变小,画出密度曲线

> hist(eruptions, seq(1.6, 5.2, 0.2), prob=TRUE

我们能够画出数据集的积累分布图,通过使用函数ecdf.

> plot(ecdf(eruptions), do.points=FALSE, verticals=TRUE)


调整分布情况

> long <- eruptions[eruptions > 3]

> plot(ecdf(long), do.points=FALSE, verticals=TRUE)

Quantile-quantile (Q-Q) plots QQ图可以帮助我们更为精细的呈现.

> qqnorm(long); qqline(long)

> qqplot(qt(ppoints(250), df = 5), long, xlab = "Q-Q plot for t dsn")#更改标题

>shapiro.test(long)#检验

Shapiro-Wilk normality test

data:  long

W = 0.9793, p-value = 0.01052

and the Kolmogorov-Smirnov test

> ks.test(long, "pnorm", mean = mean(long), sd = sqrt(var(long)))

        One-sample Kolmogorov-Smirnov test

data:  long

D = 0.0661, p-value = 0.4284

alternative hypothesis: two.sided

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,458评论 0 10
  • 一大早,两位小主就把一车铁给装好了。没等吃早餐,男主说,天热,我早去早回,卖完回来再吃早餐。他急急地开车走了,...
    狂小烹阅读 726评论 6 11
  • 榜 样 春节前,教授从黑龙江来北京看我了,带来了五种颜色的谷物,手里提着,怀里抱着的,一大堆东西。从遥远的黑龙江到...
    秦占勇阅读 228评论 0 0
  • 前端框架日新月异,Angularjs的MVVM模式风靡全球,React的MV模式也被大家捧得火热。我不知道有多少人...
    前端C罗阅读 2,981评论 1 2
  • 一、老板打人了! 这是一个真实而悲惨的故事。 就在昨天晚上,我正准备收拾东西下班,发现午餐碗没洗,就先去洗了碗,好...
    黎甜阅读 4,662评论 8 17