On Mar 28, 2010, at 3:19 AM, Severin Kacianka wrote:

Hello,

I try to create a persp-plot for the bivariate normal distribution. There are a few solutions online ([1],[2]), but I did not want to hard-code the formula like [2] did or use a kernel density estimate like [1].

My plan was to use dmvnorm, and use outer to calculate the z- dimension for each point. Here is what I tried:
library(mvtnorm)
x<-seq(0,1,len=40)
y<-x
g<-function(a,b) {
        dmvnorm(x=c(a,b))

The construction "c(a,b)" would in the later function call turn those two 40 element vectors into an 80 element vector. See if you get better success with cbind.

}
z<-outer(x,y,g)

Which results in the following error:
Error in dim(robj) <- c(dX, dY) :
 dims [product 1600] do not match the length of object [1]

What causes this error? If I set g to be a simple function like:
g<-function(a,b){
        a*b
}
Everything works fine. Why does it fail when I pass the parameters to dmvnorm?

Thank you for your time,
Severin

[1]https://stat.ethz.ch/pipermail/r-help/2003-September/038314.html
[2]http://www.stat.ucl.ac.be/ISpersonnel/lecoutre/stats/fichiers/_gallery.pdf



David Winsemius, MD
West Hartford, CT

______________________________________________
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.

Reply via email to