-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3clusters.R
88 lines (69 loc) · 2.54 KB
/
3clusters.R
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
asSparseMatrix <- function(CountsMatrix){
if(all(CountsMatrix == 0)){
CountsMatrix <- sparseMatrix(i = {}, j = {}, dims = dim(CountsMatrix))
} else {
Ind <- which(CountsMatrix != 0, arr.ind = T)
CountsMatrix <- sparseMatrix(i = Ind[,1],
j = Ind[,2],
x = CountsMatrix[Ind],
dims = dim(CountsMatrix))
}
CountsMatrix
}
One_Cluster <- function(N, G){
Counts <- rpois(N, lambda = rgamma(n = 1, rate = 0.3, shape = 0.6))
for(i in 2:G){
Counts <- cbind(Counts, rpois(N, lambda = rgamma(n = 1, rate = 0.3, shape = 0.6)))
}
asSparseMatrix(Counts)
}
Two_Clusters <- function(N, G){
stopifnot(N/2 == round(N/2))
N <- N/2
Counts1 <- rpois(N, lambda = rgamma(n = 1, rate = 0.3, shape = 0.6))
for(i in 2:(G/2)){
Counts1 <- cbind(Counts1, rpois(N, lambda = rgamma(n = 1, rate = 0.3, shape = 0.6)))
}
for(i in 1:(G/2)){
Counts1 <- cbind(Counts1, rpois(N, lambda = rgamma(n = 1, rate = 3, shape = 0.6)))
}
Counts2 <- rpois(N, lambda = rgamma(n = 1, rate = 3, shape = 0.6))
for(i in 2:(G/2)){
Counts2 <- cbind(Counts2, rpois(N, lambda = rgamma(n = 1, rate = 3, shape = 0.6)))
}
for(i in 1:(G/2)){
Counts2 <- cbind(Counts2, rpois(N, lambda = rgamma(n = 1, rate = 0.3, shape = 0.6)))
}
Counts <- rbind(Counts1, Counts2)
asSparseMatrix(Counts)
}
Three_Clusters <- function(N, G){
stopifnot(N/3 == round(N/3))
N <- N/3
Counts1 <- rpois(N, lambda = rgamma(n = 1, rate = 0.3, shape = 0.6))
for(i in 2:(G/3)){
Counts1 <- cbind(Counts1, rpois(N, lambda = rgamma(n = 1, rate = 0.3, shape = 0.6)))
}
for(i in 1:(2*(G/3))){
Counts1 <- cbind(Counts1, rpois(N, lambda = rgamma(n = 1, rate = 3, shape = 0.6)))
}
Counts2 <- rpois(N, lambda = rgamma(n = 1, rate = 3, shape = 0.6))
for(i in 2:(G/3)){
Counts2 <- cbind(Counts2, rpois(N, lambda = rgamma(n = 1, rate = 3, shape = 0.6)))
}
for(i in 1:(G/3)){
Counts2 <- cbind(Counts2, rpois(N, lambda = rgamma(n = 1, rate = 0.3, shape = 0.6)))
}
for(i in 1:(G/3)){
Counts2 <- cbind(Counts2, rpois(N, lambda = rgamma(n = 1, rate = 3, shape = 0.6)))
}
Counts3 <- rpois(N, lambda = rgamma(n = 1, rate = 3, shape = 0.6))
for(i in 2:(2*(G/3))){
Counts3 <- cbind(Counts3, rpois(N, lambda = rgamma(n = 1, rate = 3, shape = 0.6)))
}
for(i in 1:(G/3)){
Counts3 <- cbind(Counts3, rpois(N, lambda = rgamma(n = 1, rate = 0.3, shape = 0.6)))
}
Counts <- rbind(Counts1, Counts2, Counts3)
asSparseMatrix(Counts)
}