-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathtail-signif.R
65 lines (46 loc) · 1.86 KB
/
tail-signif.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
#
# tail-signif.R, 16 Jul 16
# Data from:
#
# Example from:
# Evidence-based Software Engineering: based on the publicly available data
# Derek M. Jones
#
# TAG example
source("ESEUR_config.r")
plot_layout(2, 1)
par(mar=c(5, 1, 4, 1)+0.1)
pal_col=rainbow(3)
norm_mean=4
norm_sd=1
xpoints=seq(0, norm_mean+norm_sd*4, by=0.01)
ypoints=dnorm(xpoints, mean=norm_mean, sd=norm_sd)
qn=qnorm(c(0.975, 0.95), 0, norm_sd)
max_y=max(ypoints)
# Two-tailed significance test
plot(xpoints, ypoints, type="l", col=pal_col[3], fg="grey", col.axis="grey", yaxt="n",
bty="n", yaxt="n",
xlab="Two-tailed", ylab="")
q=c(norm_mean-qn[1], norm_mean+qn[1])
lines(c(q[1], q[1]), c(0, max_y), col=pal_col[1])
lines(c(q[2], q[2]), c(0, max_y), col=pal_col[1])
upper_y=subset(ypoints, xpoints <= norm_mean-qn[1])
upper_x=subset(xpoints, xpoints <= norm_mean-qn[1])
polygon(c(upper_x, norm_mean-qn[1], 0), c(upper_y, 0, 0), col=pal_col[2])
upper_y=subset(ypoints, xpoints >= norm_mean+qn[1])
upper_x=subset(xpoints, xpoints >= norm_mean+qn[1])
polygon(c(upper_x, norm_mean+qn[1]), c(upper_y, 0), col=pal_col[2])
text(norm_mean, max_y/1.5, "Fail to reject\nnull hypothesis", cex=1.4)
text(norm_mean-norm_sd*2.0, max_y/3, "Reject null\nhypothesis", pos=2, cex=1.4)
text(norm_mean+norm_sd*2.0, max_y/3, "Reject null\nhypothesis", pos=4, cex=1.4)
# One-tailed significance test
plot(xpoints, ypoints, type="l", col=pal_col[3], fg="grey", col.axis="grey", yaxt="n",
bty="n", yaxt="n",
xlab="One-tailed", ylab="")
q=norm_mean+qn[2]
lines(c(q[1], q[1]), c(0, max_y), col=pal_col[1])
upper_y=subset(ypoints, xpoints >= norm_mean+qn[2])
upper_x=subset(xpoints, xpoints >= norm_mean+qn[2])
polygon(c(upper_x, norm_mean+qn[2]), c(upper_y, 0), col=pal_col[2])
text(norm_mean-1.3, max_y/1.5, "Fail to reject null hypothesis", cex=1.4)
text(norm_mean+norm_sd*1.7, max_y/3, "Reject null\nhypothesis", pos=4, cex=1.4)