## (a) Workspace: simulated inputs
EXPR1 <- expression(a + b^d)
a <- rnorm(10000, 12, 1)
b <- rnorm(10000, 5, 0.1)
d <- runif(10000, 6, 7)
DAT1 <- makeDat(EXPR1)
## (b) Repeated observations from a CSV file (JCGM 100:2008, H.2)
f <- tempfile(fileext = ".csv")
write.csv(data.frame(V = c(5.007, 4.994, 5.005, 4.990, 4.999),
I = c(19.663, 19.639, 19.640, 19.685, 19.678),
phi = c(1.0456, 1.0438, 1.0468, 1.0428, 1.0433)), f, row.names = FALSE)
EXPR2 <- expression((V/I) * cos(phi))
DAT2 <- makeDat(EXPR2, file = f)
RES2 <- propagate(EXPR2, DAT2, type = "raw", cov = "full", nsim = 1E5, check = FALSE)
## (c) Uncertainty budget, mass calibration of EA 4/02
## (EMUE Compendium, section 3.6)
BUD <- data.frame(name = c("mS", "dmD", "dm", "dmC", "dB"),
value = c(10000.005, 0, 0.020, 0, 0),
## dm: standard uncertainty of the mean of 3 observations, s = 0.025 g
u = c(NA, NA, 0.025/sqrt(3), NA, NA),
U = c(0.045, NA, NA, NA, NA),
k = c(2, NA, NA, NA, NA),
a = c(NA, 0.015, NA, 0.010, 0.010),
dist = c("normal", "rect", "normal", "rect", "rect"))
EXPR3 <- expression(mS + dmD + dm + dmC + dB)
## means, u, df for type = "stat" ...
DAT3 <- makeDat(EXPR3, data = BUD)
attr(DAT3, "budget")
## ... or samples from the stated distributions for type = "sim"
DAT4 <- makeDat(EXPR3, data = BUD, output = "sim", nsim = 1E5)
RES4 <- propagate(EXPR3, DAT4, type = "sim", check = FALSE)
RES4$sim ## u = 0.029 g, 95 % coverage interval [9999.967, 10000.082] g
Run the code above in your browser using DataLab