using SpecialFunctions, Gadfly
"standard Normal density (generalized) function"
function Normal_dens(x)
return exp(-x^2/2)/sqrt(2Ï€)
end
;
"standard Normal distribution function"
function Normal_dist(x)
return erfc(x/-sqrt(2))/2
end
;
plot([Normal_dens,Normal_dist],-2,2)
"standard Normal quantile function"
function Normal_quan(p)
return -sqrt(2)erfcinv(2p)
end
;
plot(Normal_quan,.1,.9)
"standard NRIG density (generalized) function"
function NRIG_dens(x,g)
return exp(g)sqrt(1+g)besselk(0,sqrt(g^2+(1+g)*x^2))/Ï€
end
;
"standard NRIG distribution function"
function NRIG_dist(x,g)
return 1/2+quadgk(z->NRIG_dens(z,g),0,x)[1]
end
;
plot([x->NRIG_dens(x,1),x->NRIG_dist(x,1)],-2,2)
"standard NRIG quantile function"
function NRIG_quan(p,g)
# Newton-Raphson method to invert NRIG_dist
x0=Normal_quan(p) # initial guess
x1=NaN
for n=1:20
f=NRIG_dens(x0,g)
x1=(p-1/2+quadgk(x->f-NRIG_dens(x,g),0,x0)[1])/f
if abs(x1-x0)<1e-12
break
end
x0=x1
end
return x1
end
;
plot(p->NRIG_quan(p,1),.1,.9)
"conventional Student's-t4 density (generalized) function"
function t4_dens(x)
return 3/8*(1+x^2/4)^(-5/2)
end
;
"conventional Student's-t4 distribution function"
function t4_dist(x)
return (1+(x*(6+x^2))/((4+x^2)^(3/2)))/2
end
;
plot([t4_dens,t4_dist],-2,2)
"conventional Student's-t4 quantile function"
function t4_quan(p)
a=1/(4p*(1-p))
return 2sign(p-1/2)sqrt(sqrt(a)cos(atan(sqrt(a-1))/3)-1)
end
;
plot(t4_quan,.1,.9)