Frequency Distribution
2015-11-03 16:12
585 查看
Data set: faithful, 272*2, Waiting time between eruptions and the duration of the eruption for the Old Faithful geyser.
> breaks <- seq(1.5, 5.5, by = 0.5)
Cutting duration into different class.
Out() function divides the range of x into intervals and codes the values in x according to which interval they fall.
Arguments: X - a numeric vector
breaks - either a numeric vector of two or more unique cut points or a single number giving the number of intervals into which x is to be cut.
right - logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa. The default is TRUE, meaning open on the left, close on the right.
Computing the cumulative frequency of each class.
Drawing a draft to show cumulative frequency.
ecdf() compute an empirical cumulative distribution function
> duration
[1] 4 2 3 2 5 3 5 4 2 4 2 4 4 2 5 2 2 5 2 4 2 2 3 3 5 4 2 4 4 4 4 4 3 4 4 2 2 5 2 5 4
[42] 2 5 2 5 3 4 2 5 2 5 5 2 5 2 5 4 2 5 4 2 4 2 5 2 4 4 5 2 5 4 2 4 4 2 5 2 5 4 4 4 4
[83] 4 3 4 5 4 5 2 4 2 4 2 5 2 4 5 4 2 5 2 4 2 4 4 2 5 2 5 4 5 2 5 4 2 5 2 5 2 4 3 4 4
[124] 2 5 4 2 4 2 5 2 4 3 4 2 4 2 5 2 4 4 2 5 5 4 2 5 2 5 2 5 4 2 5 4 4 4 4 2 4 2 4 2 4
[165] 4 5 2 5 2 5 2 2 5 3 4 4 4 2 4 4 2 5 4 4 2 4 4 2 4 2 5 2 5 4 4 4 4 4 2 5 2 4 4 2 5
[206] 2 4 4 2 4 2 5 2 4 3 4 2 5 2 4 2 4 2 4 4 4 4 4 4 5 4 2 4 2 4 2 2 4 4 2 4 2 5 3 5 4
[247] 2 4 2 4 2 4 4 4 4 4 4 4 2 4 5 5 2 4 2 2 5 4 2 4 2 4
> Fn <- ecdf(duration)
> Fn
Empirical CDF
Call: ecdf(duration)
x[1:126] = 1.6, 1.667, 1.7, ..., 5.067, 5.1
> plot(Fn)
> head(faithful) eruptions waiting 1 3.600 79 2 1.800 54 3 3.333 74 4 2.283 62 5 4.533 85 6 2.883 55Checking the range of duration.
> duration <- faithful$eruptions > range(duration) [1] 1.6 5.1Setting breaks of the distribution
> breaks <- seq(1.5, 5.5, by = 0.5)
Cutting duration into different class.
Out() function divides the range of x into intervals and codes the values in x according to which interval they fall.
Arguments: X - a numeric vector
breaks - either a numeric vector of two or more unique cut points or a single number giving the number of intervals into which x is to be cut.
right - logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa. The default is TRUE, meaning open on the left, close on the right.
> duration.cut <- cut(duration, breaks, right = F) > duration.cut [1] [3.5,4) [1.5,2) [3,3.5) [2,2.5) [4.5,5) [2.5,3) [4.5,5) [3.5,4) [1.5,2) [4,4.5) [11] [1.5,2) [3.5,4) [4,4.5) [1.5,2) [4.5,5) [2,2.5) [1.5,2) [4.5,5) [1.5,2) [4,4.5) ......Compute the frequency of each class
> duration.freq <- table(duration.cut) > duration.freq duration.cut [1.5,2) [2,2.5) [2.5,3) [3,3.5) [3.5,4) [4,4.5) [4.5,5) [5,5.5) 51 41 5 7 30 73 61 4 > cbind(duration.freq) duration.freq [1.5,2) 51 [2,2.5) 41 [2.5,3) 5 [3,3.5) 7 [3.5,4) 30 [4,4.5) 73 [4.5,5) 61 [5,5.5) 4
Computing the cumulative frequency of each class.
> duration.comfreq <- cumsum(duration.freq) > duration.comfreq [1.5,2) [2,2.5) [2.5,3) [3,3.5) [3.5,4) [4,4.5) [4.5,5) [5,5.5) 51 92 97 104 134 207 268 272
Drawing a draft to show cumulative frequency.
> comfreq0 <- c(0, duration.comfreq) > comfreq0 [1.5,2) [2,2.5) [2.5,3) [3,3.5) [3.5,4) [4,4.5) [4.5,5) [5,5.5) 0 51 92 97 104 134 207 268 272 > plot(breaks, comfreq0) > lines(breaks, comfreq0)
ecdf() compute an empirical cumulative distribution function
> duration
[1] 4 2 3 2 5 3 5 4 2 4 2 4 4 2 5 2 2 5 2 4 2 2 3 3 5 4 2 4 4 4 4 4 3 4 4 2 2 5 2 5 4
[42] 2 5 2 5 3 4 2 5 2 5 5 2 5 2 5 4 2 5 4 2 4 2 5 2 4 4 5 2 5 4 2 4 4 2 5 2 5 4 4 4 4
[83] 4 3 4 5 4 5 2 4 2 4 2 5 2 4 5 4 2 5 2 4 2 4 4 2 5 2 5 4 5 2 5 4 2 5 2 5 2 4 3 4 4
[124] 2 5 4 2 4 2 5 2 4 3 4 2 4 2 5 2 4 4 2 5 5 4 2 5 2 5 2 5 4 2 5 4 4 4 4 2 4 2 4 2 4
[165] 4 5 2 5 2 5 2 2 5 3 4 4 4 2 4 4 2 5 4 4 2 4 4 2 4 2 5 2 5 4 4 4 4 4 2 5 2 4 4 2 5
[206] 2 4 4 2 4 2 5 2 4 3 4 2 5 2 4 2 4 2 4 4 4 4 4 4 5 4 2 4 2 4 2 2 4 4 2 4 2 5 3 5 4
[247] 2 4 2 4 2 4 4 4 4 4 4 4 2 4 5 5 2 4 2 2 5 4 2 4 2 4
> Fn <- ecdf(duration)
> Fn
Empirical CDF
Call: ecdf(duration)
x[1:126] = 1.6, 1.667, 1.7, ..., 5.067, 5.1
> plot(Fn)
相关文章推荐
- C#实现统计字数功能的方法
- PowerShell统计文件夹下文件个数的方法
- 如何统计全天各个时间段产品销量情况(sqlserver)
- C#统计字符串中数字个数的方法
- C语言中使用lex统计文本文件字符数
- 如何统计在一篇文章中某个单词出现了几次,以及第一次出现的位置
- SQL进行排序、分组、统计的10个新技巧分享
- js统计网页在线时间的脚本
- C语言实现统计字符串单词数
- jQuery圆形统计图开发实例
- jQuery统计指定子元素数量的方法
- php下统计用户在线时间的一种尝试
- php ajax网站浏览统计功能的简单实现第1/2页
- JSP实现网页访问统计
- php下用cookie统计用户访问网页次数的代码
- Redis中统计各种数据大小的方法
- 也谈php网站在线人数统计
- asp实现一个统计当前在线用户的解决方案
- php使用Session和文件统计在线人数
- 用js统计用户下载网页所需时间的脚本