Description Usage Arguments Author(s) Examples
simTargetCov
transforms or simulates data with a target empirical covariance matrix supplied by the user.
1 | simTargetCov(n, p, target, X = NULL)
|
n |
Number of observations for data matrix output. |
p |
Number of variables for data matrix output. |
target |
Target empirical covariance for data matrix output. |
X |
Data matrix for transformation. |
Anthony-Alexander Christidis, anthony.christidis@stat.ubc.ca
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # Function to create target covariance matrix with kernel set to r
target_cor <- function(r, p){
Gamma <- diag(p)
for(i in 1:(p-1)){
for(j in (i+1):p){
Gamma[i,j] <- Gamma[j,i] <- r^(abs(i-j))
}
}
return(Gamma)
}
# Transformation of data to target empirical covariance
dat.target.cov <- simTargetCov(X = MASS::mvrnorm(30, mu = rep(0,6),
Sigma = target_cor(0.5,6)),
target = target_cor(0.5,6))
round(cov(dat.target.cov), 2)
# Simulation of data with target empirical covariance
sim.target.cov <- simTargetCov(n = 30, p = 6, target = target_cor(0.5,6))
round(cov(sim.target.cov), 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.