flash_r1c: Factor Loading Adaptive Shrinkage (non-constant on columns)

Description Usage Arguments Details Value Examples

Description

flash provide rank one matrix decomposition

Usage

1
flash_r1c(Y, tol = 1e-06, maxiter_r1 = 500)

Arguments

Y

is the data matrix (N by P)

tol

which is the stop criterion for the convergence, default is 1e-5

maxiter_r1

number of iteration, default is 500. for the backfitting case, the number of tau should be 5 or 10.

Details

flash_r1 privide rank one matrix decomposition with variational EM algorithm.

Value

list of factor, loading and variance of noise matrix

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
sim_hd = function(N, P, SF, SL, signal, a = rchisq(N,3),b = rchisq(P,1),mu = 0){
E = matrix(rep(0,N*P),nrow=N)
sig2_true = matrix(rep(0,N*P),nrow=N)
for(i in 1:N){
  for(j in 1:P){
    sig2_true[i,j] = mu + a[i] + b[j]
    E[i,j] = rnorm(1,0,sqrt(mu + a[i] + b[j]))
  }
}

K=1
lstart = rnorm(N, 0, signal)

fstart = rnorm(P, 0, signal)

index = sample(seq(1:N),(N*SL))
lstart[index] = 0
index = sample(seq(1:P),(P*SF))
fstart[index] = 0

Y = lstart %*% t(fstart) + E

return(list(Y = Y, L_true = lstart, F_true = fstart, Error = E,sig2_true = sig2_true))
}
N = 200
P = 500
SF = 0.5
SL = 0.5
signal = 1
data = sim_hd(N, P, SF, SL, signal, a = rep(1,N),b = rchisq(P,2),mu = 0)
sigmae2_true = data$sig2_true
Y = data$Y
E = data$Error
gc = flash_r1c(Y,tol = 1e-04,maxiter_r1 = 300)
f = gc$f
l = gc$l
sqrt(mean(((Y - l %*% t(f))-E)^2))/sqrt(mean((Y - E)^2))
# check the colmean
col_mean = gc$sigmae2
col_true = as.vector(sigmae2_true[1,])
plot(col_true,col_mean)
abline(a = 0,b=1,col = "red")
gc = flash_r1(Y,tol = 1e-04,maxiter_r1 = 300)
f = gc$f
l = gc$l
sqrt(mean(((Y - l %*% t(f))-E)^2))/sqrt(mean((Y - E)^2))

kkdey/flashr documentation built on May 20, 2019, 10:36 a.m.