Package 'uncertainty'

Title: Uncertainty Estimation and Contribution Analysis
Description: Implements the Gaussian method of first and second order, the Kragten numerical method and the Monte Carlo simulation method for uncertainty estimation and analysis.
Authors: Hugo Gasca-Aragon
Maintainer: Hugo Gasca-Aragon <[email protected]>
License: GPL (>= 2)
Version: 0.2.0
Built: 2025-01-10 02:59:40 UTC
Source: https://github.com/cran/uncertainty

Help Index


Uncertainty Estimation and Contribution Analysis

Description

Uncertainty estimation and contribution analysis implemented by 4 methods: the Gaussian method of first, the Gaussian method of second order, the Kragten numerical method and the Monte Carlo simulation method

Details

Package: uncertainty
Type: Package
Version: 0.1.1
Date: 2014-06-12
License: GPL (>=2)

Define an "uncertainty budget" object, including all the involved variables. Then estimate the "uncertainty" object by defining a measurand model, using the "uncertainty budget" and applying an estimation method. Print or plot the measurand estimates or create a "summary uncertainty" object to print or plot the uncertainty contributions to the measurand model.

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

Becker, R.A., Chambers, J.M. and Wilks, A.R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

uncertaintyBudget, print.uncertaintyBudget, uncertainty, print.uncertainty, plot.uncertainty, summary.uncertainty, print.summary.uncertainty, plot.summary.uncertainty

Examples

require(mvtnorm)

cor.mat<- matrix(c(1,-0.7,-0.7,1),2,2)

u.budget<- uncertaintyBudget(x=list(name=c("x0","x1"), 
	mean=c(10,20), u=c(1,5), dof=c(10,10),
	label=c("x[0]", "x[1]"), distribution=c("normal","normal")), y=cor.mat)
u.budget


## Gaussian first order estimates
GFO.res<- uncertainty(x=u.budget,
y=list(measurand_name="ratio.GFO", 
measurand_label=expression(ratio[GFO]), 
measurand_model="x0/x1", 
method="GFO", alpha=0.05))

contr.GFO<- summary.uncertainty(GFO.res)

## Monte Carlo estimates
MC.res<- uncertainty(x=u.budget, 
y=list(measurand_name="ratio.MC", 
measurand_label=expression(ratio[MC]),
measurand_model="x0/x1", 
method="MC", alpha=0.05, B=1e5))

contr.MC<- summary.uncertainty(MC.res)

## print the estimates
MC.res
GFO.res

## print the uncertainty summary
contr.MC
contr.GFO

## Displaying both estimated distributions
## Not run: 
plot(MC.res, col=4, xlab=MC.res$measurand_model)
plot(GFO.res, lty=2, col=2, add=T)
legend(0.7, 2.5, legend=c("Monte Carlo", "Gaussian First Order"), 
lty=c(1,2), col=c(4,2), lwd=2, bg="white")

## End(Not run)

## Display both uncertainty summaries

## Not run: 
barplot(cbind(contr.GFO$budget$contrib, contr.MC$budget$contrib), 
beside=TRUE, horiz=TRUE, main="Uncertainty contribution by method",
xlab="percent Variance",
names.arg=c(GFO.res$measurand_label, MC.res$measurand_label))

## End(Not run)

##########################
## Example H.1 from GUM ##
##########################

# define the uncertainty budget

u.budget<- uncertaintyBudget(
  x=list(
    name=c("lambda.s", "alpha.s", "theta.bar", "Delta", "delta.alpha",
    "delta.theta", "d.bar", "d.cr",
	"d.cnr"),
    label=c("lambda[s]", "alpha[s]", "bar(theta)", "Delta", "delta[alpha]",
    "delta[theta]", "bar(d)", "d[cr]", "d[cnr]"),
    mean=c(50.000623,11.5e-6,-1e-1, 0, 0, 0, 2.15e-4, 0, 0),
    units=c("mm", "oC^-1","oC","oC", "oC^-1", "oC", "mm", "mm", "mm"),
    u=c(25e-6, 1.2e-6, 0.2, 0.35, 0.58e-6, 0.029, 5.8e-6, 3.9e-6, 6.7e-6),
    distribution=c("t","unif","unif","arcsine","unif","unif","t","t","t"),
    dof=c(18, 1, 1, 1, 50, 2, 24, 5, 8)
  ),
  y=diag(1, 9)
)

# define the measurand
measurand_name<- "lambda"
measurand_label<- "lambda"
measurand_model<- paste("(lambda.s*(1+alpha.s*(theta.bar+Delta+delta.theta))",
"+d.bar+d.cr+d.cnr)/(1+(alpha.s+delta.alpha)*(theta.bar+Delta))", sep="")

# estimate the measurand using the Gaussian First Order method (GUM)

u.GFO<- uncertainty(
	x=u.budget, 
	y=list(measurand_name=measurand_name, 
		measurand_label=measurand_label, 
		measurand_model=measurand_model,
		alpha=0.01,
		method="GFO"
	)
)

u.GFO
# same result as reported in Table H.1

# estimate the measurand using the Gaussian Second Order method

u.GSO<- uncertainty(
	x=u.budget, 
	y=list(measurand_name=measurand_name, 
		measurand_label=measurand_label, 
		measurand_model=measurand_model,
		alpha=0.01,
		method="GSO"
	)
) 

u.GSO
# same results as reported in section H.1.6, U(99) = 93 nm,
# the difference is due to rounding error.
# u = 34 nm, but dof are updated to 21 instead of keeping 16.

# estimate the measurand using the Monte Carlo method (GUM supplement 1)

u.MC<- uncertainty(
	x=u.budget, 
	y=list(measurand_name=measurand_name, 
		measurand_label=measurand_label, 
		measurand_model=measurand_model,
		alpha=0.01,
		method="MC", B=1e6
	)
) 

u.MC
# this result is not reported in the GUM

# estimate the measurand using the Kragten method

u.Kragten<- uncertainty(
	x=u.budget, 
	y=list(measurand_name=measurand_name, 
		measurand_label=measurand_label, 
		measurand_model=measurand_model,
		alpha=0.01,
		method="Kragten"
	)
) 

u.Kragten
# same as GFO results

Plots an uncertainty summary. It shows the uncertainty contribution from each involved quantity

Description

Builds a barplot with a bar for each source of uncertainty. If correlation is present then an additional entry is added. The current metric used to display is When correlation is present its contribution may be negative.

Usage

## S3 method for class 'summary.uncertainty'
plot(x, y = NULL, ...)

Arguments

x

an uncertainty summary object

y

not used.

...

additional parameters to customize the plot

Details

none

Value

None (invisible NULL)

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method.

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

See Also

summary.uncertainty, plot

Examples

# create an uncertainty budget
cor.mat<- matrix(c(1,-0.7,-0.7,1),2,2)

u.budget<- uncertaintyBudget(x=list(name=c("x0","x1"), 
	mean=c(10,20), u=c(1,5), dof=c(10,10),
	label=c("x[0]", "x[1]"), distribution=c("normal","normal")), 
	y=cor.mat)

# estimate the measurand uncertainty using an uncertainty budget,
# a measurand definition and a selected estimating method.
GFO.res<- uncertainty(x=u.budget, 
y=list(measurand_name="ratio.GFO", measurand_label="ratio[GFO]", 
measurand_model="x0/x1", method="GFO", alpha=0.05))

# create an uncertainty summary object
GFO.sum<- summary(GFO.res)

# display the chart
## Not run: plot(GFO.sum)

Plots a probability density function related to the measurand model

Description

Plot a probability density function attributed to the measurand, depending on the selected method to estimate the uncertainty.

Usage

## S3 method for class 'uncertainty'
plot(x, y = NULL, xlab = parse(text = x$measurand_label), 
main = "", ylab = "Probability density", from = x$mean - 4 * x$u, to = x$mean + 4 * x$u, 
lwd = 2, add = FALSE, ...)

Arguments

x

An uncertainty object

y

not used, exists only for compatibility with the S3 generic function.

xlab

string or expression, label for the x-axis.

main

string or expression, label for the plot.

ylab

string or expression, label for the y-axis.

from

numeric, lower value of the x-axis to display.

to

numeric, upper valur of the x-axis to display.

lwd

numeric, line width.

add

logic, decides to add the curve into an existing plot or to create a new plot.

...

additional parameters.

Details

none

Value

None (invisible NULL)

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

See Also

uncertainty.default, plot

Examples

# create an uncertainty budget
cor.mat<- matrix(c(1,-0.7,-0.7,1),2,2)

u.budget<- uncertaintyBudget(x=list(name=c("x0","x1"), 
	mean=c(10,20), u=c(1,5), dof=c(10,10),
	label=c("x[0]", "x[1]"), distribution=c("normal","normal")), 
	y=cor.mat)

# estimate the measurand uncertainty using an uncertainty budget,
# a measurand definition and a selected estimating method.
GFO.res<- uncertainty(x=u.budget, 
y=list(measurand_name="ratio.GFO", measurand_label="ratio[GFO]", 
measurand_model="x0/x1", method="GFO", alpha=0.05))

# plot the estimated pdf of the measurand
## Not run: plot(GFO.res)

Displays a list with the uncertainty contribution from each input quantity

Description

For each input quantity (source of uncertainty) it shows the uncertainty contribution, measured in percent of variance of the measurand model.

Usage

## S3 method for class 'summary.uncertainty'
print(x, ...)

Arguments

x

An uncertainty summary object

...

Additional parameters

Details

none

Value

None (invisible NULL)

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

Becker, R.A., Chambers, J.M. and Wilks, A.R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

summary.uncertainty, print

Examples

# create an uncertainty budget
cor.mat<- matrix(c(1,-0.7,-0.7,1),2,2)

u.budget<- uncertaintyBudget(x=list(name=c("x0","x1"), 
	mean=c(10,20), u=c(1,5), dof=c(10,10),
	label=c("x[0]", "x[1]"), distribution=c("normal","normal")), 
	y=cor.mat)
u.budget

# estimate the measurand uncertainty using an uncertainty budget,
# a measurand definition and a selected estimating method.
GFO.res<- uncertainty(x=u.budget, 
y=list(measurand_name="ratio.GFO", measurand_label="ratio[GFO]", 
measurand_model="x0/x1", method="GFO", alpha=0.05))

GFO.res

# create an uncertainty summary object
GFO.sum<- summary(GFO.res)

# implicit call to the print method
GFO.sum

# same as
print(GFO.sum)

# uncertainty summary structure
attributes(GFO.sum)

Displays the detailed content of a measurand model including its uncertainty estimate.

Description

Displays the estimated value of the measurand, its standard deviation, its standard uncertainty, the degrees of freedom and the significance level and an CI with that significance level.

Usage

## S3 method for class 'uncertainty'
print(x, ...)

Arguments

x

an uncertainty object

...

additional parameters

Details

none

Value

None (invisible NULL)

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

Becker, R.A., Chambers, J.M. and Wilks, A.R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

uncertainty.default, print

Examples

# create an uncertainty budget
cor.mat<- matrix(c(1,-0.7,-0.7,1),2,2)

u.budget<- uncertaintyBudget(x=list(name=c("x0","x1"), 
	mean=c(10,20), u=c(1,5), dof=c(10,10),
	label=c("x[0]", "x[1]"), distribution=c("normal","normal")), 
	y=cor.mat)
u.budget

# estimate the measurand uncertainty using an uncertainty budget,
# a measurand definition and a selected estimating method.
GFO.res<- uncertainty(x=u.budget, 
y=list(measurand_name="ratio.GFO", measurand_label="ratio[GFO]", 
measurand_model="x0/x1", method="GFO", alpha=0.05))

# implicit call to print method
GFO.res

# same as
print(GFO.res)

# structure of an uncertainty estimation object
attributes(GFO.res)

Prints an uncertainty budget object

Description

Print the description of each uncertainty source

Usage

## S3 method for class 'uncertaintyBudget'
print(x, ...)

Arguments

x

an uncertainty budget object

...

additional parameters

Details

none

Value

None (invisible NULL)

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

Becker, R.A., Chambers, J.M. and Wilks, A.R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

uncertaintyBudget.default, print

Examples

cor.mat<- matrix(c(1,-0.7,-0.7,1),2,2)

u.budget<- uncertaintyBudget(x=list(name=c("x0","x1"), 
	mean=c(10,20), u=c(1,5), dof=c(10,10),
	label=c("x[0]", "x[1]"), distribution=c("normal","normal")), 
	y=cor.mat)

# implicitly calls the print method
u.budget

# same as
print(u.budget)

# uncertainty budget structure
attributes(u.budget)

Creates an uncertainty summary object

Description

Performs an uncertainty contribution estimation for the uncertainty object. The metric used to measure the contribution is percent of variance. If correlation is present an additional entry is shown with the whole contribution due to correlated input quantities.

Usage

## S3 method for class 'uncertainty'
summary(object, ndigits = 3, ...)

Arguments

object

an uncerainty object

ndigits

numeric, the number of digits for displaying.

...

additional parameters

Details

none

Value

An uncertainty summary object:

call

the call invocation

measurand.name

name of the measurand

measurand.label

label of the measurand for displaying purposes

budget

a list with the name, mean, label, u(uncertainty), dof and uncertainty contribution for each input quantity plus a correlation entry if any

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.

See Also

uncertainty.default, print.summary.uncertainty, summary

Examples

# create an uncertainty budget
cor.mat<- matrix(c(1,-0.7,-0.7,1),2,2)

u.budget<- uncertaintyBudget(x=list(name=c("x0","x1"), 
	mean=c(10,20), u=c(1,5), dof=c(10,10),
	label=c("x[0]", "x[1]"), distribution=c("normal","normal")), 
	y=cor.mat)
u.budget

# estimate the measurand uncertainty using an uncertainty budget,
# a measurand definition and a selected estimating method.
GFO.res<- uncertainty(x=u.budget, 
y=list(measurand_name="ratio.GFO", measurand_label="ratio[GFO]", 
measurand_model="x0/x1", method="GFO", alpha=0.05))

GFO.res

# create an uncertainty summary object
GFO.sum<- summary(GFO.res)

# implicit call to the print method
GFO.sum

# same as
print(GFO.sum)

# uncertainty summary structure
attributes(GFO.sum)

Creates an uncertainty object

Description

Builds an uncertainty estimation object using a measurand model and an uncertainty budget object

Usage

uncertainty(x, ...)

Arguments

x

an uncertainty budget object

...

additional parameters

Details

Creates an uncertainty estimation object. Uses an uncertainty budget object to estimate the expected value and uncertainty of a measurand by applying a selected estimation method.

Value

An uncertainty estimation object

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

Becker, R.A., Chambers, J.M. and Wilks, A.R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

uncertainty.default


Generic function for calling an uncertainty object

Description

Creates an uncertainty estimation object using a measurand model and an uncertainty budget object

Usage

## Default S3 method:
uncertainty(x, y, ...)

Arguments

x

an uncertainty budget object

y

a list with the measurand description and selected estimation method, the measurand description includes: measurand_name, measurand_model, measurand_label, alpha (significance level), method and method parameters.

the valid methods are: GFO, GSO, MC, Kragten.

currently the only method parameter implemented is the number of simulated samples (B) for the method MC.

...

additional parameters

Details

Creates an uncertainty estimation object. Uses an uncertainty budget object to estimate the expected value and uncertainty of a measurand by applying a selected estimation method.

Value

An uncertainty estimation object with the structure: method selected estimating method, call current call invocation, uncertaintyBudget an uncertainty budget object, measurand name, label, model describing the measurand, mean the estimated mean, sd the estimated standard deviation, u the estimated standard uncertainty, alpha the significante level used in the estimation, dof the estimated degrees of freedom, U the estimated expanded uncertainty, lcl the lower confidence interval, ucl the upper confidence interval, variables a vector with the input quantities, contribution a vector with the uncertainty contributions, cor.contribution the uncertainty contribution due to overall correlation, partial a vector of the partial derivatives of the measurand.model with respect to each input quantity, coeff a vector of the sensibility coefficients for each input quantity.

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

See Also

uncertainty, uncertaintyBudget.default, print.uncertainty, plot.uncertainty, summary.uncertainty

Examples

# create an uncertainty budget
cor.mat<- matrix(c(1,-0.7,-0.7,1),2,2)

u.budget<- uncertaintyBudget(x=list(name=c("x0","x1"), 
	mean=c(10,20), u=c(1,5), dof=c(10,10),
	label=c("x[0]", "x[1]"), distribution=c("normal","normal")), 
	y=cor.mat)
u.budget

# estimate the measurand uncertainty using an uncertainty budget,
# a measurand definition and a selected estimating method.
GFO.res<- uncertainty(x=u.budget, 
y=list(measurand_name="ratio.GFO", measurand_label="ratio[GFO]", 
measurand_model="x0/x1", method="GFO", alpha=0.05))

GFO.res

Generic function for uncertainty budget object

Description

Generic function for creating an uncertainty budget object

Usage

uncertaintyBudget(x, ...)

Arguments

x

a list with the vector entries name, label, mean, u(uncertainty), distribution and dof, one for each quantity.

...

additional parameters

Details

uncertaintyBudget is a generic function (under S3 protocol) for searching the default method.

Value

An uncertainty budget object with attributes:

name the name of each input quantity

mean the mean value of each input quantity

u the uncertainty of each input quantity

dof the degrees of freedom of each input quantity

label the label of each input quantity

distribution the distribution of each input quantity, valid values are (normal, unif, t, chisq, f, triangle, binomial, bernoulli, beta, gamma)

cor the correlation matrix among the input quantities

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

Becker, R.A., Chambers, J.M. and Wilks, A.R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

uncertaintyBudget.default


Generic function for calling an uncertainty budget object

Description

Creates an uncertainty budget.

Usage

## Default S3 method:
uncertaintyBudget(x, y, ...)

Arguments

x

a list with the vector entries name, label, mean, u(uncertainty), distribution and dof, one for each input quantity.

y

a correlation matrix of the input quantities, interpreted in the same order of input quantities as the vector name

...

additional parameters

Details

Creates an uncertainty budget object

Value

An uncertainty budget object with attributes:

name the name of each input quantity

mean the mean value of each input quantity

u the uncertainty of each input quantity

dofthe degrees of freedom of each input quantity

labelthe label of each input quantity

distribution the distribution of each input quantity, valid values are (bernoulli, beta, binomial, cuachy, chisq, exp, f, gamma, lognormal, poission, normal, unif, t, traingular, weibull, arcsine)

cor the correlation matrix among the input quantities

Note

none

Author(s)

H. Gasca-Aragon

Maintainer: H. Gasca-Aragon <[email protected]>

References

JCGM 100:2008. Guide to the expression of uncertainty of measurement

JCGM 100:2005. Supplement 1 Propagation of distributions usign a Monte Carlo method

EURACHEM/CITAC Guide CG 4. Quantifying Uncertainty in Analytical Measurement

Becker, R.A., Chambers, J.M. and Wilks, A.R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

uncertaintyBudget, uncertainty, print.uncertaintyBudget

Examples

require(mvtnorm)

cor.mat<- matrix(c(1,-0.7,-0.7,1),2,2)

u.budget<- uncertaintyBudget(x=list(name=c("x0","x1"), 
	mean=c(10,20), u=c(1,5), dof=c(10,10),
	label=c("x[0]", "x[1]"), distribution=c("normal","normal")), y=cor.mat)
u.budget