BFR.BE.EM: Bayesian factor regression with batch effect correction.

Description Usage Arguments Value Examples

View source: R/BFR.BE.EM.R

Description

Bayesian factor regression with batch effect correction.

Usage

1
2
3
4
BFR.BE.EM(x, v = NULL, b = NULL, q = 2, eps = 0.001, it = 100,
  epsM = 0.05, prior = "N.MOM", varianceBE = TRUE, init = NULL,
  hyper = NULL, seed = 4, scaling = FALSE, intercept = FALSE,
  varimax = FALSE)

Arguments

x

n x p matrix of p observations for n individuals

v

n x p_v matrix of known covariates.

b

n x p_b matrix of batch indicator.

q

latent cardinality.

eps

margin for convergence.

it

maximum number of iterations.

epsM

margin for convergence for M.

prior

Spike prior to use for the laodings: "N.MOM", "Normal" or "Flat".

varianceBE

TRUE if variance batch correction is modeled; FALSE if not.

init

list of initial parameters.

hyper

list of hyper parameters.

seed

random seed to use.

scaling

mean centering the data?

intercept

adds intercept to the Bayesian factor regression.

varimax

TRUE for initial varimax rotated loadings.

Value

A list with the optimised parameters.

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
n<-200
p<-250
q<-10
Pv = 1
Pb = 2

grid<-seq(-1,1,length.out=p)
M<-matrix(grid,ncol=q,nrow=p)
rate<-trunc(p/(q*2))
for(i in 2:q){
  M[,i]<-grid[c((i*rate):p,1:(i*rate-1))]
}

Z <- rmvnorm(n,numeric(q),diag(q))
Psi <- diag(c(rep(.5,p)),p)
V <- matrix(ncol = Pv, nrow = n, runif(n*Pv,0,3))
Theta = matrix(ncol=Pv,c(rep(-2,round(p/2)),rep(2,p-round(p/2))))
batch = round(runif(n,0,1),0)
B = matrix(ncol=Pb, c(batch,ifelse(batch==1,0,1)))
Beta = matrix(ncol=Pb, c(rep(2,p),rep(0,p)))
Tau_inv = cbind(diag(Psi),diag(Psi)*1.5)
Er = matrix(ncol=p, nrow=n)
for (i in 1:n){
  if(i%%10==0){print(i)}
  Er[i,] = mvrnorm(1, rep(0,p), diag(c(Tau_inv %*% B[i,]),p), tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
}

X <- Z%*%t(M) + V%*%t(Theta) + B%*%t(Beta) + Er

result=BFR.BE.EM(x=X,v=V,b=B,q = 10)

AleAviP/BFR.BE documentation built on Feb. 22, 2020, 12:34 p.m.