Mercurial > repos > cristian > notos
annotate Functions/density_pm.R @ 1:cb8bac9d0d37 draft default tip
planemo upload commit 4ec21642211c1fb7427e4c98fdf0f4b9a3f8a185-dirty
author | cristian |
---|---|
date | Thu, 07 Sep 2017 10:21:45 -0400 |
parents | 1535ffddeff4 |
children |
rev | line source |
---|---|
0
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
1 ### Auxiliary functions ### |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
2 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
3 # Finds the peak |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
4 peaks <- function(x,partial=TRUE){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
5 if (partial){ #includes the first and the last element |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
6 which(diff(c(TRUE,diff(x)>=0,FALSE))<0) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
7 }else { |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
8 which(diff(diff(x)>=0)<0)+1 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
9 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
10 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
11 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
12 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
13 #Function that finds the valleys |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
14 valleys <- function(x,partial=TRUE){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
15 if (partial){ #includes the first and the last element |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
16 which(diff(c(FALSE,diff(x)>0,TRUE))>0) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
17 }else { |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
18 which(diff(diff(x)>0)>0)+1 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
19 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
20 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
21 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
22 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
23 #Function that calculates the probability masses |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
24 #ker: kernel density |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
25 #v: valleys |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
26 probability_mass <- function(ker,v){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
27 require(sfsmisc, quietly = TRUE) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
28 ker$y[which(ker$x<0)] = 0 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
29 pm = c() |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
30 for(j in 1:(length(v)-1)){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
31 pm[j] = integrate.xy(ker$x,ker$y,ker$x[v[j]],ker$x[v[j+1]], use.spline = FALSE) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
32 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
33 pm = pm/sum(pm) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
34 return(pm) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
35 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
36 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
37 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
38 #Function that tests if pm < value |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
39 #pm: probability masses |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
40 test_pm <- function(pm,value){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
41 p = c() |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
42 num_pm = length(pm) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
43 for(j in 1:num_pm){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
44 if(pm[j]<value){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
45 p = c(p,j) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
46 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
47 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
48 return(p) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
49 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
50 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
51 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
52 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
53 ### Main functions ### |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
54 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
55 # Estimate the kernel density and calculate the probability masses |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
56 # obs : data set |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
57 # num.points : number of points for the estimation of the kernel density |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
58 density_pm <- function(obs, num.points, p.bw = p.bw, threshold.modes = threshold.modes){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
59 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
60 # fit model |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
61 ker = density(obs, bw = p.bw, n = num.points) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
62 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
63 # find peaks |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
64 p = peaks(ker$y) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
65 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
66 # find valleys |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
67 v = valleys(ker$y) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
68 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
69 # probability masses |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
70 pm = probability_mass(ker,v) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
71 num_pm = length(pm) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
72 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
73 # number of pm < threshold.modes |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
74 p.del = test_pm(pm,threshold.modes) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
75 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
76 # delete modes with probability masses < threshold.modes |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
77 for(j in 1:num_pm){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
78 if(j %in% p.del){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
79 p[j] = NA |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
80 v[j+1] = NA |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
81 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
82 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
83 p = p[!is.na(p)] |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
84 v = v[!is.na(v)] |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
85 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
86 # probability masses (without the ones < threshold.modes) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
87 pm = probability_mass(ker,v) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
88 num_pm = length(pm) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
89 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
90 # number of pm<0.05 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
91 p5 = test_pm(pm,0.05) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
92 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
93 # number of pm<0.10 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
94 p10 = test_pm(pm,0.10) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
95 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
96 estimate = list(ker=ker,peaks=p,valleys=v,pm=pm,p5=p5,p10=p10) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
97 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
98 return(estimate) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
99 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
100 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
101 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
102 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
103 # Estimate the kernel density and calculate the probability masses, and do bootstrap |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
104 # obs : data set |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
105 # num.points : number of points for the estimation of the kernel density |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
106 density_pm_boot <- function(obs, num.points, p.bw = p.bw, threshold.modes = threshold.modes){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
107 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
108 # fit model |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
109 ker = density(obs,bw = p.bw, n = num.points) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
110 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
111 # find peaks |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
112 p = peaks(ker$y) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
113 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
114 # find valleys |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
115 v = valleys(ker$y) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
116 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
117 # probability masses |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
118 pm = probability_mass(ker, v) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
119 num_pm = length(pm) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
120 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
121 # number of pm < threshold.modes |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
122 p.del = test_pm(pm,threshold.modes) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
123 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
124 # delete modes with probability masses < threshold.modes |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
125 for(j in 1:num_pm){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
126 if(j %in% p.del){ |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
127 p[j] = 0 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
128 v[j+1] = 0 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
129 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
130 } |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
131 p = p[! p == 0] |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
132 v = v[! v == 0] |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
133 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
134 # probability masses (without the ones < threshold.modes) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
135 pm = probability_mass(ker,v) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
136 num_pm = length(pm) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
137 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
138 estimate = list(ker=ker,peaks=p,valleys=v,pm=pm) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
139 |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
140 return(estimate) |
1535ffddeff4
planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff
changeset
|
141 } |