双分布正态(或拆分正态)分布的密度

4

是否在CRAN上有关于两段正态分布的密度函数:

enter image description here

我想在编写代码之前先检查一下。我已经查看了分布任务视图,但没有找到该函数。我已经查看了几个可能的程序包,但均未找到。

更新:我已将 dsplitnormpsplitnormqsplitnormrsplitnorm 函数添加到 fanplot 程序包中。

1个回答

5
如果您选择构建自己的发行版,您可能会对distr感兴趣。它(以及相关的软件包distrExdistrSimdistrTEstdistrTeachdistrDoc)旨在提供一个统一的接口,用于从现有分布构建新的分布。(我使用了伴随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


谢谢。我想这就是我正在寻找的(或者至少是我正在寻找的参数化)。 - guyabel
@gjabel -- 更简单的方法是,如果我只需要密度,可以像这样做:ifelse(x < 0, dnorm(x, mean=0, sd=2), dnorm(x, mean=0, sd=1))(对于一个具有 mode=0、下半部分 sd=2 和上半部分 sd=1 的分布)。 - Josh O'Brien

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接