Learn R Programming

toscca (version 0.1.0)

toscamm.perm: Computes permutatied cc fot TOSCCA-MM

Description

This function estimates sparse canonical vectors for permuted matrices with multiple measurements.

Usage

toscamm.perm(
  A,
  B,
  nonzero_a,
  nonzero_b,
  K = 1,
  folds = 1,
  toPlot = FALSE,
  draws = 1000,
  cancor,
  bootCCA = NULL,
  silent = TRUE,
  parallel_logic = TRUE,
  nuisanceVar = 0,
  testStatType = "CC",
  model = "lme",
  lmeformula = " ~ 0 + poly(time,3) + (1|id)",
  arformula = NULL,
  ncores = NULL
)

Value

Permuted canonical correlation for ell K and p-values.

List with permuted correlations and p-values.

Arguments

A

A matrix.

B

A matrix.

nonzero_a

Integer. Threshold parameter for A.

nonzero_b

Integer. Threshold parameter for B.

K

Interger. Numner of components.

folds

Integer. Indicates number of folds to perform.

toPlot

Logical. Indicates if plots will be produced. Default is False.

draws

Integer. Number of draws in permutation.

cancor

Numeric vector of length K with estimated canonical correlations.

bootCCA

deprecated.

silent

Logical. TRUE to keep silent output messages. Default is FALSE.

parallel_logic

Logical. TRUE to parallelise folds. Default is FALSE.

nuisanceVar

Numeric. Number of nuisance variables.

testStatType

Character. Choice of test-statistic c("CC", "Wilks", "Roy"),

model

Character. c("lme", "ar"). Model to fit longitudinal latent space.

lmeformula

Character. LME formula. Default is " ~ -1 + time + (1|id)".

arformula

Numeric vector. Choice of ARIMA. Default is c(1,0,0).

ncores

numeric. Number of cores to use in parallelisation. Default is detectCores() -1.

Examples

Run this code
# example code
# \donttest{
# dont run due to parallel processes
#sample size etc
N = 10
p = 25
q = 5
X0 = list()
Y0 = list()

#Some associations with the true signal
cwa = (6:10) / 10
cwb  = -(2:3) / 10

alpha = rep(0, p)
beta = rep(0, q)

loc_alpha = 1:length(alpha)
loc_beta  = 1:length(beta)

alpha[loc_alpha] = cwa
beta[loc_beta] = cwb

sg = matrix(c(1, 0.6, 0.3, rep(0, 2),
              0.6, 1, 0.6, 0.3, rep(0, 1),
              0.3, 0.6, 1, 0.6, 0.3,
              rep(0,1), 0.3, 0.6, 1, 0.6,
              rep(0,2), 0.3, 0.6, 1), ncol = 5)
for(i in 1:N)
{
  times = 1:5
  Zi1 = (sin(100*times))^times +   times * 0.65 +rnorm(1,0,0.95)
  Zi = cbind(Zi1)
  #Simulate data and add some noise
  X0i = sapply(1:p, function(a) MASS::mvrnorm(1, (Zi %*% t(alpha))[,a], Sigma = sg))
  Y0i = sapply(1:q, function(a) MASS::mvrnorm(1, (Zi %*% t(beta))[,a], Sigma = sg))

  colnames(X0i) = paste0("X", 1:ncol(X0i))
  colnames(Y0i) = paste0("Y", 1:ncol(Y0i))
  #Check the simulated cross correlation
  #image(cor(X0i, Y0i))

  #Remove some observations
  # p_observed = 1
  X0i = cbind(id=i, time=times, X0i)#[rbinom(length(times),1,p_observed)==1,]
  Y0i = cbind(id=i, time=times, Y0i)#[rbinom(length(times),1,p_observed)==1,]

  X0[[i]] = X0i
  Y0[[i]] = Y0i
}

X0 = do.call("rbind", X0)
Y0 = do.call("rbind", Y0)

X = data.frame(X0); Y = data.frame(Y0)
nonz_a = c(2, 5, 10, 20)
nonz_b =  c(2, 3, 4)

mod <- tosccamm(X, Y, folds = 2, nonzero_a = nonz_a, nonzero_b = nonz_b, silent = TRUE)
nza <- mod$nonzero_a
nzb <- mod$nonzero_b
cc  <- mod$cancor
perm_cc <- toscamm.perm(X,Y, nonzero_a=nza, nonzero_b=nzb,cancor=cc, ncores=2, draws = 10)
# }

Run the code above in your browser using DataLab