如何在 R 中生成给定分布、均值、SD、偏斜和峰度? [英] How to generate distributions given, mean, SD, skew and kurtosis in R?

查看:20
本文介绍了如何在 R 中生成给定分布、均值、SD、偏斜和峰度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 R 中生成均值、标准差、偏度和峰度已知的分布?到目前为止,似乎最好的方法是创建随机数并相应地转换它们.如果有一个专门用于生成可以调整的特定发行版的软件包,我还没有找到.谢谢

Is it possible to generate distributions in R for which the Mean, SD, skew and kurtosis are known? So far it appears the best route would be to create random numbers and transform them accordingly. If there is a package tailored to generating specific distributions which could be adapted, I have not yet found it. Thanks

推荐答案

SuppDists 包中有一个 Johnson 发行版.Johnson 将为您提供匹配矩或分位数的分布.其他人的评论是正确的,即 4 个时刻不是分配使.但约翰逊肯定会尝试.

There is a Johnson distribution in the SuppDists package. Johnson will give you a distribution that matches either moments or quantiles. Others comments are correct that 4 moments does not a distribution make. But Johnson will certainly try.

以下是将 Johnson 拟合到一些样本数据的示例:

Here's an example of fitting a Johnson to some sample data:

require(SuppDists)

## make a weird dist with Kurtosis and Skew
a <- rnorm( 5000, 0, 2 )
b <- rnorm( 1000, -2, 4 )
c <- rnorm( 3000,  4, 4 )
babyGotKurtosis <- c( a, b, c )
hist( babyGotKurtosis , freq=FALSE)

## Fit a Johnson distribution to the data
## TODO: Insert Johnson joke here
parms<-JohnsonFit(babyGotKurtosis, moment="find")

## Print out the parameters 
sJohnson(parms)

## add the Johnson function to the histogram
plot(function(x)dJohnson(x,parms), -20, 20, add=TRUE, col="red")

最终的情节是这样的:

您可以看到其他人指出的一些问题,即 4 个时刻如何不能完全捕获分布.

You can see a bit of the issue that others point out about how 4 moments do not fully capture a distribution.

祝你好运!

编辑正如哈德利在评论中指出的那样,约翰逊的合身看起来很糟糕.我做了一个快速测试并使用 moment="quant" 拟合约翰逊分布,它使用 5 个分位数而不是 4 个矩来拟合约翰逊分布.结果看起来好多了:

EDIT As Hadley pointed out in the comments, the Johnson fit looks off. I did a quick test and fit the Johnson distribution using moment="quant" which fits the Johnson distribution using 5 quantiles instead of the 4 moments. The results look much better:

parms<-JohnsonFit(babyGotKurtosis, moment="quant")
plot(function(x)dJohnson(x,parms), -20, 20, add=TRUE, col="red")

产生以下结果:

有人知道为什么约翰逊在使用时刻适合时似乎有偏见吗?

Anyone have any ideas why Johnson seems biased when fit using moments?

这篇关于如何在 R 中生成给定分布、均值、SD、偏斜和峰度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆