如何生成R中给定的均值,SD,偏斜和峰度的分布? [英] How to generate distributions given, mean, SD, skew and kurtosis in R?
问题描述
是否可以在R中生成均值,SD,偏斜和峰度已知的分布?到目前为止,最好的方法似乎是创建随机数并相应地对其进行转换. 如果有适合生成特定发行版的软件包,而我可能还没有找到它. 谢谢
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发行版.约翰逊将为您提供与力矩或分位数相匹配的分布.其他评论是正确的,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.
祝你好运!
编辑
正如哈德利(Hadley)在评论中指出的那样,约翰逊(Johnson)看上去很合适.我进行了快速测试,并使用moment="quant"
拟合了Johnson分布,该分布使用5个分位数而不是4个矩拟合了Johnson分布.结果看起来好多了:
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屋!