-
Notifications
You must be signed in to change notification settings - Fork 9
/
graph.R
60 lines (45 loc) · 1.96 KB
/
graph.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
#################################################
plotgraph.bias <- function(result, b1, b2, p1, rho){
matrixA <- result[[1]] #; browser()
for (i in 2:length(result) ){
matrixA <- rbind(matrixA, result[[i]] )
}
KKK <- data.frame(N = as.factor(matrixA[,1]) ,
K = as.factor(matrixA[,2]) ,
b.init = matrixA[,3],
b.corr = matrixA[,4]
)
KKKK <- melt(KKK, id.vars = c("N", "K"),
measure.vars= c("b.init", "b.corr") )
######################
p <- ggplot(data = KKKK, aes(x = value, fill = variable, alpha = 0.05) )
pc1 <- p + geom_density() + geom_vline( xintercept = b1)
pc2 <- pc1 + facet_grid(N~K, scales = "free", labeller = label_both)
pc2 <- pc2 + xlab("") + labs(title = paste("b1 =", b1, ", b2 =", b2) )
print(pc2)
return(pc2)
}
#####################################################
plotgraph.normal <- function(result, b1, b2, p1, rho){
matrixA <- result[[1]] #; browser()
for (i in 2:length(result) ){
matrixA <- rbind(matrixA, result[[i]] )
}
KKK <- data.frame(N = as.factor(matrixA[,1]) ,
K = as.factor(matrixA[,2]) ,
# standardize point estimate
b.corr.std = ( matrixA[,4] - b1 ) * matrixA[ ,5]/ matrixA[,6]
)
KKKK <- melt(KKK, id.vars = c("N", "K"),
measure.vars= c("b.corr.std") )
base <- seq(-3, 3, length.out = 200 )
data.normal <- data.frame( base = base, y.base = dnorm(base) )
######################
p <- ggplot(data = KKKK, aes(x = value) )
pc0 <- p +geom_density(fill = "red", alpha = 0.5, color = "red")
pc1 <- pc0 + geom_line( aes(x = base, y = y.base ), data = data.normal, size = 1)
pc2 <- pc1 + facet_grid(N~K, scales = "free", labeller = label_both)
pc2 <- pc2 + xlab("") + labs(title = paste("b1 =", b1, ", b2 =", b2) ) + xlim(c(-3,3))
print(pc2)
return(pc2)
}