两片正态(或分裂正态)分布的密度

时间:2013-04-17 15:50:49

标签: r statistics distribution cran

两件式正态分布是否有密度函数:

enter image description here

CRAN上的

?以为我会在编码之前检查一下。我检查了分发任务视图。它没有列在那里。我看了几个可能的套餐,但无济于事。

更新:我已将dsplitnormpsplitnormqsplitnormrsplitnorm个功能添加到fanplot包中。

1 个答案:

答案 0 :(得分:4)

如果您选择构建自己的发行版本,则可能对 distr 感兴趣。它(以及相关的包 distrEx distrSim distrTEst distrTeach distrDoc )已经编写,以提供一个统一的界面来构建现有的新发行版。 (我在 distrDoc 包附带的精彩插图的帮助下构建了这个示例,可以通过键入vignette("distr")来获取。)

这实现了split normal distribution,这可能不是你想要的。但是,使用 distr 工具集,调整它以满足您的确切需求应该不会太难。

library(distr)

## Construct the distribution object.
## Here, it's a split normal distribution with mode=0, and lower- and
## upper-half standard deviations of 1 and 2, respectively.
splitNorm <- UnivarMixingDistribution(Truncate(Norm(0,2), upper=0), 
                                      Truncate(Norm(0,1), lower=0), 
                                      mixCoeff=c(0.5, 0.5))
## Construct its density function ...
dsplitNorm <- d(splitNorm)
## ... and a function for sampling random variates from it
rsplitNorm <- r(splitNorm)

## Compare the density it returns to that from rnorm()
dsplitNorm(-1)
# [1] 0.1760327    
dnorm(-1, sd=2)
# [1] 0.1760327    

## Sample and plot a million random variates from the distribution
x <- rsplitNorm(1e6)         
hist(x, breaks=100, col="grey")

## Plot the distribution's continuous density
plot(splitNorm, to.draw.arg="d") 

enter image description here

enter image description here