Uncertainty Propagation for R Vectors

Support for measurement errors in R vectors, matrices and arrays: automatic uncertainty propagation and reporting.


BuildStatus CoverageStatus CRAN_Status_Badge Downloads

The errors package provides support for easurement errors in R vectors, matrices and arrays: automatic uncertainty propagation and reporting.

Installation

Install the release version from CRAN:

install.packages("errors")

The installation from GitHub requires the remotes package.

# install.packages("remotes")
remotes::install_github("r-quantities/errors")

Example

library(errors)
 
x <- 1:10
errors(x) <- 0.1
x
#> Errors: 0.1 0.1 0.1 0.1 0.1 ...
#>  [1]  1  2  3  4  5  6  7  8  9 10
 
(x <- set_errors(1:10, 1:10 * 0.05))
#> Errors: 0.05 0.10 0.15 0.20 0.25 ...
#>  [1]  1  2  3  4  5  6  7  8  9 10
 
(df <- data.frame(x, 3*x, x^2, sin(x), cumsum(x)))
#> Warning: In 'Ops' : non-'errors' operand automatically coerced to an
#> 'errors' object with no uncertainty
#>          x  X3...x     x.2   sin.x. cumsum.x.
#> 1  1.00(5)  3.0(2)  1.0(1)  0.84(3)   1.00(5)
#> 2   2.0(1)  6.0(3)  4.0(4)  0.91(4)    3.0(1)
#> 3   3.0(2)  9.0(5)  9.0(9)   0.1(1)    6.0(2)
#> 4   4.0(2) 12.0(6)   16(2)  -0.8(1)   10.0(3)
#> 5   5.0(2) 15.0(8)   25(2) -0.96(7)   15.0(4)
#> 6   6.0(3) 18.0(9)   36(4)  -0.3(3)   21.0(5)
#> 7   7.0(4)   21(1)   49(5)   0.7(3)   28.0(6)
#> 8   8.0(4)   24(1)   64(6)  0.99(6)   36.0(7)
#> 9   9.0(4)   27(1)   81(8)   0.4(4)   45.0(8)
#> 10 10.0(5)   30(2) 100(10)  -0.5(4)     55(1)
 
format(df, notation="plus-minus")
#>              x     X3...x       x.2       sin.x.   cumsum.x.
#> 1  1.00 ± 0.05  3.0 ± 0.2 1.0 ± 0.1  0.84 ± 0.03 1.00 ± 0.05
#> 2    2.0 ± 0.1  6.0 ± 0.3 4.0 ± 0.4  0.91 ± 0.04   3.0 ± 0.1
#> 3    3.0 ± 0.2  9.0 ± 0.5 9.0 ± 0.9    0.1 ± 0.1   6.0 ± 0.2
#> 4    4.0 ± 0.2 12.0 ± 0.6    16 ± 2   -0.8 ± 0.1  10.0 ± 0.3
#> 5    5.0 ± 0.2 15.0 ± 0.8    25 ± 2 -0.96 ± 0.07  15.0 ± 0.4
#> 6    6.0 ± 0.3 18.0 ± 0.9    36 ± 4   -0.3 ± 0.3  21.0 ± 0.5
#> 7    7.0 ± 0.4     21 ± 1    49 ± 5    0.7 ± 0.3  28.0 ± 0.6
#> 8    8.0 ± 0.4     24 ± 1    64 ± 6  0.99 ± 0.06  36.0 ± 0.7
#> 9    9.0 ± 0.4     27 ± 1    81 ± 8    0.4 ± 0.4  45.0 ± 0.8
#> 10  10.0 ± 0.5     30 ± 2  100 ± 10   -0.5 ± 0.4      55 ± 1
 
sum(x)
#> 55(1)
 
print(mean(x), digits=3)
#> 5.500(957)

News

errors 0.3.0

New features

  • Implement as.list for errors objects (7aff546).
  • Implement support for correlations between variables (#26). The correl and covar methods set and retrieve pairwise correlations or covariances, respectively, between errors objects, thereby completing the full first-order Taylor series method of propagation of uncertainty.
  • Add a new dataset from the Annex H of the Guide to the Expression of Uncertainty in Measurement (GUM) (as part of #26; see ?GUM.H.2 and examples under ?correl).
  • Implement all.equal for errors objects (as part of #26), which returns TRUE for different (different internal identifier) objects with the same quantity values and uncertainty. To compare whether two variables are exactly the same object, identical should be used instead.

Minor changes and fixes:

  • Fix encoding issues for the plus-minus symbol (#24).
  • Fix pillar representation (14df89b).
  • Fix coercion issues (0e04519).
  • Improve documentation (as part of #26).

errors 0.2.1

New features

  • New drop_errors method drops errors class and attributes. Equivalent to setting a NULL error (#23).
  • Implement pillar_shaft for tidy tibble printing and improve type_sum (700f1aa).

Minor changes and fixes:

  • Show Ops warnings once (#22).
  • Refactor print method (2c252d9).
  • Drop support for matrix multiplication: no warning is issued anymore (090e953).
  • Fix cbind/rbind column/row name parsing for named arguments (b8ea6b5).
  • Improve plus-minus separator (8b3d231).
  • Fix formatting to take into account the scipen option (9299551).

errors 0.2.0

Minor changes and fixes:

  • Show a warning and drop errors in boolean operators instead of failing (#17).
  • min, max, range return numeric, including the error: value minus error, value plus error and (min, max) respectively (#18).
  • Use structure instead of set_errors internally (#20).
  • Improved support for matrices and data frames with the implementation of rbind, cbind, as.data.frame for errors objects (#21).
  • Improved documentation and testing (#19).

errors 0.1.0

Minor changes and fixes:

  • Improved support for arrays and matrices (#4).
  • Inf, NaN and NA values default to Inf, NaN and NA errors respectively (#10).
  • Drop errors with a warning in matrix multiplication (#11).
  • Fix errors defined as integers (#12).
  • Do not allow boolean operators on errors objects (#13).
  • Give a default value to set_errors (#14).
  • Tidy tibble printing (#15).
  • Correct plot limits according to error bars (#16).

errors 0.0.2

Minor changes and fixes:

  • Fix exponentiation with negative base (#2).
  • Fix formatting when the value equals zero (#3).
  • Fix formatting when the error equals zero (#5).
  • Take digits into account for errors in vector display (#7).
  • Fix deletion of trailing zeroes in plus-minus notation (#8).

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("errors")

0.3.1 by Iñaki Ucar, 3 months ago


https://github.com/r-quantities/errors


Report a bug at https://github.com/r-quantities/errors/issues


Browse source code at https://github.com/cran/errors


Authors: Iñaki Ucar [aut, cph, cre]


Documentation:   PDF Manual  


Task views: Chemometrics and Computational Physics


MIT + file LICENSE license


Suggests tibble, pillar, testthat


Depended on by quantities.

Suggested by constants.


See at CRAN