View source: R/prepare_locus.R
set_groups | R Documentation |
[FUNCTIONALITY UNDER ACTIVE DEVELOPMENT, PERFORMANCE (CPU TIME) NOT OPTIMIZED]. Posterior probabilities of associations are computed for predefined groups of candidate predictors. Within each group, the mean-field inference procedure makes no independence assumptions for the regression coefficients; variables in each group are approximated by a multivariate normal distribution, and they share a single binary latent selection variable.
set_groups(n, p, pos_gr, verbose = TRUE)
n |
Number of samples. |
p |
Number of candidate predictors. |
pos_gr |
Vector gathering the predictor group positions (first index of each group). The predictors must be ordered by groups. |
verbose |
If |
An object of class "groups
" preparing the settings for group
selection 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 <- 250; p0 <- 75; 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_gr <- 100
pos_gr <- seq(1, p, by = ceiling(p/n_gr))
list_groups <- set_groups(n, p, pos_gr)
g0_av <- 50 # Number of active groups. /!\ Often best to set it large, as a
# too small value may (wrong) result in no group being selected.
vb <- locus(Y = Y, X = X, p0_av = g0_av, link = "identity",
list_groups = list_groups, user_seed = seed)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.