-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbetadistribution.R
49 lines (29 loc) · 1.56 KB
/
betadistribution.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
# Draw the beta distribution.
x <- seq(0, 1, 0.001)
#a <- 0.5
a <- 2
s <- 2
maxprob<- 1.5
# graphics margins:
margins<-c(4.5,4.5,1,2)
png(filename="betadistribution.png", width=5, height=5, units="in", pointsize=10, bg="white", res=300, type="quartz")
plot(x, dbeta(x, shape1 = a, shape2 = s, log=FALSE), type = "l", ylim = c(0,maxprob), lwd = 2, xlab="X value", ylab="Probability of event occurrence")
i<- seq(0,1,0.01)
# polygon(c(i),dbeta(i, shape = a, scale = s), density=5, angle=45)
polygon(c(i),dbeta(i, shape1 = a, shape2 = s), col="darkblue")
text(6, 1.4, expression(f(x) == frac(1, s^a * Beta(a)) * x^(a - 1) * exp(-frac(x, s))))
text(6, 1.2, expression(paste(a > 0, ": shape parameter")))
text(6, 1.1, expression(paste(s > 0, ": scale parameter")))
title("Beta distribution: parameters shape=2 and scale=2",cex = 0.6)
dev.off()
png(filename="betadistribution_simple.png", width=5, height=5, units="in", pointsize=10, bg="white", res=300, type="quartz")
par(mar=margins)
plot(x, dbeta(x, shape1 = a, shape2 = s, log=FALSE), type = "l", ylim = c(0,maxprob), lwd = 2, xlab="X value", ylab="Probability of event occurrence")
i<- seq(0,1,0.01)
# polygon(c(i),dbeta(i, shape1 = a, shapes2 = s), density=5, angle=45)
polygon(c(i),dbeta(i, shape1 = a, shape2 = s), col="darkblue")
#text(6, 1.4, expression(f(x) == frac(1, s^a * Beta(a)) * x^(a - 1) * exp(-frac(x, s))))
#text(6, 1.2, expression(paste(a > 0, ": shape parameter")))
#text(6, 1.1, expression(paste(s > 0, ": scale parameter")))
#title("Beta distribution: parameters shape=2 and scale=2",cex = 0.6)
dev.off()