I have a problem in understanding this question, especially this part:
"generate a random sample of length n from a normal multivariate"
This is what I have done using the R package mvtnorm:
my_function <- function(n=1,k){
mean = rep(0,k)
sigma = diag(length(mean))
rmvnorm(n, mean, sigma,method=c("eigen", "svd", "chol"), pre0.9_9994 = FALSE)}
my_function(3)
This way the output of my function is, in this example, a vector of three numbers which in my mind is A sample of length 3. Is this correct? Is there another way to do this?
I am asking this question because I have to do the same without using the library rmvnorm and with a normal bivariate.
I just managed to write the density function:
dbivnorm <- function(x,y,mux=0,muy=0,sigmax=1,sigmay=1,rho=0){
(2*pi)^(-1) * ((1-rho^2)*sigmax^2*sigmay^2)^(-.5) *
exp( -((x-mux)^2/(sigmax^2) -2*rho*((x-mux)/sigmax *(y-muy)/sigmay) +
(y-muy)^2/(sigmay^2))/(2*(1-rho^2)) )
}
But now I am not sure how to proceed.
rmvnorm
a few times with different argument values. Since (for some reason) you don't want to usermvnorm
, could you please be specific about what tools or techniques you are willing to employ? If the reason for not using the solution available to you is educational, then please tag your post with self-study. $\endgroup$