Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
影响用R中的hist()函数绘制的直方图的变量_R_Histogram - Fatal编程技术网

影响用R中的hist()函数绘制的直方图的变量

影响用R中的hist()函数绘制的直方图的变量,r,histogram,R,Histogram,在R中,可以绘制直方图并将其属性保存到变量: > h1=hist(c(1,1,2,3,4,5,5), breaks=0.5:5.5) 然后可以读取这些属性: > h1 $breaks [1] 0.5 1.5 2.5 3.5 4.5 5.5 $counts [1] 2 1 1 1 2 $density [1] 0.2857143 0.1428571 0.1428571 0.1428571 0.2857143 $mids [1] 1 2 3 4 5 $xname [1] "c(

在R中,可以绘制直方图并将其属性保存到变量:

> h1=hist(c(1,1,2,3,4,5,5), breaks=0.5:5.5)
然后可以读取这些属性:

> h1
$breaks
[1] 0.5 1.5 2.5 3.5 4.5 5.5

$counts
[1] 2 1 1 1 2

$density
[1] 0.2857143 0.1428571 0.1428571 0.1428571 0.2857143

$mids
[1] 1 2 3 4 5

$xname
[1] "c(1, 1, 2, 3, 4, 5, 5)"

$equidist
[1] TRUE

attr(,"class")
[1] "histogram"
这些属性如何影响直方图?到目前为止,我已经得出以下结论:

h1=hist(c(1,1,2,3,4,5,5,1.5), breaks=0.5:5.5)
$breaks
$counts
之间的关系
$breaks
表示打印数据可能下降到的间隔,
$counts
表示下降到该间隔的数据量,例如:

BREAKS  : DENSITY
[0.5-1.5] : 0.2857143 # This interval covers cca 28% of plot
(1.5-2.5] : 0.1428571 # This interval covers cca 14% of plot
(2.5-3.5] : 0.1428571 # This interval covers cca 14% of plot
(3.5-4.5] : 0.1428571 # This interval covers cca 14% of plot
(4.5-5.5] : 0.2857143 # This interval covers cca 28% of plot
[]表示(包括端点)

()表示(不包括端点)

$breaks
$density
之间的关系基本上与上述相同,但以百分比表示,例如:

BREAKS  : DENSITY
[0.5-1.5] : 0.2857143 # This interval covers cca 28% of plot
(1.5-2.5] : 0.1428571 # This interval covers cca 14% of plot
(2.5-3.5] : 0.1428571 # This interval covers cca 14% of plot
(3.5-4.5] : 0.1428571 # This interval covers cca 14% of plot
(4.5-5.5] : 0.2857143 # This interval covers cca 28% of plot
当然,当您将所有这些值相加时,您将得到1:

> sum(h1$density)
[1] 1
以下代表x轴名称:

$xname
[1] "c(1, 1, 2, 3, 4, 5, 5)"
但是剩下的部分做什么,特别是
$mids

$mids
[1] 1 2 3 4 5

$equidist
[1] TRUE

attr(,"class")
[1] "histogram"
另外,
help(hist)
还返回了许多其他文件,它们不应该也列在上面的输出中吗?如果不是,为什么?正如文章中所解释的

默认情况下,仓位计数包括小于或等于仓位的值 右断点并严格大于料仓的左断点 点,但最左侧的箱子除外,该箱子包括其左断点 重点

因此:

h1=hist(c(1,1,2,3,4,5,5,1.5), breaks=0.5:5.5)
将返回直方图,其中1.5分为0.5-1.5区间。一个“解决方法”是将间隔大小设置得更小,例如

h1=hist(c(1,1,2,3,4,5,5,1.5), breaks=seq(0.5,5.5,0.1))
但这对我来说似乎不现实,而且它还为
$counts
$density
添加了大量的0,有没有更好的自动方法

除此之外,它还有一个我无法解释的副作用:为什么最后一个示例返回摘要10而不是摘要1

> sum(h1$density)
[1] 10
> h1$density[h1$density>0]
[1] 2.50 1.25 1.25 1.25 1.25 2.50

问题1$mids和$equidist是什么意思: 从帮助文件:

mids:n个单元的中点

等距:逻辑上的,指示打断之间的距离是否都相同


问题2:是的,有
h1=hist(c(1,1,2,3,4,5,5,1.5),breaks=0.5:5.5)
1.5将归入0.5-1.5类。如果要将其归入1.5-2.5类别,应使用:

h1=hist(c(1,1,2,3,4,5,5,1.5), breaks=0.49:5.49)
或者更整洁:

h1=hist(c(1,1,2,3,4,5,5,1.5), breaks=0.5:5.5, right=FALSE)
我不确定您想在这里自动化什么,但希望上面的内容能够回答您的问题。如果没有,请让我更清楚地回答你的问题


第三季度 关于密度是10而不是1,这是因为密度不是频率。从帮助文件:

密度: 值f^(x[i]),作为估计密度值。如果所有(差异(中断)==1),则它们是相对频率计数/n,并且通常满足和[i;f^(x[i])(b[i+1]-b[i])=1,其中b[i]=中断[i]


因此,如果您的休息时间不等于1,那么密度总和将不会等于1。

在发布类似问题之前,请阅读
?[functionname]
。感谢您的回复,我不是英语母语人士,因此即使从帮助中,我也没有领会
mids
背后的想法。若我理解正确,那个么它是特定竖条的中心吗?关于最后一个问题,我发现它将返回1
sum(h$density*diff(h$breaks))
我也不是母语人士,但我的理解是一样的:它是直方图类的中间,如果类是2.5-3.5,中间将是3。