Nothing
## propagate demo: all examples of JCGM 100:2008 (GUM), Annex H
## demo("GUM-AnnexH", package = "propagate")
library(propagate)
library(crayon)
M <- 1E6 ## Monte Carlo trials
## comparison of a computed value with a published (gauge) value; the published value is given as a
## character string, so that its decimals define the rounding tolerance; 'se' adds 4 Monte Carlo
## standard errors (of both calculations) for Monte Carlo results; note = TRUE marks a documented
## discrepancy of the published value (printed as NOTE instead of DIFF)
gauge <- function(item, value, published, se = 0, note = FALSE) {
d <- if (grepl(".", published, fixed = TRUE)) nchar(sub("^[^.]*\\.", "", published)) else 0
pub <- as.numeric(published); tol <- 0.5 * 10^-d + 4 * se; ok <- abs(value - pub) <= tol
cat(sprintf(" %-46s published %12s propagate %14.*f |diff| %8.2g tol %8.2g %s\n",
item, published, d + 2, value, abs(value - pub), tol, if (ok) green("PASS") else if (note) red("NOTE") else blue("DIFF")))
invisible(ok)
}
## Monte Carlo standard errors (both calculations with M trials) of the mean and the standard deviation of y
seMean <- function(y) sqrt(2) * sd(y)/sqrt(length(y))
seSD <- function(y) { k <- mean((y - mean(y))^4)/var(y)^2; sqrt(2) * sd(y) * sqrt((k - 1)/(4 * length(y))) }
seQ <- function(y, p) { f <- density(y, from = quantile(y, p), to = quantile(y, p), n = 1)$y; sqrt(2) * sqrt(p * (1 - p)/length(y))/f }
set.seed(100)
######## H.1 End-gauge calibration (l - 50 mm in nm), Table H.1 ########
data(H.1)
EX1 <- expression(Ls + d - Ls * (da * theta + as * dt) - 50000000)
H1 <- propagate(EX1, H.1, type = "stat", alpha = 0.01, nsim = M, check = FALSE)
H1
cat("Comparison with GUM H.1:\n")
gauge("l - 50 mm [nm]", H1$prop["mean.1"], "838")
gauge("u(l) [nm]", H1$prop["u.1"], "32")
gauge("nu_eff (truncated to 16)", H1$ws.df, "16")
gauge("k = t_99(16)", H1$k, "2.92")
gauge("U_99 [nm] (GUM: from the rounded u = 32 nm)", H1$u.exp, "93", note = TRUE)
gauge("u(l), second order [nm]", H1$prop["u.2"], "34")
######## H.2 Resistance, reactance and impedance, Table H.2 ########
data(H.2)
EX2 <- expression(R = (V/I) * cos(phi), X = (V/I) * sin(phi), Z = V/I)
H2 <- propagateMV(EX2, H.2, type = "raw", cov = "full", nsim = M)
H2
cat("Comparison with GUM H.2, approach 1 (Table H.3):\n")
for (j in 1:3) { gauge(paste(H2$names[j], "[Ohm]"), H2$guf$y[j], c("127.732", "219.847", "254.260")[j])
gauge(paste0("u(", H2$names[j], ") [Ohm]"), H2$guf$u[j], c("0.071", "0.295", "0.236")[j], note = (j == 2)) }
gauge("r(R, X)", H2$guf$r[1, 2], "-0.588"); gauge("r(R, Z)", H2$guf$r[1, 3], "-0.485"); gauge("r(X, Z)", H2$guf$r[2, 3], "0.993")
## u(X): NOTE; the LPU gives 0.2956, the printed 0.295 is the value of approach 2 (Table H.4)
YK <- sapply(EX2, function(e) eval(e, as.data.frame(H.2)))
cat("Approach 2 (Table H.4):\n")
for (j in 1:3) gauge(paste0("u(", H2$names[j], ") [Ohm]"), sd(YK[, j])/sqrt(5), c("0.071", "0.295", "0.236")[j])
H2d <- propagateMV(EX2, H.2, type = "raw", cov = "diag", nsim = M)
cat("Uncorrelated inputs (Table H.5):\n")
for (j in 1:3) gauge(paste0("u(", H2$names[j], ") [Ohm]"), H2d$guf$u[j], c("0.195", "0.201", "0.204")[j])
gauge("r(R, Z)", H2d$guf$r[1, 3], "0.527")
######## H.3 Calibration of a thermometer, Table H.6 ########
data(H.3)
FIT <- lm(bk ~ I(tk - 20), data = H.3)
V12 <- vcov(FIT); dimnames(V12) <- list(c("y1", "y2"), c("y1", "y2"))
EX3 <- expression(y1 + y2 * (30 - 20))
H3 <- propagate(EX3, cbind(y1 = c(coef(FIT)[1], sqrt(V12[1, 1]), 9), y2 = c(coef(FIT)[2], sqrt(V12[2, 2]), 9)),
type = "stat", cov = V12, ws.group = c(1, 1), mc.margins = "mvt", nsim = M, check = FALSE)
H3
cat("Comparison with GUM H.3:\n")
gauge("y1 [degC]", coef(FIT)[1], "-0.1712"); gauge("y2", coef(FIT)[2], "0.00218")
gauge("r(y1, y2)", cov2cor(V12)[1, 2], "-0.930"); gauge("s [degC]", summary(FIT)$sigma, "0.0035")
gauge("b(30 degC) [degC]", H3$prop["mean.1"], "-0.1494"); gauge("u(b) [degC]", H3$prop["u.1"], "0.0041")
gauge("nu = n - 2", H3$ws.df, "9")
######## H.4 Measurement of activity, Tables H.7, H.8 ########
data(H.4)
lambda <- 1.25894E-4
Rx <- (H.4$Cx - H.4$Cb)/60 * exp(lambda * H.4$tx)
Rs <- (H.4$Cs - H.4$Cb)/60 * exp(lambda * H.4$ts)
COV4 <- diag(c(0.0018, 0.0050, 0.0010, 0, 0)^2); COV4[4:5, 4:5] <- cov(cbind(Rx, Rs))/6
dimnames(COV4) <- rep(list(c("As", "ms", "mx", "Rx", "Rs")), 2)
DF4 <- cbind(As = c(0.1368, 0.0018, Inf), ms = c(5.0192, 0.0050, Inf), mx = c(5.0571, 0.0010, Inf),
Rx = c(mean(Rx), sd(Rx)/sqrt(6), 5), Rs = c(mean(Rs), sd(Rs)/sqrt(6), 5))
EX4a <- expression(As * (ms/mx) * (Rx/Rs))
H4a <- propagate(EX4a, DF4, type = "stat", cov = COV4, ws.group = c(NA, NA, NA, 1, 1), nsim = M, check = FALSE)
H4a
EX4b <- expression(As * (ms/mx) * R)
H4b <- propagate(EX4b, cbind(DF4[, 1:3], R = c(mean(Rx/Rs), sd(Rx/Rs)/sqrt(6), 5)),
type = "stat", nsim = M, check = FALSE)
cat("Comparison with GUM H.4:\n")
gauge("mean R_x [1/min]", mean(Rx), "652.60"); gauge("mean R_S [1/min]", mean(Rs), "206.09")
gauge("r(R_x, R_S)", cor(Rx, Rs), "0.646")
gauge("A_x [Bq/g], approach 1 (GUM: rounded ratio)", H4a$prop["mean.1"], "0.4300", note = TRUE)
gauge("u(A_x) [Bq/g], approach 1", H4a$prop["u.1"], "0.0083")
gauge("A_x [Bq/g], approach 2", H4b$prop["mean.1"], "0.4304")
gauge("u(A_x) [Bq/g], approach 2", H4b$prop["u.1"], "0.0084")
######## H.5 Analysis of variance, Table H.9 (V - 10 V in uV) ########
data(H.5)
Vj <- c(172, 116, 13, 144, 106, 31, 60, 125, 163, 41)
sjk <- c(60, 77, 111, 101, 67, 93, 80, 73, 88, 86)
H5 <- propagate(expression(V), cbind(V = Vj), type = "raw", nsim = M, check = FALSE)
H5
cat("Comparison with GUM H.5:\n")
gauge("s(V_j) [uV]", sd(Vj), "57"); gauge("s_b [uV]", sqrt(mean(sjk^2)), "85")
gauge("F (GUM: from rounded 57 and 85 uV)", 5 * var(Vj)/mean(sjk^2), "2.25", note = TRUE)
gauge("F_0.95(9, 40)", qf(0.95, 9, 40), "2.12")
gauge("V - 10 V [uV]", H5$prop["mean.1"], "97"); gauge("u [uV], between-day", H5$prop["u.1"], "18")
gauge("u [uV], pooled", sqrt((9 * 5 * var(Vj) + 40 * mean(sjk^2))/(50 * 49)), "13")
######## H.6 Rockwell C hardness, Table H.10 ########
data(H.6)
EX6 <- expression(100 - d - Dc - Db - DS)
BUD6 <- data.frame(name = c("d", "Dc", "Db", "DS"), value = c(36.0, 0, 0, 0),
u = c(sqrt(0.45^2/5 + 0.1^2/12), sqrt(0.10^2/6 + 0.11^2/6), NA, 0.5),
a = c(NA, NA, 0.015 * 36/2, NA), dist = c("normal", "normal", "tri", "normal"))
H6 <- propagate(EX6, makeDat(EX6, data = BUD6, output = "sim", nsim = M), type = "sim", check = FALSE)
H6
cat("Comparison with GUM H.6:\n")
gauge("h [RU]", H6$prop["mean.1"], "64.0"); gauge("u(h) [RU]", H6$prop["u.1"], "0.55")
gauge("u(Db) [RU]", 0.015 * 36/sqrt(24), "0.11")
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.