| mixCov | R Documentation |
This function aggregates covariance matrices, single variance values or vectors of variance values into one block-diagonal covariance matrix with dimnames, suitable for the cov argument of propagate.
mixCov(...)
... |
any number of covariance matrices (square, at least 2 x 2), single variance values or vectors of variance values, in the order in which the variables should appear in the result. |
'Mixes' (aggregates) data of the following types into a final covariance matrix:
1) covariance matrices \mathbf{\Sigma} that are already available.
2) single variance values \sigma^2.
3) a vector of variance values \sigma^2_1, \sigma^2_2, \ldots, \sigma^2_m.
Each covariance matrix is used as it is; a single variance or a vector of variances becomes a diagonal matrix. If the k-th argument has m_k variables and S_k = m_1 + \ldots + m_k (S_0 = 0), the result is the S_K \times S_K matrix \mathbf{C} (K = number of arguments) that is filled successively: the k-th argument fills rows and columns S_{k-1} + 1 \ldots S_k of \mathbf{C}, and all elements outside these diagonal blocks are 0 (no covariances between the blocks).
The dimnames of the result are taken, for each argument, from the column names of a covariance matrix or the names of a variance vector. If these are missing, the (first) variable in the argument's expression is used, e.g. "As" for As[2]^2, with a number appended if the argument holds more than one variance (e.g. "x1", "x2" for an unnamed vector x of length 2). If the expression contains no variable (e.g. a number), the names are "V1", "V2" and so on. Finally, make.unique makes all names unique. These names matter because propagate matches the rows/columns of cov to the columns of data by name.
The aggregated (block-diagonal) covariance matrix with dimnames.
Andrej-Nikolai Spiess
Evaluation of measurement data - Guide to the expression of uncertainty in measurement.
JCGM 100:2008. Joint Committee for Guides in Metrology (2008).
\Sexpr[results=rd]{tools:::Rd_expr_doi("10.59161/JCGM100-2008E")}
## Names of the result: column names of a matrix,
## names of a vector, else the variable in the call.
S <- matrix(c(4, 1, 1, 9), 2, 2, dimnames = list(c("a", "b"), c("a", "b")))
u <- 0.5
mixCov(S, c(d = 0.01, e = 0.04), u^2, 2)
#######################################################
## Example in Annex H.4.1 of JCGM 100:2008,
## measurement of activity.
## This will give exactly the same values as Table H.8.
data(H.4)
T0 <- 60 ## counting time in min (JCGM 100:2008, H.4)
lambda <- 1.25894E-4
Rx <- with(H.4, ((Cx - Cb)/T0) * exp(lambda * tx))
Rs <- with(H.4, ((Cs - Cb)/T0) * exp(lambda * ts))
mRx <- mean(Rx)
sRx <- sd(Rx)/sqrt(6)
mRx
sRx
mRs <- mean(Rs)
sRs <- sd(Rs)/sqrt(6)
mRs
sRs
R <- Rx/Rs
mR <- mean(R)
sR <- sd(R)/sqrt(6)
mR
sR
cor(Rx, Rs)
## Definition as in H.4.3.
As <- c(0.1368, 0.0018)
ms <- c(5.0192, 0.005)
mx <- c(5.0571, 0.001)
## We have to scale Rs/Rx by sqrt(6) to get the
## covariances of the means.
Rs <- Rs/sqrt(6)
Rx <- Rx/sqrt(6)
## Here we create an aggregated covariance matrix
## from the raw and summary data; its names are
## "Rs", "Rx", "As", "ms", "mx".
COV1 <- cov(cbind(Rs, Rx))
COV <- mixCov(COV1, As[2]^2, ms[2]^2, mx[2]^2)
COV
## Prepare the data for 'propagate'.
MEANS <- c(mRs, mRx, As[1], ms[1], mx[1])
SDS <- c(sRs, sRx, As[2], ms[2], mx[2])
DAT <- rbind(MEANS, SDS)
colnames(DAT) <- c("Rs", "Rx", "As", "ms", "mx")
## This will give exactly the same values as
## in H.4.3/H.4.3.1.
EXPR <- expression(As * (ms/mx) * (Rx/Rs))
propagate(EXPR, data = DAT, cov = COV, nsim = 10000, check = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.