Permalink
Browse files

Added quantiles for (left-)truncated normal (with tests).

  • Loading branch information...
1 parent b6fd724 commit 995232be9e9386571d6896c043b935f156efce70 @tpapp committed Apr 14, 2012
Showing with 10 additions and 2 deletions.
  1. +4 −0 src/univariate.lisp
  2. +6 −2 tests/univariate.lisp
View
@@ -198,6 +198,10 @@ respectively), on the interval [left, \infinity).")
(cdf (x) (if (<= left x)
(/ (1- (+ (cdf-normal% x mu sigma) m0)) m0)
0d0))
+ (quantile (q)
+ (with-doubles (q)
+ (check-probability q :right)
+ (rmath:qnorm5 (+ (* q m0) (1c m0)) mu sigma 1 0)))
(mean () (truncated-normal-moments% 1 mu sigma left nil))
(variance () (truncated-normal-moments% 2 mu sigma left nil)))
View
@@ -60,12 +60,16 @@
(ensure-same (pdf rv -0.7) 0)
(ensure-same (pdf rv -0.3) 0.5515669)
(ensure-same (cdf rv -0.7) 0)
- (ensure-same (cdf rv -0.3) 0.1063703))
+ (ensure-same (quantile rv 0) -0.5)
+ (ensure-same (cdf rv -0.3) 0.1063703)
+ (ensure-same (quantile rv 0.1063703) -0.3))
(let ((rv (r-truncated-normal -0.5 nil -0.4 2.5)))
(ensure-same (pdf rv -0.7) 0)
(ensure-same (pdf rv -0.3) 0.3090382)
(ensure-same (cdf rv -0.7) 0)
- (ensure-same (cdf rv -0.3) 0.06184061)))
+ (ensure-same (cdf rv -0.3) 0.06184061)
+ (ensure-same (quantile rv 0) -0.5)
+ (ensure-same (quantile rv 0.06184061) -0.3)))
(addtest (cl-random-tests)
;; LEFT

0 comments on commit 995232b

Please sign in to comment.