R/rngh.sub.R

rngh.sub <-
function(n,g,h,rho){
#
# Determine adjusted value for rho so that
# the actual correlation is some desired value
#
#  rho: desired correlation
vals=seq(rho,.99,.01)
for(i in 1:length(vals)){
adj=vals[i]
cmat<-matrix(vals[i],2,2)
diag(cmat)<-1
x=mvrnorm(1000000,mu=c(0,0),Sigma=cmat)
for(i in 1:2){
if (g>0){
x[,i]<-(exp(g*x[,i])-1)*exp(h*x[,i]^2/2)/g
}
if(g==0)x[,i]<-x[,i]*exp(h*x[,i]^2/2)
}
chk=cor(x)
if(abs(chk[1,2]-rho)<.01)break
if(chk[1,2]>=rho)break
}
list(rho.adjusted=adj,rho.actual=chk[1,2])
}
musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.