View source: R/prepare_locus.R
set_blocks | R Documentation |
Parallel applications of the method on blocks of candidate predictors for large datasets allows faster and less RAM-greedy executions.
set_blocks(p, pos_bl, n_cpus, verbose = TRUE)
p |
Number of candidate predictors. |
pos_bl |
Vector gathering the predictor block positions (first index of each block). |
n_cpus |
Number of CPUs to be used. If large, one should ensure that enough RAM will be available for parallel execution. Set to 1 for serial execution. |
verbose |
If |
An object of class "blocks
" preparing the settings for parallel
inference in a form that can be passed to the locus
function.
locus
seed <- 123; set.seed(seed)
###################
## Simulate data ##
###################
## Example using small problem sizes:
##
n <- 200; p <- 1200; p0 <- 200; d <- 50; d0 <- 40
## Candidate predictors (subject to selection)
##
# Here we simulate common genetic variants (but any type of candidate
# predictors can be supplied).
# 0 = homozygous, major allele, 1 = heterozygous, 2 = homozygous, minor allele
#
X_act <- matrix(rbinom(n * p0, size = 2, p = 0.25), nrow = n)
X_inact <- matrix(rbinom(n * (p - p0), size = 2, p = 0.25), nrow = n)
shuff_x_ind <- sample(p)
X <- cbind(X_act, X_inact)[, shuff_x_ind]
bool_x_act <- shuff_x_ind <= p0
pat_act <- beta <- matrix(0, nrow = p0, ncol = d0)
pat_act[sample(p0*d0, floor(p0*d0/5))] <- 1
beta[as.logical(pat_act)] <- rnorm(sum(pat_act))
## Gaussian responses
##
Y_act <- matrix(rnorm(n * d0, mean = X_act %*% beta, sd = 0.5), nrow = n)
Y_inact <- matrix(rnorm(n * (d - d0), sd = 0.5), nrow = n)
shuff_y_ind <- sample(d)
Y <- cbind(Y_act, Y_inact)[, shuff_y_ind]
########################
## Infer associations ##
########################
n_bl <- 6
pos_bl <- seq(1, p, by = ceiling(p/n_bl))
list_blocks <- set_blocks(p, pos_bl, n_cpus = 1)
vb <- locus(Y = Y, X = X, p0_av = p0, link = "identity",
list_blocks = list_blocks, user_seed = seed)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.