Closed venpopov closed 5 months ago
Now that we don't get NA values after #97, there is an easy fix:
mean_new <- function(x, ...) {
fun <- function(at, dist) {
unlist(density(dist, at)) * at
}
integrate(fun, -Inf, Inf, dist = x, rel.tol = .Machine$double.eps^0.5)$value
}
covariance_new <- function(x, ...) {
fun <- function(at, dist) {
unlist(density(dist, at)) * at^2
}
mean <- mean_int(dist)
integrate(fun, -Inf, Inf, dist = x, rel.tol = .Machine$double.eps^0.5)$value - mean^2
}
mean_new(trans_lnorm)
#> [1] 22.7599
var_int(trans_lnorm)
#> [1] 4396.756
Currently these are calculated with taylor series approximations, which are faster than the numerical integration and I think work fine in most cases. Maybe numerical integration would be fast enough with a higher tolerance, while still giving comparable accuracy but with improved consistency.
Closing as this is a duplicate of #73, you can add your examples or comments in that thread.
The mean and variance methods for transformed distributions give incorrect results. This is unrelated to recent changes, as it also happens on the cran version. Here are two examples:
Created on 2024-04-04 with reprex v2.1.0