Hello, I am trying to compute rectangle probability of bivariate
normal distribution with the following function:
bvnrectangle - function(mu, Sig, xmin, xmax, ymin, ymax){
library(adapt)
Siginv - solve(Sig)
detSig - det(Sig)
areal - adapt(ndim=2, lower=c(xmin,ymin), upper=c(xmax,ymax),
minpts=100, maxpts=1000, functn=bvnpdf, mu, Siginv, detSig)$value
areal
}
bvnpdf - function(xy, mu, Siginv, detSig){
f-numeric()
for(xloop in 1:length(xy[1])){
x - xy[[1]][xloop]
if(xy[[1]]xy[[2]] (1==2)) {
f[xloop] - 0} else {
v - rbind(xy[1], xy[2])
e - t(v-mu) %*% Siginv %*% (v-mu)
f[xloop] - exp(-e/2)/(2*pi)/sqrt(detSig)
}
}
f
}
bvnpdf works correctly (tested),
ex.: bvnpdf(c(0,0), c(0,0), solve( matrix(c(1, 0.5, 0.5, 1), nrow=2,
byrow=FALSE)), det( matrix(c(1, 0.5, 0.5, 1), nrow=2, byrow=FALSE)))
but when I run bvnrectangle, ex.: bvnrectangle(c(0,0), matrix(c(1,
0.5, 0.5, 1), nrow=2, byrow=FALSE), 0, 8, 0, 8)
I get the following error message:
Error in v - mu : non-conformable arrays
Why do I get this error message. I just can't understand what I am
doing wrong... Please, help.
Thanks in advance,
Regards,
Sergey
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.