Skip to contents

Empirical Bayes multivariate functional regression

Usage

EBmvFR(
  Y,
  X,
  adjust = FALSE,
  pos = NULL,
  prior = "mixture_normal_per_scale",
  verbose = TRUE,
  maxit = 100,
  tol = 0.1,
  init_pi0_w = 1,
  nullweight = 10,
  control_mixsqp = list(verbose = FALSE, eps = 1e-06, numiter.em = 4),
  thresh_lowcount = 0,
  cal_obj = FALSE,
  quantile_trans = FALSE,
  gridmult = sqrt(2),
  max_step_EM = 1,
  max_SNP_EM = 100
)

Arguments

Y

functional phenotype, matrix of size N by size J. The underlying algorithm uses wavelets and expects a power-of-two grid. Otherwise the data are interpolated to a power-of-two grid. At least two individuals and four response positions are required.

X

finite numeric matrix of size n by p containing the covariates. Constant columns, including an explicit intercept, must be omitted; the response and predictors are centered internally.

adjust

logical if set to TRUE (default FALSE), then the output contains the adjusted coeficients (usefull to correct for batch effect)

pos

vector of length J, corresponding to position/time pf the observed column in Y, if missing, suppose that the observation are evenly spaced

prior

specify the prior used in susiF. The two available choices are available "mixture_normal_per_scale", "mixture_normal". Default "mixture_normal_per_scale",

verbose

If verbose = TRUE, the algorithm's progress, and a summary of the optimization settings are printed to the console.

maxit

Maximum number of complete coordinate-ascent sweeps.

tol

Non-negative convergence tolerance. With cal_obj=TRUE, stop when the absolute penalized ELBO change is at most tol. Otherwise, check relative changes in coefficients and residual variance, and absolute changes in mixture probabilities. An explicitly supplied tolerance is always respected. When omitted, the default is 0.1 for ELBO monitoring and 0.001 for parameter monitoring.

init_pi0_w, control_mixsqp, max_step_EM, max_SNP_EM

Legacy optimizer controls retained for call compatibility. These do not control the coordinate-ascent updates, which use one exact responsibility M-step per sweep over all predictors.

nullweight

Finite numeric value at least 1, using the same convention as ashr::ash. Adds (nullweight - 1) * log(pi0) to the ELBO for each fitted mixture, where pi0 is its null-component weight. The default is 10; 1 gives no penalty. The penalty is applied once for mixture_normal and once per retained scale for mixture_normal_per_scale, without scaling by the number of predictors or wavelet coefficients. Completely excluded scales are left unchanged.

thresh_lowcount

numeric, used to check the wavelet coefficients have problematic distribution (very low dispersion even after standardization). Basically check if the median of the absolute value of the distribution of a wavelet coefficient is below this threshold. If yes, the algorithm discard this wavelet column from fitting, prior learning and noise estimation; its effect and posterior variance are set to zero. Set to 0 by default. It can be useful when analyzing sparse data from sequence based assay or small samples.

cal_obj

If TRUE, record and monitor the penalized ELBO, including the initial value. If FALSE, monitor parameter changes without storing ELBO history.

quantile_trans

logical if set as TRUE perform normal quantile transform on wavelet coefficients

gridmult

numeric used to control the number of components used in the mixture prior (see ashr package for more details). From the ash function: multiplier by which the default grid values for mixsd differ from one another. (Smaller values produce finer grids.). Increasing this value may reduce computational time

Value

An EBmvFR object. fitted_func contains effect curves in the original predictor units; ind_fitted_func contains the fitted centered response. fitted_wc[[1]] contains posterior means and fitted_wc2[[1]] posterior variances in the standardized design. MLE_wc2[[1]] retains standard errors, despite its historical name. mixture_counts stores summed responsibilities by predictor and prior group. KL contains augmented-posterior KL divergences to the current prior, sigma2 the fitted noise variance, and active_wc the retained wavelet columns. niter counts completed sweeps and converged indicates whether the requested stopping criterion was reached. ELBO includes the null-weight penalty and is populated only when cal_obj=TRUE.

Details

Fits a factorized variational posterior by coordinate ascent in wavelet space. Normal-mixture prior variances are on the coefficient scale and are not multiplied by the residual variance. Mixture weights are updated from posterior component counts plus nullweight - 1 extra counts for the null component, separately at each wavelet scale when using mixture_normal_per_scale. A shared residual variance is estimated from the expected residual sum of squares over the retained wavelet columns.

Examples



library(ashr)
#> 
#> Attaching package: ‘ashr’
#> The following object is masked from ‘package:fsusieR’:
#> 
#>     get_pi0
library(wavethresh)
#> Loading required package: MASS
#> WaveThresh: R wavelet software, release 4.7.2, installed
#> Copyright Guy Nason and others 1993-2022
#> Note: nlevels has been renamed to nlevelsWT
set.seed(1)
#Example using curves simulated under the Mixture normal per scale prior
rsnr <- 1 #expected root signal noise ratio
N <- 100    #Number of individuals
P <- 10     #Number of covariates/SNP
pos1 <- 1   #Position of the causal covariate for effect 1
pos2 <- 5   #Position of the causal covariate for effect 2
lev_res <- 7#length of the molecular phenotype (2^lev_res)
f1 <-  simu_IBSS_per_level(lev_res )$sim_func#first effect
f2 <- simu_IBSS_per_level(lev_res )$sim_func #second effect

plot( f1, type ="l", ylab="effect", col="blue")
abline(a=0,b=0)
lines(f2, type="l", col="green")

legend(x=100,
      y=3,
      lty = rep(1,3),
      legend= c("effect 1", "effect 2" ),
      col=c("black","blue","yellow"))

G = matrix(sample(c(0, 1,2), size=N*P, replace=TRUE), nrow=N, ncol=P) #Genotype
beta0       <- 0
beta1       <- 1
beta2       <- 1
noisy.data  <- list()

for ( i in 1:N)
{
 f1_obs <- f1
 f2_obs <- f2
 noise <- rnorm(length(f1), sd=  (1/  rsnr ) * var(f1))
 noisy.data [[i]] <-   beta1*G[i,pos1]*f1_obs + beta2*G[i,pos2]*f2_obs + noise

}
noisy.data <- do.call(rbind, noisy.data)




plot( noisy.data[1,], type = "l", col=(G[1, pos1]*3+1),
     main="Observed curves \n colored by the causal effect", ylim= c(-40,40), xlab="")
for ( i in 2:N)
{
 lines( noisy.data[i,], type = "l", col=(G[i, pos1]*3+1))

}
legend(x=0.3,
      y=-10,
      lty = rep(1,3),
      legend= c("0", "1","2"),
      col=c("black","blue","yellow"))




Y <- noisy.data
X <- G
#Running Empirical Bayes multivariate function regression

out <- EBmvFR(Y,X )
#> [1] "Starting initialization"
#> [1] "Discarding  0 wavelet coefficients out of  128"
#> [1] "Initialization done"
#> [1] "Fitting iter 1"
#> [1] "Fitting iter 2"
#> [1] "Fitting iter 3"
#> [1] "Fitting iter 4"
#> [1] "Fitting iter 5"
#> [1] "Fitting iter 6"
#> [1] "Fitting iter 7"
#> [1] "Fitting iter 8"
#> [1] "Fitting iter 9"
#> [1] "Fitting iter 10"
#> [1] "Fitting iter 11"
#> [1] "Fitting iter 12"
#> [1] "Fitting iter 13"
#> [1] "Fitting iter 14"
#> [1] "Fitting iter 15"
#> [1] "Fitting iter 16"
#> [1] "Fitting iter 17"
#> [1] "Fitting iter 18"
#> [1] "Fitting iter 19"
#> [1] "Fitting iter 20"
#> [1] "Fitting iter 21"
#> [1] "Fitting iter 22"
#> [1] "Fitting iter 23"
#> [1] "Fitting iter 24"
#> [1] "Fitting iter 25"
#> [1] "Fitting iter 26"
#> [1] "Fitting iter 27"
#> [1] "Fitting iter 28"
#> [1] "Fitting iter 29"
#> [1] "Fitting iter 30"
#> [1] "Fitting iter 31"
#> [1] "Fitting iter 32"
#> [1] "Fitting iter 33"
#> [1] "Fitting iter 34"
#> [1] "Fitting iter 35"
#> [1] "Fitting iter 36"
#> [1] "Fitting iter 37"
#> [1] "Fitting iter 38"
#> [1] "Fitting iter 39"
#> [1] "Fitting iter 40"
#> [1] "Fitting iter 41"
#> [1] "Fitting iter 42"
#> [1] "Fitting iter 43"
#> [1] "Fitting iter 44"
#> [1] "Fitting iter 45"
#the easiest way to visualize the result is to use the plot_susiF function

plot( f1, type="l", main="Estimated effect 1", xlab="")
lines(unlist(out$fitted_func[1,]),col='blue' )
abline(a=0,b=0)
legend(x= 60,
      y=3,
      lty= rep(1,2),
      legend = c("effect 1"," EBmvFR est "),
      col=c("black","blue" )
)

plot( f2, type="l", main="Estimated effect 2", xlab="")
lines(unlist(out$fitted_func[5,]),col='green' )
abline(a=0,b=0)
legend(x= 85,
      y= 2,
      lty= rep(1,2),
      legend = c("effect 2"," EBmvFR est "),
      col=c("black","green" )
)


par(mfrow=c(1,1))