สถาบันวิจัยและพัฒนา มหาวิทยาลัยราชภัฏอุบลราชธานี
2010-Oct-20 05:29 UTC
[R] Generate variable with Bivariate Normal Distribution
Dear All
I want to generate variable with Bivariate Normal Distribution by
use mean1 = a, variance1 = b, mean2 = c, variance2 = d, rho = e.
How I can do this.
Many Thanks.
IRD
[[alternative HTML version deleted]]
You could e.g. use the package "mvtnorm" (not horribly fast, but
handy):
(assuming that rho is the correlation)
library("mvtnorm")
m <- c(mean1, mean2) #mean vector
cov <- rho*sqrt(variance1*variance2)
sig <- matrix(c(variance1, cov, cov, variance2), nrow=2) #covariance matrix
rmvnorm(100, mean=m, sigma=sig)
alternatively, you can transform manually via sigma^(1/2) (faster). This is
covered
in almost any (multivariate) statistics book.
Gregor
On Wed, 20 Oct 2010 12:29:53 +0700
??????????????????? ???????????????????????????? <ird_ubru at hotmail.com>
wrote:
>
> Dear All
>
> I want to generate variable with Bivariate Normal Distribution by
> use mean1 = a, variance1 = b, mean2 = c, variance2 = d, rho = e.
>
> How I can do this.
>
> Many Thanks.
>
> IRD
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.