truncnorm icon indicating copy to clipboard operation
truncnorm copied to clipboard

vtruncnorm: Variance is not calculated correctly

Open jpasquier opened this issue 2 years ago • 1 comments

Hi,

vtruncnorm returns Inf for some parameters.

Example:

> vtruncnorm(0, 1, 1, .1)
[1] Inf
> vtruncnorm2 <- function(a, b, m, s) {
+   a <- (a - m) / s
+   b <- (b - m) / s
+   Z <- pnorm(b) - pnorm(a)
+   s^2 * (1 - (b * dnorm(b) - a * dnorm(a)) / Z - ((dnorm(b) - dnorm(a)) / Z)^2)
+ } 
> vtruncnorm2(0, 1, 1, .1)
[1] 0.003633802

Best regards,

Jérôme

jpasquier avatar Apr 20 '23 10:04 jpasquier

Hi,

I'm also facing this problem (and also with etruncnorm). Are there any actions planned to tackle this?

Thank you very much. Best regards Jan

jkapar avatar May 30 '24 15:05 jkapar