r-quantities / errors

Uncertainty Propagation for R Vectors
https://r-quantities.github.io/errors
Other
49 stars 8 forks source link

Handle covariance matrix with vector input #58

Open StaffanBetner opened 1 year ago

StaffanBetner commented 1 year ago

Functionality like this would be useful to have available:

lm(formula = mpg ~ cyl + wt, data = mtcars) |> coef() -> coefficients
lm(formula = mpg ~ cyl + wt, data = mtcars) |> vcov() -> covar_mat

set_errors(coefficients, value = covar_mat) -> coefficients_covar

It is a bit cumbersome to set the covariances one by one.

Enchufa2 commented 1 year ago

What do you mean "one by one"?

Enchufa2 commented 1 year ago

Maybe something like

covar(x) <- vcov(fit)
set_covar(x, value=vcov(fit))

could be handled as special cases when the provided argument is detected as a valid covariance matrix?

The thing is that the output of this should be a list, which may be confusing for set_covar, but it's not acceptable for covar<- I think, because it's effectively changing the object. See this discussion about wrapping linear models.