shark_fin | R Documentation |
A shark fin generator Generating from the shark fin distribution
shark_fin(z, q, var)
z |
vector of quantiles |
q |
the q-parameter |
varexp |
the variance you want |
n=1000 xgrid = seq(-4, 4, length.out=n) q=.5 var=1 plot(xgrid,shark_fin(xgrid, q, var), type='l', lwd=2,col='firebrick4', main='Sharkfin plot', xlab='u', ylab='f(u)') #draw from a sharkfin ind = rbinom(n,1,q) u = rep(NA,n) a=(1-(dnorm(0)/(1-pnorm(0)))^2) b=((dnorm(0)/(1-pnorm(0)))) sig=sqrt(var/((1-q)*a*((1-q)/q)^2 + q*a + (b*(1 + (1-q)/q))^2*q*(1-q))) u[ind==1] = truncnorm::rtruncnorm(sum(ind==1),a = -Inf, b = 0, sd = sig) u[ind==0] = truncnorm::rtruncnorm(sum(ind==0),a = 0, b = +Inf,sd = sig*(1-q)/q) #prob 1-q over 0, 1/s and s cancel plot(density(u), lwd=2) lines(xgrid, shark_fin(xgrid, q, var), type='l', lwd=2, col='firebrick4')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.