Teksim

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

## Pembangkitan Data Multivariat Normal dengan p=3

multinormal=function(n,mu,cov)
{
p=length(mu)
C=matrix(0,p,p)
z=matrix(0,p,n)
for(i in 1:n){ ## Pembangkitan Normal Baku
z[,i]=rnorm(p,0,1)
}
C[1,1]=sqrt(cov[1,1])
C[2,1]=cov[2,1]/sqrt(cov[1,1])
C[2,2]=sqrt(cov[2,2]-C[2,1]^2)
C[3,1]= cov[3,1]/C[1,1]
C[3,2]=(cov[3,2]-C[3,1]*C[2,1])/sqrt(cov[2,2]-C[2,1]^2)
C[3,3]=sqrt(cov[3,3]-(C[3,1]^2+C[3,2]^2))
y=C%*%z+mu
Y=t(y)
return(Y)
}
## Contoh
mu=c(10,15,20)
cov=matrix(c(9,5,4,5,16,8,4,8,25),ncol=3,byrow=TRUE)
multinormal(30,mu,cov)

You might also like