-
Notifications
You must be signed in to change notification settings - Fork 2
/
flash_f1_size.Rmd
53 lines (45 loc) · 1.3 KB
/
flash_f1_size.Rmd
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
47
48
49
50
51
52
53
---
title: "flash_f1_size"
author: "Matthew Stephens"
date: "2021-10-21"
output: workflowr::wflow_html
editor_options:
chunk_output_type: console
---
## Introduction
Following up on some results from Joonsuk Kang,
I wanted to investigate how the "size" (PVE) of the first factor
affects ability to detect a second factor in a simple situation.
## Simulation
I'll simulate two factors, both random normal:
```{r}
library("flashr")
n = 100
p = 100
k = 2
LL = matrix(rnorm(p*k), nrow=n, ncol=k)
FF = matrix(rnorm(p*k), nrow=p, ncol=k)
E = matrix(rnorm(n*p),nrow=n,ncol=p)
Y = LL %*% t(FF) + E
svd(Y)$d[1:5] # singular values
fit1 = flashr::flash(Y,verbose=FALSE)
cor(flash_get_ldf(fit1)$l,LL)
```
Actually you see the non-identifiability here: because both factors
are a similar size they have similar eigenvalues so you get the rotation-invariance issue.
Now make first factor stronger. This makes the two factors identifiable and results are more accurate:
```{r}
FF[,1] = FF[,1]* 10
Y = LL %*% t(FF) + E
svd(Y)$d[1:5] # singular values
fit1 = flashr::flash(Y, verbose=FALSE)
cor(flash_get_ldf(fit1)$l,LL)
```
Now make first factor much stronger. It still seems to work....
```{r}
FF[,1] = FF[,1]* 1000
Y = LL %*% t(FF) + E
svd(Y)$d[1:5] # singular values
fit1 = flashr::flash(Y,verbose=F)
cor(flash_get_ldf(fit1)$l,LL)
```