【问题标题】:How to extract values fitted to a gaussian distribution in R?如何提取适合R中高斯分布的值?
【发布时间】:2015-07-11 16:38:16
【问题描述】:

我有一个数据框 X,它有 2 列 a 和 b,a 是字符类,b 是数字类。 我使用 b 上的 fitdist(fitdistrplus 包)函数拟合了一个高斯分布。

data.fit <- fitdist(x$b,"norm", "mle")

我想提取 a 列中落在拟合高斯分布 5% 右尾的元素。
我不确定如何进行,因为我对拟合分布的了解有限。
我是否需要保留 a 列中 b 大于 95% 的值的相应元素?
或者拟合是否意味着已经为 b 中的每个值创建了新值并且我应该使用这些值?

谢谢

【问题讨论】:

    标签: r model-fitting


    【解决方案1】:

    通过调用unclass(data.fit),您可以查看构成data.fit 对象的所有部分,其中包括:

    $estimate
         mean        sd 
    0.1125554 1.2724377 
    

    这意味着您可以通过以下方式访问估计的均值和标准差:

    data.fit$estimate['sd']
    data.fit$estimate['mean']
    

    要计算拟合分布的上 5 个百分位数,您可以使用 qnorm() 函数(q 代表分位数,顺便说一句),如下所示:

    threshold <- 
        qnorm(p = 0.95,
              mean=data.fit$estimate['mean'],
              sd=data.fit$estimate['sd'])
    

    你可以像这样子集你的data.frame x

    x[x$b > threshold,# an indicator of the rows to return
      'a']# the column to return
    

    【讨论】:

      猜你喜欢
      • 2022-01-25
      • 2015-02-15
      • 2019-03-06
      • 2016-09-16
      • 2016-01-15
      • 1970-01-01
      • 2020-02-26
      • 2017-11-24
      • 2019-07-15
      相关资源
      最近更新 更多