shark_fin: A shark fin generator Generating from the shark fin...

View source: R/mono_bart.R

shark_finR Documentation

A shark fin generator Generating from the shark fin distribution

Description

A shark fin generator Generating from the shark fin distribution

Usage

shark_fin(z, q, var)

Arguments

z

vector of quantiles

q

the q-parameter

varexp

the variance you want

Examples

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

demetrios1/Causallysensitive documentation built on Nov. 18, 2022, 5:27 p.m.