-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdiagram.R
86 lines (65 loc) · 2.31 KB
/
diagram.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
line <- function(x1,y1,x2,y2) lines(c(x1,x2),c(y1,y2))
red <- "#ee0000"
btext <- function(x,y,...) {
a <- 0.02
for(i in -2:2)
for(j in -2:2)
text(x+a*i,y+a*j,col="white",...)
text(x,y,...)
}
begin <- function() {
par(mar=c(0,0,0,0))
plot(0,type='n',axes=FALSE,ann=FALSE,
xlim=c(-1,6), ylim=c(-1,6), asp=1)
arrows(-1,0,5,0)
text(5,0, adj=c(-0.5,0.5), "y[1]")
arrows(0,-1,0,5)
text(0,5, adj=c(0.5,-0.5), "y[2]")
}
the_truth <- function() {
points(3.5,3.5, pch=21,bg="black")
btext(3.5,3.5, adj=c(1,0.5), "The unknown truth ")
}
one_exp <- function() {
points(3,5, pch=21,bg="white")
}
many_exp <- function() {
s <- 0.6
n <- 500
set.seed(123)
points(c(rnorm(n,mean=3.5,sd=s), 3), c(rnorm(n,mean=3.5,sd=s), 5), pch=21,bg="white")
btext(3.5, 1.5, "Possible experiment outcomes")
}
to_predict <- function() {
line(-1,-1, 5,5)
text(0,0, srt=45, adj=c(0.2,0), "Subspace of possible predictions")
arrows(4,4, 3,5, length=0.1)
line(3.8,3.8, 3.6,4.0)
line(3.6,4.0, 3.8,4.2)
text(3.5, 4.5, adj=c(0.5,-1.5),srt=-45, expression(hat(epsilon)))
text(3.5,4.5, adj=c(0.5,-0.5),cex=0.75,srt=-45, "residuals(fit)")
points(3,5, pch=21,bg="white")
text(3,5, adj=c(1.5,-0.5), expression(y))
points(4,4, pch=21,bg="grey")
text(4,4, adj=c(0,1.25), expression(Chi * hat(beta)))
text(4,4, adj=c(0,3.75), " predict(fit)")
}
to_test <- function() {
arrows(0,0, 3,5, length=0.1, col=red)
text(1.5, 2.5, adj=c(0.5, -0.5),cex=0.75,srt=60,col=red, "residuals(fit0)")
text(1.5, 2.5, adj=c(0.5, -1.5),srt=60,col=red, expression(hat(epsilon)[0]))
points(0,0, pch=21,bg="black")
text(0,0, adj=c(-0,1.1), " H0 restricted\n to this point")
line(-1,-1, 5,5)
text(2,2, srt=45, adj=c(0.5,0), "H1 can predict anything on this line")
arrows(4,4, 3,5, length=0.1, col=red)
line(3.8,3.8, 3.6,4.0)
line(3.6,4.0, 3.8,4.2)
text(3.5, 4.5, adj=c(0.5,-1.5),srt=-45,col=red, expression(hat(epsilon)[1]))
text(3.5,4.5, adj=c(0.5,-0.5),cex=0.75,srt=-45,col=red, "residuals(fit1)")
points(3,5, pch=21,bg="white")
text(3,5, adj=c(1.5,-0.5), expression(y))
points(4,4, pch=21,bg="grey")
#text(4,4, adj=c(0,1.25), expression(Chi * hat(beta)[1]))
#text(4,4, adj=c(0,3.75), " predict(fit1)")
}