【问题标题】:cumulative log-normal function does not return a correct probability累积对数正态函数不返回正确的概率
【发布时间】:2018-07-23 19:35:11
【问题描述】:

我有一些正数,我正在使用对数正态分布来绘制并显示 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", "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

【问题讨论】:

  • 您能否更具体地说明什么“看起来不正确?关于曲线下填充区域还有其他问题:stackoverflow.com/questions/33244629/…
  • 在我的计算区域应该给我们 CNT 在 1 到 50 之间的概率,它应该是 0.7 左右,但它给出了 0.025

标签: r ggplot2 probability normal-distribution


【解决方案1】:

log-norm 的参数化要求您传入平均对数值,而不是原始值。试试

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

【讨论】:

    猜你喜欢
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    相关资源
    最近更新 更多