Displaying 1 result from an estimated 1 matches for "gaussin".
Did you mean:
gaussian
2008 Jun 26
2
constructing arbitrary (positive definite) covariance matrix
...ples
########
COV<-function (p = 3, sd = 1, r= 0.5){
cov <- diag(sd^2, ncol=p, nrow=p)
for (i in 1:p) {
for (j in 1:p) {
if (i != j) {
cov[i, j] <- r * sd*sd
}
}
}
cov
}
> library(MASS)
> ### Simualte multivarite gaussin data (works OK)
> Sigma<-COV(p = 3, sd = 2, r= 0.5)
> mu<-1:3
> mvrnorm(5, mu=mu, Sigma=Sigma)
[,1] [,2] [,3]
[1,] 1.2979984 1.843248 4.460891
[2,] 2.1061054 1.457201 3.774833
[3,] 2.1578538 2.761939 4.589977
[4,] 0.8775056 4.240710 2.203712
[5,] 0.2698180 2.075759...