mitchelloharawild / distributional

Vectorised distributions for R
https://pkg.mitchelloharawild.com/distributional
GNU General Public License v3.0
100 stars 16 forks source link

Inconsistency in vectorisation of multivariate distributions #119

Open robjhyndman opened 3 months ago

robjhyndman commented 3 months ago
library(distributional)
mu <- c(0, 0)
Sigma <- diag(2)
dist <- distributional::dist_multivariate_normal(list(mu), list(Sigma))

density(dist, at = c(0,0))
#> [[1]]
#> [1] 0.1591549
density(dist, at = matrix(c(0,0), nrow=1))
#> [1] 0.1591549

Created on 2024-07-31 with reprex v2.1.1

mitchelloharawild commented 3 months ago

I think the first option here should error, since the dimensions of at do not match the dimension of the distribution. What do you think?

The intended vectorisation is described in https://github.com/mitchelloharawild/distributional/issues/52#issuecomment-939891904, although more formal descriptions of how distributional vectorises distributions/operations is needed (#107).

robjhyndman commented 3 months ago

I was thinking a vector should be interpreted as a 1 row matrix, and then the dimensions do match. This is how mvtnorm::dmvnorm() works.

mitchelloharawild commented 3 months ago

For me it's a question of if that default mapping of dimensions is appropriate, and I'm leaning toward being strict and not having a default dimension for univariate inputs -> multivariate distributions (essentially requiring matrix inputs)