gpt4 book ai didi

r - 在直方图上绘制高斯曲线时遇到问题吗? (使用前面的示例,没有运气)

转载 作者:行者123 更新时间:2023-12-02 04:36:34 28 4
gpt4 key购买 nike

首先,下面是代码:

hist(sumCol)
curve(dnorm(sumCol, mean=Mean, sd=SD),
col="darkblue", lwd=2, add=TRUE, yaxt="n")

我使用发现 here的代码,但没有运气。任何帮助将非常感激。平均值是49.9,SD是6.66。
> dput(sumCol)
c(47.4105366033036, 58.3324683033861, 58.1094471025281, 49.9950564198662,
46.136499152286, 57.6314454714302, 55.9323056084104, 42.4964612387121,
56.1618362078443, 42.376149847405, 56.1894942307845, 50.9596610828303,
44.9340054308996, 56.2675485799555, 44.5740411255974, 55.4805521473754,
50.7398278019391, 48.7541372219566, 36.393867429113, 46.3503022803925,
55.629230362596, 41.7389209344983, 37.9173863746691, 49.6265010556672,
52.5780587899499, 48.2867740916554, 47.6546685318463, 55.3406274791341,
42.1973585763481, 44.8090796419419, 45.2378696959931, 49.4975818633102,
49.5211400222033, 66.1860005331691, 64.2629869871307, 52.9526992985047,
43.8075632608961, 52.2976646479219, 49.4498609972652, 43.0183454982471
)

最佳答案

容易获得的是高度为概率密度时的曲线直方图。

hist(sumCol, prob=TRUE)
sumCol_norm = function(x) { dnorm(x, mean=mean(sumCol), sd=sd(sumCol)) }
curve(sumCol_norm, col="darkblue", lwd=2, add=TRUE, yaxt="n")

这将精确地提供所需的形状,但是y轴标签是密度,而不是计数。为了像原始直方图中那样使用计数来执行此操作,我们需要通过所有分箱的总计数来缩放密度。我们可以通过保存直方图的输出并进行较小的计算来获得该结果。
H = hist(sumCol)
area = sum(diff(H$breaks)*H$counts)
sumCol_norm = function(x) { area*dnorm(x, mean=mean(sumCol), sd=sd(sumCol)) }
curve(sumCol_norm, col="darkblue", lwd=2, add=TRUE, yaxt="n")

Histogram with overlaid normal

关于r - 在直方图上绘制高斯曲线时遇到问题吗? (使用前面的示例,没有运气),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42015367/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com