SimulateCVR: Generate simulation data.

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Generate two sets of covariates and an univariate response driven by several latent factors.

Usage

1
2
3
SimulateCVR(family = c("gaussian", "binomial", "poisson"), n = 100,  
         rank = 4, p1 = 50, p2 = 70, pnz = 10, sigmax = 0.2,   
         sigmay = 0.5, beta = c(2, 1, 0, 0), standardization = TRUE)

Arguments

family

Type of response. "gaussian" for continuous response, "binomial" for binary response, and "poisson" for Poisson response. The default is "gaussian".

n

Number of rows. The default is 100.

rank

Number of latent factors generating the covariates. The default is 4.

p1

Number of variables in X1. The default is 50.

p2

Number of variables in X2. The default is 70.

pnz

Number of variables in X1 and X2 related to the signal. The default is 10.

sigmax

Standard deviation of normal noise in X1 and X2. The default is 0.2.

sigmay

Standard deviation of normal noise in Y. Only used when the response is Gaussian. The default is 0.5.

beta

Numeric vector, the coefficients used to generate respose from the latent factors. The default is c(2, 1, 0, 0).

standardization

Logical. If TRUE, standardize X1 and X2 before output. The default is TRUE.

Details

The latent factors in U are randomly generated normal vectors,

X1 = U*V1 + sigmax*E1, X2 = U*V2 + sigmax*E2, E1, E2 are N(0,1) noise matrices.

The nonzero entries of V1 and V2 are generated from Uniform([-1,-0.5]U[0.5,1]).

For Gaussian response,

y = U*β + sigmay*ey, ey is N(0,1) noise vector,

for binary response,

y \sim rbinom(n, 1, 1/(1 + \exp(-U*β))),

and for Poisson response,

y \sim rpois(n, \exp(U*β)).

See the reference for more details.

Value

X1, X2

The two sets of covariates with dimensions n*p1 and n*p2 respectively.

y

The response vector with length n.

U

The true latent factor matrix with dimension n*rank.

beta

The coefficients used to generate response from U. The length is rank.

V1, V2

The true loading matrices for X1 and X2 with dimensions p1*rank and p2*rank. The first pnz rows are nonzero.

Author(s)

Chongliang Luo, Kun Chen.

References

Chongliang Luo, Jin Liu, Dipak D. Dey and Kun Chen (2016) Canonical variate regression. Biostatistics, doi: 10.1093/biostatistics/kxw001.

See Also

CVR, cvrsolver.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
 set.seed(42)
 mydata <- SimulateCVR(family = "g", n = 100, rank = 4, p1 = 50, p2 = 70, 
                   pnz = 10, beta = c(2, 1, 0, 0))
 X1 <- mydata$X1
 X2 <- mydata$X2
 Xlist <- list(X1 = X1, X2 = X2); 
 Y <- mydata$y
 opts <- list(standardization = FALSE, maxIters = 300, tol = 0.005)
 ## use sparse CCA solution as initial values, see SparseCCA()
 Wini <- SparseCCA(X1, X2, 4, 0.7, 0.7) 
 ## perform CVR with fixed eta and lambda, see cvrsolver()
 fit <- cvrsolver(Y, Xlist, rank = 4, eta = 0.5, Lam = c(1, 1), 
                 family = "gaussian", Wini, penalty = "GL1", opts)
 ## check sparsity recovery
 fit$W[[1]]; 
 fit$W[[2]];
 ## check orthogonality
 X1W1 <- X1 %*% fit$W[[1]]; 
 t(X1W1) %*% X1W1

Example output

Loading required package: PMA
Loading required package: plyr
Loading required package: impute
              [,1]         [,2]         [,3]         [,4]
 [1,] -0.012261873  0.004887863  0.001891378 -0.001131116
 [2,]  0.021741597 -0.008053111  0.013607888  0.048431585
 [3,] -0.023697795  0.035884726 -0.040794735  0.038214989
 [4,] -0.012745818 -0.019816143  0.011464357  0.005906790
 [5,] -0.010457530  0.039261017  0.014783877 -0.021886999
 [6,] -0.029410177 -0.008615172  0.035705562 -0.012323978
 [7,] -0.021403281 -0.018304434  0.005118862  0.025530928
 [8,]  0.025653388 -0.003808161  0.005551649 -0.007043912
 [9,] -0.005418697  0.021831804  0.030404987  0.021518821
[10,] -0.019343988 -0.015667729 -0.033564347 -0.003813159
[11,]  0.000000000  0.000000000  0.000000000  0.000000000
[12,]  0.000000000  0.000000000  0.000000000  0.000000000
[13,]  0.000000000  0.000000000  0.000000000  0.000000000
[14,]  0.000000000  0.000000000  0.000000000  0.000000000
[15,]  0.000000000  0.000000000  0.000000000  0.000000000
[16,]  0.000000000  0.000000000  0.000000000  0.000000000
[17,]  0.000000000  0.000000000  0.000000000  0.000000000
[18,]  0.000000000  0.000000000  0.000000000  0.000000000
[19,]  0.000000000  0.000000000  0.000000000  0.000000000
[20,]  0.000000000  0.000000000  0.000000000  0.000000000
[21,]  0.000000000  0.000000000  0.000000000  0.000000000
[22,]  0.000000000  0.000000000  0.000000000  0.000000000
[23,]  0.000000000  0.000000000  0.000000000  0.000000000
[24,]  0.000000000  0.000000000  0.000000000  0.000000000
[25,]  0.000000000  0.000000000  0.000000000  0.000000000
[26,]  0.000000000  0.000000000  0.000000000  0.000000000
[27,]  0.000000000  0.000000000  0.000000000  0.000000000
[28,]  0.000000000  0.000000000  0.000000000  0.000000000
[29,]  0.000000000  0.000000000  0.000000000  0.000000000
[30,]  0.000000000  0.000000000  0.000000000  0.000000000
[31,]  0.000000000  0.000000000  0.000000000  0.000000000
[32,]  0.000000000  0.000000000  0.000000000  0.000000000
[33,]  0.000000000  0.000000000  0.000000000  0.000000000
[34,]  0.000000000  0.000000000  0.000000000  0.000000000
[35,]  0.000000000  0.000000000  0.000000000  0.000000000
[36,]  0.000000000  0.000000000  0.000000000  0.000000000
[37,]  0.000000000  0.000000000  0.000000000  0.000000000
[38,]  0.000000000  0.000000000  0.000000000  0.000000000
[39,]  0.000000000  0.000000000  0.000000000  0.000000000
[40,]  0.000000000  0.000000000  0.000000000  0.000000000
[41,]  0.000000000  0.000000000  0.000000000  0.000000000
[42,]  0.000000000  0.000000000  0.000000000  0.000000000
[43,]  0.000000000  0.000000000  0.000000000  0.000000000
[44,]  0.000000000  0.000000000  0.000000000  0.000000000
[45,]  0.000000000  0.000000000  0.000000000  0.000000000
[46,]  0.000000000  0.000000000  0.000000000  0.000000000
[47,]  0.000000000  0.000000000  0.000000000  0.000000000
[48,]  0.000000000  0.000000000  0.000000000  0.000000000
[49,]  0.000000000  0.000000000  0.000000000  0.000000000
[50,]  0.000000000  0.000000000  0.000000000  0.000000000
              [,1]         [,2]         [,3]          [,4]
 [1,] -0.006453426  0.022856458 -0.028357996  0.0188470164
 [2,]  0.032263506 -0.018173378  0.003859985  0.0711976285
 [3,] -0.047191309  0.021500836  0.030841538  0.0405123637
 [4,]  0.025615261  0.020591873  0.011706378 -0.0107687299
 [5,]  0.003760129 -0.002716499 -0.003008353  0.0004232668
 [6,] -0.005897278  0.031320022  0.015246928 -0.0175948257
 [7,]  0.030384252  0.022827877 -0.011511467 -0.0036913397
 [8,]  0.000000000  0.000000000  0.000000000  0.0000000000
 [9,] -0.005087890 -0.030962364 -0.002772552 -0.0120926511
[10,]  0.017449124 -0.009808173  0.058766066 -0.0067824773
[11,]  0.000000000  0.000000000  0.000000000  0.0000000000
[12,]  0.000000000  0.000000000  0.000000000  0.0000000000
[13,]  0.000000000  0.000000000  0.000000000  0.0000000000
[14,]  0.000000000  0.000000000  0.000000000  0.0000000000
[15,]  0.000000000  0.000000000  0.000000000  0.0000000000
[16,]  0.000000000  0.000000000  0.000000000  0.0000000000
[17,]  0.000000000  0.000000000  0.000000000  0.0000000000
[18,]  0.000000000  0.000000000  0.000000000  0.0000000000
[19,]  0.000000000  0.000000000  0.000000000  0.0000000000
[20,]  0.000000000  0.000000000  0.000000000  0.0000000000
[21,]  0.000000000  0.000000000  0.000000000  0.0000000000
[22,]  0.000000000  0.000000000  0.000000000  0.0000000000
[23,]  0.000000000  0.000000000  0.000000000  0.0000000000
[24,]  0.000000000  0.000000000  0.000000000  0.0000000000
[25,]  0.000000000  0.000000000  0.000000000  0.0000000000
[26,]  0.000000000  0.000000000  0.000000000  0.0000000000
[27,]  0.000000000  0.000000000  0.000000000  0.0000000000
[28,]  0.000000000  0.000000000  0.000000000  0.0000000000
[29,]  0.000000000  0.000000000  0.000000000  0.0000000000
[30,]  0.000000000  0.000000000  0.000000000  0.0000000000
[31,]  0.000000000  0.000000000  0.000000000  0.0000000000
[32,]  0.000000000  0.000000000  0.000000000  0.0000000000
[33,]  0.000000000  0.000000000  0.000000000  0.0000000000
[34,]  0.000000000  0.000000000  0.000000000  0.0000000000
[35,]  0.000000000  0.000000000  0.000000000  0.0000000000
[36,]  0.000000000  0.000000000  0.000000000  0.0000000000
[37,]  0.000000000  0.000000000  0.000000000  0.0000000000
[38,]  0.000000000  0.000000000  0.000000000  0.0000000000
[39,]  0.000000000  0.000000000  0.000000000  0.0000000000
[40,]  0.000000000  0.000000000  0.000000000  0.0000000000
[41,]  0.000000000  0.000000000  0.000000000  0.0000000000
[42,]  0.000000000  0.000000000  0.000000000  0.0000000000
[43,]  0.000000000  0.000000000  0.000000000  0.0000000000
[44,]  0.000000000  0.000000000  0.000000000  0.0000000000
[45,]  0.000000000  0.000000000  0.000000000  0.0000000000
[46,]  0.000000000  0.000000000  0.000000000  0.0000000000
[47,]  0.000000000  0.000000000  0.000000000  0.0000000000
[48,]  0.000000000  0.000000000  0.000000000  0.0000000000
[49,]  0.000000000  0.000000000  0.000000000  0.0000000000
[50,]  0.000000000  0.000000000  0.000000000  0.0000000000
[51,]  0.000000000  0.000000000  0.000000000  0.0000000000
[52,]  0.000000000  0.000000000  0.000000000  0.0000000000
[53,]  0.000000000  0.000000000  0.000000000  0.0000000000
[54,]  0.000000000  0.000000000  0.000000000  0.0000000000
[55,]  0.000000000  0.000000000  0.000000000  0.0000000000
[56,]  0.000000000  0.000000000  0.000000000  0.0000000000
[57,]  0.000000000  0.000000000  0.000000000  0.0000000000
[58,]  0.000000000  0.000000000  0.000000000  0.0000000000
[59,]  0.000000000  0.000000000  0.000000000  0.0000000000
[60,]  0.000000000  0.000000000  0.000000000  0.0000000000
[61,]  0.000000000  0.000000000  0.000000000  0.0000000000
[62,]  0.000000000  0.000000000  0.000000000  0.0000000000
[63,]  0.000000000  0.000000000  0.000000000  0.0000000000
[64,]  0.000000000  0.000000000  0.000000000  0.0000000000
[65,]  0.000000000  0.000000000  0.000000000  0.0000000000
[66,]  0.000000000  0.000000000  0.000000000  0.0000000000
[67,]  0.000000000  0.000000000  0.000000000  0.0000000000
[68,]  0.000000000  0.000000000  0.000000000  0.0000000000
[69,]  0.000000000  0.000000000  0.000000000  0.0000000000
[70,]  0.000000000  0.000000000  0.000000000  0.0000000000
              [,1]          [,2]          [,3]          [,4]
[1,]  0.9997417811  2.166757e-04 -0.0002361597  2.309047e-04
[2,]  0.0002166757  1.000161e+00 -0.0002215642 -4.634658e-05
[3,] -0.0002361597 -2.215642e-04  1.0007830450 -5.379070e-04
[4,]  0.0002309047 -4.634658e-05 -0.0005379070  1.000216e+00

CVR documentation built on May 2, 2019, 8:50 a.m.