I'm new to Julia and I'm trying to convert a function I've written in R to Julia and I'm having some troubles.
So my function in R is
jgaus<-function(s,thetaW){
z<-qnorm(1-exp(-s))
if(any(z==Inf)){
z<- -qnorm(exp(-s))
}
inside<--(1/(2*(1-thetaW^2)))*(z[1]^2-2*thetaW*z[1]*z[2]+z[2]^2)
expinside<-exp(inside)
dens<-(1/(2*pi*sqrt(1-thetaW^2)))*expinside*prod(exp(-s)/dnorm(z))
return(dens)
}
jgaus(rbind(c(0.4,0.3),c(0.5,0.6)),0.4)
# z matrix
[,1] [,2]
[1,] -0.4407971 -0.6458700
[2,] -0.2702880 -0.1226595
# dens values: the first is for the vector (-0.44,-0.65) and the second for (-0.27,-0.12)
[1] 0.902662
[1] 1.451246
but when I tried to write in Julia
function jgaus(s,thetaW)
z = quantile(Normal(0,1), 1-exp(-s))
if any(z==Inf)
z = -quantile(Normal(0,1), exp(-s))
end
inside = -(1/(2*(1-thetaW^2)))*(z[1]^2-2*thetaW*z[1]*z[2]+z[2]^2)
expinside = exp(inside)
(1/(2*pi*sqrt(1-thetaW^2)))*expinside*prod(exp(-s)/pdf(Normal(0,1), z))
end
jgaus.([0.4 0.3; 0.5 0.6],0.4)
I get an error. I think it's in the call for z[1] and z[2] but I'm not sure. Can anyone help me?
Many thanks