Density of a Two-Piece Normal (or Split Normal) Distribution

流过昼夜 提交于 2019-12-12 12:14:06

问题


Is there a density function for the two-piece Normal distribution:

on CRAN? Thought I would check before I code one. I have checked the distribution task view. It is not listed there. I have looked in a couple of likely packages, but to no avail.

Update: I have added dsplitnorm, psplitnorm, qsplitnorm and rsplitnorm functions to the fanplot package.


回答1:


If you choose to construct your own version of the distribution, you might be interested in distr. It (and the related packages distrEx, distrSim, distrTEst, distrTeach and distrDoc) have been written to provide a unified interface for constructing new distributions from existing ones. (I constructed this example with the help of the wonderful vignette that accompanies the distrDoc package and which can be gotten by typing vignette("distr").)

This implements the split normal distribution, which may not be exactly what you are after. Using the distr toolset, though, it shouldn't be too hard to adjust this to fit your exact needs.

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") 



来源:https://stackoverflow.com/questions/16064639/density-of-a-two-piece-normal-or-split-normal-distribution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!