set_hyper: Gather model hyperparameters provided by the user.

View source: R/set_hyper_init.R

set_hyperR Documentation

Gather model hyperparameters provided by the user.

Description

This function is used to provide hyperparameter values for atlasqtl.

Usage

set_hyper(q, p, eta, kappa, n0, nu, rho, t02)

Arguments

q

Number of responses.

p

Number of candidate predictors.

eta

Vector of length 1 or q. Provides the shape hyperparameter \eta for the gamma prior distribution of the response residual precision, \tau. If of length 1, the provided value is repeated q times.

kappa

Vector of length 1 or q. Provides the rate hyperparameter \kappa for the gamma prior distribution of the response residual precision, \tau. If of length 1, the provided value is repeated q times.

n0

Vector of length 1 or q, prior mean for the response effects.

nu

Vector of length 1 providing the shape hyperparameter \nu for the gamma prior distribution of \sigma^{-2}. \sigma represents the typical size of nonzero effects.

rho

Vector of length 1 providing the rate hyperparameter \rho for the prior distribution of \sigma^{-2}. \sigma represents the typical size of nonzero effects.

t02

Prior variance for the response effects.

Details

The atlasqtl function can also be used with default hyperparameter values (i.e., without using set_hyper) by setting its argument list_hyper to NULL.

Value

An object of class "hyper" preparing user hyperparameter in a form that can be passed to the atlasqtl function.

See Also

set_init, atlasqtl

Examples

seed <- 123; set.seed(seed)

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

## Examples using 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 hyperparameters ##
#############################

list_hyper <- set_hyper(q, p, eta = 1, kappa = 1, n0 = -2, nu = 1, rho = 1, 
                        t02 = 0.1)
                        
########################
## Infer associations ##
########################

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

res_atlas <- atlasqtl(Y, X, p0, list_hyper = list_hyper, user_seed = seed)


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