R 累积对数正态函数不返回正确的概率
我有一些正数,我使用对数正态分布来绘制和显示CNT在1到50之间的概率。我想给曲线下面的区域上色并计算概率。我已经成功绘制了图表,我正在尝试计算概率,但是返回的结果看起来不正确,我在哪里出错?如何绘制lb和ub之间曲线下方的区域R 累积对数正态函数不返回正确的概率,r,ggplot2,probability,normal-distribution,R,Ggplot2,Probability,Normal Distribution,我有一些正数,我使用对数正态分布来绘制和显示CNT在1到50之间的概率。我想给曲线下面的区域上色并计算概率。我已经成功绘制了图表,我正在尝试计算概率,但是返回的结果看起来不正确,我在哪里出错?如何绘制lb和ub之间曲线下方的区域 df <-structure(list(Year_Month = structure(1:35, .Label = c("2015-05", "2015-10", "2015-11", "2015-12", "2016-01", "2016-02
df <-structure(list(Year_Month = structure(1:35, .Label = c("2015-05",
"2015-10", "2015-11", "2015-12", "2016-01", "2016-02", "2016-03",
"2016-04", "2016-05", "2016-06", "2016-07", "2016-08", "2016-09",
"2016-10", "2016-11", "2016-12", "2017-01", "2017-02", "2017-03",
"2017-04", "2017-05", "2017-06", "2017-07", "2017-08", "2017-09",
"2017-10", "2017-11", "2017-12", "2018-01", "2018-02", "2018-03",
"2018-04", "2018-05", "2018-06", "2018-07"), class = "factor"),
CNT = c(1, 1, 1, 5, 6, 5, 21, 10, 11, 16,
14, 19, 11, 9, 15, 6, 7, 33, 24, 47, 76, 92,
72, 92, 63, 60, 69, 66, 65, 89, 91, 76, 84, 71,
40)), .Names = c("Year_Month", "CNT"), row.names = c(NA,
35), class = "data.frame")
std=sd(df$CNT)
m=mean(df$CNT)
lb=1
ub=50
ggplot(df, aes(x=CNT)) + stat_function(fun=dlnorm, args=list(mean=m, sd=std))
i <- CNT >= lb & CNT <= ub
area <- plnorm(ub, m, std) - plnorm(lb, m, std)
area
df对数范数的参数化要求您传入平均对数值,而不是原始值。试一试
std <- sd(log(df$CNT))
m <- mean(log(df$CNT))
lb <- 1
ub <- 50
ggplot(df, aes(x=CNT)) +
stat_function(fun=dlnorm, args=list(mean=m, sd=std)) +
stat_function(fun=dlnorm, args=list(mean=m, sd=std), xlim=c(lb, ub), geom="area")
plnorm(ub, m, std) - plnorm(lb, m, std)
# [1] 0.7230461
std你能更具体地说明什么“看起来不对吗?关于曲线下的填充区域还有其他问题:在我的计算区域中,CNT的概率应该在1到50之间,应该是0.7左右,但它给出了0.025