-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mean and variance are incorrect for transformed distributions #102
Comments
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
The text was updated successfully, but these errors were encountered: