File: make_dataset.R

package info (click to toggle)
r-bioc-glmgampoi 1.2.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 704 kB
  • sloc: cpp: 523; ansic: 114; sh: 13; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 724 bytes parent folder | download | duplicates (2)
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


make_dataset <- function(n_genes = 1000, n_samples = 30){

  sf <- exp(rnorm(n = n_samples, mean = 1.7, sd = 0.7))
  dispersions <- rgamma(n = n_genes, shape = 3, rate = 6)
  X <- matrix(1, nrow = n_samples)  # Only intercept
  Betas <- matrix(rnorm(n = n_genes, mean = 0, sd = 3), nrow = n_genes)

  Q <- Betas %*% t(X)

  Y <- t(vapply(seq_len(n_genes), function(i){
    rnbinom(n_samples, mu = sf * exp(Q[i, ]), size = 1/dispersions[i])
  }, FUN.VALUE = rep(0.0, n_samples)))

  row_all_zero <- which(rowSums(Y) == 0)
  for(idx in row_all_zero){
    Y[idx, sample(seq_len(n_samples), 1)] <- 1
  }

  list(
    Y = Y,
    X = X,
    Q = Q,
    overdispersion = dispersions,
    size_factor = sf,
    Betas = Betas
  )
}