-
Notifications
You must be signed in to change notification settings - Fork 2
/
figure1.R
48 lines (39 loc) · 1.25 KB
/
figure1.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
# --------------------------------------------------------------------------- #
# ASCE-ASME paper - code for Fig 1
# --------------------------------------------------------------------------- #
source("weibull-sys-functions.R")
source("plotdefs.R")
# example for Fig 1: assume mean ft = 9
beta <- 2
y0 <- failuretolambda(9, beta)
n0 <- 2
t1 <- 1
t2 <- 2
n2 <- n0 + 2
y2 <- (n0*y0 + t1^beta + t2^beta)/n2
y2
eft2 <- lambdatofailure(y2, beta)
eft2
invgammavar <- function(n0, y0)
y0^2/(1-1/n0)
invgammasd <- function(n0, y0)
sqrt(y0^2/(1-1/n0))
invgammavar(n2, y2)
invgammasd(n2, y2)
invgammasd(n0, y0)
failuretolambda(7)
(2*failuretolambda(7) + 6^2 + 7^2)/4
# the plot
xseq <- seq(0.1, 200, length.out = 300)
fig1df <- data.frame(x = rep(xseq, 2),
y = c(cpinvgamma(xseq, n0, y0), cpinvgamma(xseq, n2, y2)),
p = factor(rep(c("Prior", "Posterior"), each = length(xseq)),
levels = c("Prior", "Posterior")))
fig1 <- ggplot(fig1df, aes(x=x)) + geom_line(aes(y=y, group=p, colour=p)) + ylim(0, 1) +
theme_bw() + ijarcol + rightlegend + xlab(expression(lambda)) + ylab(expression(F(lambda)))
#setEPS()
#postscript("fig1.eps",width=5,height=3)
pdf("fig1.pdf",width=6,height=3)
fig1
dev.off()
#