0

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

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

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

谢谢

4

1 回答 1

2

通过调用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'])

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

x[x$b > threshold,# an indicator of the rows to return
  'a']# the column to return
于 2015-05-01T19:41:53.910 回答