1 | rngh.sub(n, g, h, rho)
|
n |
|
g |
|
h |
|
rho |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (n, g, h, rho)
{
vals = seq(rho, 0.99, 0.01)
for (i in 1:length(vals)) {
adj = vals[i]
cmat <- matrix(vals[i], 2, 2)
diag(cmat) <- 1
x = mvrnorm(1e+06, 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) < 0.01)
break
if (chk[1, 2] >= rho)
break
}
list(rho.adjusted = adj, rho.actual = chk[1, 2])
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.