-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsecond_step.R
More file actions
54 lines (44 loc) · 1.82 KB
/
second_step.R
File metadata and controls
54 lines (44 loc) · 1.82 KB
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
source("utilities.R")
source("BernGrid.R")
# Theta = seq( 0 , 1 , length=1001 ) # Fine teeth for Theta.
# pTheta = pmin( Theta , 1-Theta ) # Triangular shape for pTheta.
first_example <- function() {
Theta = seq( 0 , 1 , length=10001 ) # Fine teeth for Theta.
pTheta = rep(1,length(Theta)) # Uniform (horizontal) shape for pTheta.
pTheta = pTheta/sum(pTheta)
Data = c(rep(0,30),rep(1,10)) # 25% heads, N=40
openGraph(width=5,height=7)
posterior = BernGrid( Theta, pTheta , Data , plotType="Bars" ,
showCentTend="Mode" , showHDI=TRUE , showpD=FALSE )
}
third_example <- function() {
Theta = seq( 0 , 1 , length=1001 ) # Fine teeth for Theta.
pTheta = pmin( Theta , 1-Theta ) # Triangular shape for pTheta.
pTheta = pTheta ^ 20 # Sharpen pTheta !
pTheta = pTheta/sum(pTheta) # Make pTheta sum to 1.0
Data = c(rep(0,30),rep(1,10)) # 25% heads, N=40
openGraph(width=5,height=7)
posterior = BernGrid( Theta, pTheta , Data , plotType="Bars" ,
showCentTend="Mode" , showHDI=TRUE , showpD=FALSE )
}
iteration <- function(n = 5, x)
{
Theta = seq( 0 , 1 , length=1001 ) # Fine teeth for Theta.
pTheta = pmin( Theta , 1-Theta ) # Triangular shape for pTheta.
pTheta = pTheta ^ 20 # Sharpen pTheta !
pTheta = pTheta/sum(pTheta) # Make pTheta sum to 1.0
Data = c(rep(0,30),rep(1,10)) # 25% heads, N=40
openGraph(width=5,height=7)
posterior = BernGrid( Theta, pTheta , Data , plotType="Bars" ,
showCentTend="Mode" , showHDI=TRUE , showpD=FALSE )
for (i in 1:n) {
p1 <- proc.time()
Sys.sleep(x)
posterior = BernGrid( Theta, posterior , Data , plotType="Bars" ,
showCentTend="Mode" , showHDI=TRUE , showpD=FALSE )
proc.time() - p1 # The cpu usage should be negligible
}
}
first_example()
third_example()
iteration(n = 10, 5)