set_init: Gather initial variational parameters provided by the user.

View source: R/set_hyper_init.R

set_initR Documentation

Gather initial variational parameters provided by the user.

Description

This function must be used to provide initial values for the variational parameters by atlasqtl.

Usage

set_init(
  q,
  p,
  gam_vb,
  mu_beta_vb,
  sig02_inv_vb,
  sig2_beta_vb,
  sig2_theta_vb,
  tau_vb,
  theta_vb,
  zeta_vb
)

Arguments

q

Number of responses.

p

Number of candidate predictors.

gam_vb

Matrix of size p x q with initial values for the variational parameter yielding posterior probabilities of inclusion.

mu_beta_vb

Matrix of size p x q with initial values for the variational parameter yielding the posterior mean of regression estimates for predictor-response pairs included in the model.

sig02_inv_vb

Initial parameter for the hotspot propensity global precision.

sig2_beta_vb

Vector of length q. Initial values for the variational parameter yielding the posterior variance of regression estimates for predictor-response pairs included in the model.

sig2_theta_vb

Vector of length p. Initial values for the variational parameter yielding the posterior variance of the hotspot propensities.

tau_vb

Vector of length q with initial values for the variational parameter yielding estimates for the response residual precisions.

theta_vb

Vector of length p. Initial values for the variational parameter yielding the posterior mean of the hotspot propensities.

zeta_vb

Vector of length q. Initial values for the variational parameter yielding the posterior mean of the response propensities.

Details

The atlasqtl function can also be used with default initial parameter choices (without using set_init) by setting its argument list_init to NULL.

Value

An object of class "init" preparing user initial values for the variational parameters in a form that can be passed to the atlasqtl function.

See Also

set_hyper, atlasqtl

Examples

seed <- 123; set.seed(seed)

###################
## Simulate data ##
###################

# Example with small problem sizes:
#
n <- 200; p <- 50; p_act <- 10; q <- 100; q_act <- 50

# Candidate predictors (subject to selection)
#
# Here example with common genetic variants under Hardy-Weinberg equilibrium
#
X_act <- matrix(rbinom(n * p_act, size = 2, p = 0.25), nrow = n)
X_inact <- matrix(rbinom(n * (p - p_act), size = 2, p = 0.25), nrow = n)

# shuffle indices 
shuff_x_ind <- sample(p)
shuff_y_ind <- sample(q)

X <- cbind(X_act, X_inact)[, shuff_x_ind]

# Association pattern and effect sizes
#
pat <- matrix(FALSE, ncol = q, nrow = p)
bool_x <- shuff_x_ind <= p_act
bool_y <- shuff_y_ind <= q_act

pat_act <- beta_act <- matrix(0, nrow = p_act, ncol = q_act)
pat_act[sample(p_act * q_act, floor(p_act * q_act / 5))] <- 1
beta_act[as.logical(pat_act)] <-  rnorm(sum(pat_act))

pat[bool_x, bool_y] <- pat_act

# Gaussian responses
#
Y_act <- matrix(rnorm(n * q_act, mean = X_act %*% beta_act), nrow = n)
Y_inact <- matrix(rnorm(n * (q - q_act)), nrow = n)

Y <- cbind(Y_act, Y_inact)[, shuff_y_ind]


################################
## Specify initial parameters ##
################################

tau_vb <- rep(1, q)

gam_vb <- matrix(rbeta(p * q, shape1 = 1, shape2 = 4 * q - 1), nrow = p)

mu_beta_vb <- matrix(rnorm(p * q), nrow = p)
sig2_beta_vb <- 1 / rgamma(q, shape = 2, rate = 1)

sig02_inv_vb <- rgamma(1, shape = max(p, q), rate = 1)

theta_vb <- rnorm(p, sd = 1 / sqrt(sig02_inv_vb * q))
sig2_theta_vb <- 1 / (q + rgamma(p, shape = sig02_inv_vb * q, rate = 1))

zeta_vb <- rnorm(q, mean = -2, sd = 0.1)

list_init <- set_init(q, p, gam_vb, mu_beta_vb, sig02_inv_vb, sig2_beta_vb, 
                      sig2_theta_vb, tau_vb, theta_vb, zeta_vb)
                      
                      
########################
## Infer associations ##
########################

p0 <- c(mean(colSums(pat)), 10)

res_atlas <- atlasqtl(Y, X, p0, list_init = list_init)


hruffieux/atlasqtl documentation built on April 12, 2025, 12:54 p.m.