set_blocks: Gather settings for parallel inference on partitioned...

Description Usage Arguments Value See Also Examples

View source: R/prepare_locus.R

Description

Parallel applications of the method on blocks of candidate predictors for large datasets allows faster and less RAM-greedy executions.

Usage

1
set_blocks(p, pos_bl, n_cpus, verbose = TRUE)

Arguments

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 TRUE, messages are displayed when calling set_blocks.

Value

An object of class "blocks" preparing the settings for parallel inference in a form that can be passed to the locus function.

See Also

locus

Examples

 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 = 2)

vb <- locus(Y = Y, X = X, p0_av = p0, link = "identity",
            list_blocks = list_blocks, user_seed = seed)

hruffieux/locus documentation built on Oct. 22, 2018, 6:54 a.m.