mitchelloharawild / distributional

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

Mixtures assume univariate components #121

Open robjhyndman opened 3 months ago

robjhyndman commented 3 months ago

e.g.,

library(distributional)
p1 <- p2 <- 0.5
mu1 <- c(0, 0)
mu2 <- c(3, 1)
Sigma1 <- rbind(c(1, 0.5), c(0.5, 1))
Sigma2 <- diag(2)
dist_mixture(
  dist_multivariate_normal(list(mu1), list(Sigma1)),
  dist_multivariate_normal(list(mu2), list(Sigma2)),
  weights = c(p1, p2)
) |>
  mean()
#> Error in vapply(x[["dist"]], mean, numeric(1L), ...): values must be length 1,
#>  but FUN(X[[1]]) result is length 2

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

mitchelloharawild commented 3 months ago

Implementation of this partly depends on #25, due to the problem being encapsulation of different distribution types.

dim(<dist>) exists to identify the appropriate dimension of the distribution, but is unused (and is not currently easy to use).