Vectorized truncated log-moment of the Weibull distribution
Source:R/truncated_moments.R
trunc_log_moment_vec.RdComputes \(E[\log T | T < t_i]\) for \(T \sim \text{Weibull}(\alpha, \beta)\) simultaneously for a vector of truncation points.
Details
Uses the identity: $$E[\log T | T < t] = \log \beta + \frac{1}{\alpha} E[\log U | U < v_{\max}]$$ where \(U \sim \text{Exp}(1)\) and \(v_{\max} = (t/\beta)^\alpha\).
The inner expectation \(E[\log U | U < v_{\max}]\) is computed via central finite difference of the lower incomplete gamma function at \(s = 1\).
For very small \(v_{\max}\) (below 1e-10), the asymptotic
approximation \(E[\log T | T < t] \approx \log t - 1/\alpha\) is used.
For large \(v_{\max}\) where numerical issues arise, the untruncated
moment \(E[\log T] = \log \beta + \psi(1)/\alpha\) is used as fallback,
where \(\psi\) is the digamma function.
Examples
# E[log T | T < t] for Weibull(shape=2, scale=1) at t = 0.5, 1.0, 2.0
v_max <- (c(0.5, 1.0, 2.0) / 1)^2
trunc_log_moment_vec(v_max_vec = v_max, alpha = 2, beta = 1)
#> [1] -1.2248035 -0.6301010 -0.3088497