I am trying to plot the conditional distributions from the bivariate normal using the joint and marginal distributions.
The conditional distribution of X given Y is X|Y=y~N(rho * y,1-rho^2) and Y given X is Y|X=x~N(rho*x,1-rho^2)
Here is my approach to implement this in R using simulation (taking the particular value of rho=1/2 in both the joint and marginal dist. for more info see here :
plot.new()
num<-exp(-2*((x^2)-(x*y)+(y^2))/3)
den<-(exp((-x^2)/2)*sqrt(3))/sqrt(2*pi)
quot<-num/den
fun <- function(x, y){quot}
xs <- seq(-10, 10, by=1)
ys <- seq(-10, 10, by=1)
res <- mapply(fun, list(xs), list(ys))
cols <- c("black", "cornflowerblue", "orange")
matplot(xs, res, col=cols, type="l", lty=1, lwd=2, xlab="x", ylab="result")
legend("bottomright", legend=ys, title="value of y", lwd=2, col=cols)
When I run the code I get the message error
Error in matplot(xs, res, col = cols, type = "l", lty = 1, lwd = 2, xlab = "x", :
'x' and 'y' must have same number of rows
why does it says that x and y must have same number of rows? In which part of the code can I fix this?
I don't get it, please help me.