[R] generate bi-variate normal data
Liaw, Andy
andy_liaw at merck.com
Wed Jul 5 18:50:28 CEST 2006
From: Shin, David
>
> Dear all,
>
> I would like to generate bi-variate normal data given that
> the first column of the data is known. for example:
> I first generate a set of data using the command, x <-
> rmvnorm(10, c(0, 0), matrix(c(1, 0, 0, 1), 2))
>
> then I would like to sum up the two columns of x:
> x.sum <- apply(x, 1, sum)
>
> now with x.sum I would like to generate another column of
> data, say y, that makes cbind(x.sum, y) follow a bi-variate
> normal distribution with mean = c(0, 0) and sigma =
> matrix(c(1, 0, 0, 1),2)
x.sum as you described would be distributed as normal with mean=0 and
variance=2 (so you might as well just use x.sum <- rnorm(10, 0, sqrt(2))),
so I don't see how you can get to the second step where you want x.sum to
have variance=1. Also, since the covariances are 0, you could just generate
the columns separately using rnorm() and cbind() them together.
It might be helpful for you to get some basic understanding of math stat. I
only say that because most likely there are other steps to whatever task you
are doing (people are unlikely to be generating random numbers just for
kicks), and there's no telling what other things you are doing
inefficiently, or even erroneously.
Andy
> I will appreciate for all insights.
>
> David s.
>
> **************************************************************
> **************
> This email may contain confidential material.\ If you were...{{dropped}}
More information about the R-help
mailing list