R/rngh.R

rngh <-
function(n,rho=0,p=2,g=0,h=0,ADJ=TRUE){
#
# Generate data from a multivariate distribution where the marginal distributions
#  are g-and-h distributions that have common correlation rho.
# Strategy: adjust the correlation when generating data from multivariate normal  normal distribution so that
# when transforming the marginal distributions to a g-and-h distribution, the correlation is rho.
# 
#
library(MASS)
if(ADJ){
adjrho=rngh.sub(n,g,h,rho)$rho.adjusted #$
rho=adjrho
print(paste('Adjusted rho',rho))
}
cmat<-matrix(rho,p,p)
diag(cmat)<-1
x=mvrnorm(n=n, mu=rep(0,p), Sigma=cmat)
for(i in 1:p){
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)
}
x
}
musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.