uncertMC estimates measurement uncertainty from a function,
expression or formula by Monte Carlo simulation.
An expression, function, or formula with no left-hand side (e.g.
A named list or vector of parameters supplied to
A named list or named vector of length
Method of uncertainty evaluation. The only method currently supported
A named list or named vector of degrees of freedom.
Optional (square, symmetric) correlation or covariance matrices, respectively.
If neither is specified,
A character vector of length
A named list of lists of parameters describing the distributions
Number of Monte Carlo replicates.
Additional parameters to be passed to a function (for the function method) or used in an expression (for expression or formula method).
Although most likely to be called by
uncertMC may be called directly.
If any of
distrib.pars are not lists,
they are coerced to lists. If
x is not named, arbitrary names of the form 'Xn'
are applied. If
distrib.pars do not have
names, the names will be set to
names(x) if they are of length exactly
length(x); if not, an error is returned.
For Monte Carlo evaluation, distributions and distribution parameters are needed but
defaults are used if some or all are absent. If
distrib is missing, or
if it is a list with some members missing, the distribution is assumed Normal
and any missing member of
distrib is set to "norm".
Distributions are usually identified by the root of the distribution function name; for example
to specify the Normal,
distrib$name="norm". At present, only the random value
rnorm) is used. Names of user-specified distributions functions can also be
used, provided they have a random value generator named
is the abbreviated distribution. Parameters are passed to distribution functions using
do.call, so the function must accept the parameters supplied in
distrib.pars or members of it are missing, an attempt is made to deduce
appropriate distribution parameters from
In doing so, the following assumptions and values apply for the respective distributions:
min=x-sqrt(6)*u, max=x+sqrt(6)*u, mode=x.
df=df, mean=x, sd=u.
cov are present, a test is made to see if off-diagonal
elements are significant. If not,
uncertMC treats the values as independent.
The test simply checks whether the sum of off-diagonal elements of
cov is present) is bigger than
Correlation is supported as long as all correlated variables are normally distributed.
If correlation is present,
uncertMC follows a two-stage simulation procedure.
First, variables showing correlation are identified. Following a check that
distrib values are all
the MASS library is called to generate the simulated
x values for those variables.
Second, any remaining (i.e. independent) variables are simulated from their respective
Vectorisation makes a difference to execution speed. If
vectorize=TRUE, MC evaluation
eval using the simulated data as the evaluation environment; if not,
is used row-wise on the simulated input matrix. This makes an appreciable difference to
execution speed (typically
eval is faster by a factor of 5 or more) so the default
assumes vectorised expressions. However, not all functions and expressions take vector arguments,
especially user functions involving complicated arithmetic or numerical solutions. Use
for functions or expressions that do not take vector arguments.
Note: One common symptom of an expression that does not take vector arguments is
an R warning indicating that only the first element (typically of a parameter in
x) is used.
uncertMC may also return NA for
u on attempting to take the sd of a single simulated point.
An object of class
uncertMC-class for details.
S. L. R. Ellison email@example.com
JCGM 100 (2008) Evaluation of measurement data - Guide to the expression of uncertainty in measurement. http://www.bipm.org/utils/common/documents/jcgm/JCGM_100_2008_E.pdf. (JCGM 100:2008 is a public domain copy of ISO/IEC Guide to the expression of uncertainty in measurement (1995) ).
Kragten, J. (1994) Calculating standard deviations and confidence intervals with a universally applicable spreadsheet technique, Analyst, 119, 2161-2166.
Ellison, S. L. R. (2005) Including correlation effects in an improved spreadsheet calculation of combined standard uncertainties, Accred. Qual. Assur. 10, 338-343.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
expr <- expression(a+b*2+c*3+d/2) x <- list(a=1, b=3, c=2, d=11) u <- lapply(x, function(x) x/10) u.MC<-uncertMC(expr, x, u, distrib=rep("norm", 4), method="MC") print(u.MC, simplify=FALSE) #An example with correlation u.cor<-diag(1,4) u.cor[3,4]<-u.cor[4,3]<-0.5 u.formc.MC<-uncertMC(~a+b*2+c*3+d/2, x, u, cor=u.cor, keep.x=TRUE) u.formc.MC #A non-linear example expr <- expression(a/(b-c)) x <- list(a=1, b=3, c=2) u <- lapply(x, function(x) x/20) set.seed(403) u.invexpr<-uncertMC(expr, x, u, distrib=rep("norm", 3), B=999, keep.x=TRUE ) u.invexpr #Look at effect of vectorize system.time(uncertMC(expr, x, u, distrib=rep("norm", 3), B=9999, keep.x=TRUE )) system.time(uncertMC(expr, x, u, distrib=rep("norm", 3), B=9999, keep.x=TRUE, vectorize=FALSE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.