flash | R Documentation |
This is the main interface for fitting EBMF models
based on algorithms from Wang and Stephens. The default behaviour
is simply to run the greedy algorithm and return the result. To
follow it by backfitting set backfit = TRUE
.
flash(data, Kmax = 100, f_init = NULL, var_type = c("by_column",
"by_row", "constant", "zero", "kroneker"), init_fn = "udv_si",
tol = 0.01, ebnm_fn = "ebnm_pn", ebnm_param = NULL,
verbose = TRUE, nullcheck = TRUE, seed = 123, greedy = TRUE,
backfit = FALSE)
data |
An n by p matrix or a flash data object created using
|
Kmax |
The maximum number of factors to be added to the flash object. |
f_init |
The flash object or flash fit object to which new
factors are to be added. If |
var_type |
The type of variance structure to assume for residuals. Options include:
|
init_fn |
The function used to initialize factors. Options include:
A user-specified function can also be used. This function should
take parameters |
tol |
Specifies how much the objective can change in a single iteration to be considered not converged. |
ebnm_fn |
The function used to solve the Empirical Bayes Normal
Means problem. Either a single character string (giving the name of
of the function) or a list with fields
|
ebnm_param |
A named list containing parameters to be passed to
|
verbose |
If |
nullcheck |
If |
seed |
A random number seed to use before running |
greedy |
If |
backfit |
If |
A flash object. Use flash_get_ldf
to access
standardized loadings and factors; use
flash_get_fitted_values
to access fitted LF'.
flash_add_greedy
, flash_backfit
set.seed(1) # for reproducibility
ftrue = matrix(rnorm(200), ncol=2)
ltrue = matrix(rnorm(40), ncol=2)
ltrue[1:10, 1] = 0 # set up some sparsity
ltrue[11:20, 2] = 0
Y = ltrue %*% t(ftrue) + rnorm(2000) # set up a simulated matrix
f = flash(Y)
ldf = f$ldf
# Show the weights, analogous to singular values showing importance
# of each factor.
ldf$d
# Plot true l against estimated l; with this seed it turns out the
# 2nd loading/factor corresponds to the first column of ltrue.
plot(ltrue[,1], ldf$l[,2])
# Plot true f against estimated f (note estimate is normalized).
plot(ftrue[,1], ldf$f[,2])
# Plot true lf' against estimated lf'; the scale of the estimate
# matches the data.
plot(ltrue %*% t(ftrue), f$fitted_values)
# Example to use the more flexible ebnm function in ashr.
f2 = flash(Y, ebnm_fn="ebnm_ash")
# Example to show how to pass parameters to ashr (may be most
# useful for research use).
f3 = flash(Y,
ebnm_fn="ebnm_ash",
ebnm_param=list(mixcompdist="normal", method="fdr"))
# Example to show how to separately specify parameters for factors
# and loadings.
f4 = flash(Y,
ebnm_fn=list(l="ebnm_pn", f="ebnm_ash"),
ebnm_param=list(l=list(),
f=list(g=ashr::normalmix(1,0,1), fixg=TRUE)))
# Example to show how to use a different initialization function.
library(softImpute)
f5 = flash(Y, init_fn=function(x, K=1){softImpute(x, K, lambda=10)})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.