Coder Social home page Coder Social logo

r-quantities / quantities Goto Github PK

View Code? Open in Web Editor NEW
26.0 6.0 3.0 3.33 MB

Quantity Calculus for R Vectors

Home Page: https://r-quantities.github.io/quantities

License: Other

R 88.40% C++ 11.60%
r r-package quantity-calculus units-of-measurement uncertainty-propagation cran

quantities's Introduction

Quantity Calculus for R

Build Status Coverage Status CRAN_Status_Badge Downloads

The quantities package provides integration of the 'units' and 'errors' packages for a complete quantity calculus system for R vectors, matrices and arrays, with automatic propagation, conversion, derivation and simplification of magnitudes and uncertainties.

Documentation

Blog posts:

  1. Quantities for R -- First working prototype, Mar 1, 2018.
  2. Using quantities to parse data with units and errors, May 7, 2018.
  3. Data wrangling operations with quantities, Jun 27, 2018.
  4. Quantities for R -- Ready for a CRAN release, Aug 31, 2018.

Vignettes:

Papers:

  • Edzer Pebesma, Thomas Mailund and James Hiebert (2016). "Measurement Units in R." The R Journal, 8 (2), 486--494. DOI: 10.32614/RJ-2016-061
  • Iñaki Ucar, Edzer Pebesma and Arturo Azcorra (2018). "Measurement Errors in R." The R Journal, 10 (2), 549--557. DOI: 10.32614/RJ-2018-075

Installation

Install the release version from CRAN:

install.packages("quantities")

The installation from GitHub requires the remotes package.

# install.packages("remotes")
remotes::install_github(paste("r-quantities", c("units", "errors", "quantities"), sep="/"))

Acknowledgement

This project gratefully acknowledges financial support from the

quantities's People

Contributors

edzer avatar enchufa2 avatar lionel- avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

quantities's Issues

Wrapping lm() function

Hi everybody,

I open this issue in order to review any problems that I observed with lm function and the package quantiles.
I have reviewed the documentation. Specifically at the following link (https://www.r-spatial.org/r/2018/08/31/quantities-final.html#fitting-linear-models-with-quantities), it is very well specified how to include specific methods to use lm with the package quantities.
First of all, note that this is the first time I have tried to include experimental error in linear regression models. The first question that arises is whether to consider a regression weighing with the uncertainty of the response variable. It is a correct approach?
I have tried to include the weight parameter to the qlm function and it is not able to get the model. The error obtained is the following:

Model_Wc<-qlm(formula = Wcomp ~  Pevap + Pcond + Pevap:Pcond, weights = rep(1, 91),  data = df)
Error in eval(extras, data, env) : 
  ..1 usado en un contexto incorreto, ningún ... para examinar

I have reviewed the function definition and this supports additional parameters.

The other problem that I have noticed is the presence of a warning in the coef.qlm function. When the formula to be applied in the function is defined with interaction variables of type x1: x2 (the special nomenclature of th lm function), the following warning is obtained:

> df<-l_scroll$AHRI_66$HPR2A$SH_11
> Model_Wc<-qlm(formula = Wcomp ~  Pevap + Pcond + Pevap:Pcond,  data = df)
> coef(Model_Wc)
$`(Intercept)`
0.5(2) [kW]

$Pevap
0.06(2) [kW/bar]

$Pcond
0.34(1) [kW/bar]

$`Pevap:Pcond`
9(10)e-4 [kW]

Warning message:
In mapply(set_quantities, NextMethod(), coef.units, sqrt(diag(vcov(object))),  :
  el argumento más largo no es múltiplo de la longitud del más corto

On the other hand, If I applied the following definition for the formula parameter the warning disappears:

> Model_Wc<-qlm(formula = Wcomp ~  Pevap + Pcond + I(Pevap*Pcond),  data = df)
> coef(Model_Wc)
$`(Intercept)`
0.5(2) [kW]

$Pevap
0.06(2) [kW/bar]

$Pcond
0.34(1) [kW/bar]

$`I(Pevap * Pcond)`
9(10)e-4 [kW/bar^2]

The results seem corrects but a warning is present in the first method.

An other question is about the summary obtained for this qlm objects. If I print the summary the Std. Error of the coefficients is not the same as te previous one (coef(Model_Wc)).

Other problem is how to define the uncertainty for the variables involved in the regression model? Is necessary to define as standard uncertainty or is it possible to define as an expanded uncertainty and to obtaint the correct error for the coefficients when I apply coef function?

Finally, the last question is about the predict function for qlm objects. In the linked reported, it defines specific methods for qlm objects too. I have reviewed the function and it only applies the set_quantities function and it activates the native parameter se.fit. Is the obtained error correct? The se.fit parameter only activates the native confidenze intervals for the lm function. Are not necessary to take into account the experimental uncertainties for the calculation of the response variable error?

This problem is discussed in https://stats.stackexchange.com/questions/235693/linear-model-where-the-data-has-uncertainty-using-r but the final solution involves using the root python packe.

Sorry for the many doubts and thanks in advance

[feature request]: support for censored data and analysis methods

Thank you for this fantastic package. It's exactly what I dreamed of creating, but did not have the skill to create myself. I really feel like it should be a part of base R.

I'm not sure if this would fall into the scope of what you want for the package, or not, but a lot of measurement data has lower (and less frequently upper) detection/quantification/reporting limits. I work a lot with water sampling data, and this almost always has a lower reporting limit. Values less than this limit are reported as "below reporting limit", rather than as numerics. I realise this might be outside the scope of the package because the correct way to treat censored data is not as clear cut as units or errors.

On a related note, many measurements have a standardised method associated with them. It might be nice to treat this a bit like units, though less strictly. Possibly just giving a warning if an operation acts on two objects with different methods. Again, this may be outside of what you see as the legitimate scope of the package.

Sum return NaN errors

I'm know the package is not yet released, so a bug report is to premature. But I wanted just to point out in case this is unnoticed:

set_errors(1, 0) + set_errors(0, 0)
# 1(0)
set_quantities(1, 1, 0) + set_quantities(0, 1, 0)
# 1(NaN) 

Thanks for the awesome package =)

quantities does not work with unique() in tibbles

df <- tribble(
  ~a, ~b,
  "foo", set_quantities(1, mm, 1),
  "foo", set_quantities(1, mm, 1)
)
unique(df)
A tibble: 2 x 2
  a              b
  <chr> ± err [mm]
1 foo        1 ± 1
2 foo        1 ± 1

I had a more complex tibble with quantities where calling unique() wasn't working so I tested "df[1,] == df[2,]" and got the following error:

Warning message:
In '==' : boolean operators not defined for 'errors' objects, uncertainty dropped

However, I can't seem to get this error again with the minimal working example above even though unique() isn't working correctly.

The conversion celsius to fahrenheit is not applied in the uncertainty

Hello everybody,

First of all, congratulations for this wonderful package. I have used the units packages the last two years and the possibility to add the uncertainty in the same object is really interesting.

In my first test with this package I have noticed that the conversion celsius/farenhait is correct only for the main measure but incorrect for the uncertainty ( tc = (9/5)*(tf-32) )

This is a simple example to reproduce the error.

> library(quantities) 
> temp<-20 
> temp<-set_quantities(temp, unit = 'celsius', errors = 1) 
>  
>  
> temp 
20(1) [°C] 
> temp<-set_units(temp, 'kelvin')
> temp 
293(1) [K]

An other error to report is a wrong conversion btu/h to W in uncertainties too. The conversion factor to apply is 1055.056/3600 but applies 1000/3600. Rounding error? I didn't check any other conversion but it would be desirable to check more conversions between imperial/international units.

As commented above, these are my first test with the package and it's possible that I don't use the correct commands.

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.