[Distr-commits] r1265 - in branches/distr-2.8/pkg/distrEx: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Aug 10 15:55:48 CEST 2018


Author: ruckdeschel
Date: 2018-08-10 15:55:48 +0200 (Fri, 10 Aug 2018)
New Revision: 1265

Modified:
   branches/distr-2.8/pkg/distrEx/R/Expectation.R
   branches/distr-2.8/pkg/distrEx/R/GammaWeibullExpectation.R
   branches/distr-2.8/pkg/distrEx/inst/NEWS
   branches/distr-2.8/pkg/distrEx/man/E.Rd
Log:
[distrEx] + the Cauchy distribution now also uses quantile integration 

Modified: branches/distr-2.8/pkg/distrEx/R/Expectation.R
===================================================================
--- branches/distr-2.8/pkg/distrEx/R/Expectation.R	2018-08-10 12:53:27 UTC (rev 1264)
+++ branches/distr-2.8/pkg/distrEx/R/Expectation.R	2018-08-10 13:55:48 UTC (rev 1265)
@@ -467,8 +467,8 @@
 
 ### source: https://mathworld.wolfram.com/BinomialDistribution.html
 
-setMethod("E", signature(object = "Cauchy", 
-                         fun = "missing", 
+setMethod("E", signature(object = "Cauchy",
+                         fun = "missing",
                          cond = "missing"),
     function(object, low = NULL, upp = NULL, ...){
     if(is.null(low) && is.null(upp))
@@ -476,16 +476,16 @@
     else{
         if(is.null(low)) low <- -Inf
         if(is.null(upp)) upp <- Inf
-        if(low == -Inf){  
+        if(low == -Inf){
            if(upp == Inf) return(NA)
            else return(-Inf)
         }else{
-           return(if(upp == Inf) 
-                    Inf else 
-                    E(as(object,"AbscontDistribution"), low=low, upp=upp,...))
+           return(if(upp == Inf) Inf else{
+                    getMethod("E", signature(object = "Cauchy",
+                                     fun = "function", cond = "missing"))(object,
+                                          fun=function(x)(x<upp & x>low)*1.0,...)})
         }
     }
-#        return(E(as(object,"AbscontDistribution"), low=low, upp=upp, ...))    
   })
 
 ### source https://mathworld.wolfram.com/CauchyDistribution.html

Modified: branches/distr-2.8/pkg/distrEx/R/GammaWeibullExpectation.R
===================================================================
--- branches/distr-2.8/pkg/distrEx/R/GammaWeibullExpectation.R	2018-08-10 12:53:27 UTC (rev 1264)
+++ branches/distr-2.8/pkg/distrEx/R/GammaWeibullExpectation.R	2018-08-10 13:55:48 UTC (rev 1265)
@@ -98,3 +98,18 @@
              IQR.fac = IQR.fac, ...,
              .withLeftTail = TRUE, .withRightTail = TRUE)
     })
+
+
+setMethod("E", signature(object = "Cauchy", fun = "function", cond = "missing"),
+    function(object, fun, low = NULL, upp = NULL,
+             rel.tol= getdistrExOption("ErelativeTolerance"),
+             lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
+             upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
+             IQR.fac = max(1e4,getdistrExOption("IQR.fac")), ...
+             ){
+    .qtlIntegrate(object = object, fun = fun, low = low, upp = upp,
+             rel.tol= rel.tol, lowerTruncQuantile = lowerTruncQuantile,
+             upperTruncQuantile = upperTruncQuantile,
+             IQR.fac = IQR.fac, ...,
+             .withLeftTail = TRUE, .withRightTail = TRUE)
+    })

Modified: branches/distr-2.8/pkg/distrEx/inst/NEWS
===================================================================
--- branches/distr-2.8/pkg/distrEx/inst/NEWS	2018-08-10 12:53:27 UTC (rev 1264)
+++ branches/distr-2.8/pkg/distrEx/inst/NEWS	2018-08-10 13:55:48 UTC (rev 1265)
@@ -16,7 +16,8 @@
 
 under the hood:
 + moved quantile integration methods for expectation for Weibull and
-  Gamma distribution from pkg RobExtremes to distrEx 
+  Gamma distribution from pkg RobExtremes to distrEx; this is now also used
+  for Cauchy distributions  
 + introduce exported helper function .qtlIntegrate  to achieve this
   (is reused in RobExtremes for the GEV methods there)
 + cleaned .Rd file E.Rd: It contained still some references to methods

Modified: branches/distr-2.8/pkg/distrEx/man/E.Rd
===================================================================
--- branches/distr-2.8/pkg/distrEx/man/E.Rd	2018-08-10 12:53:27 UTC (rev 1264)
+++ branches/distr-2.8/pkg/distrEx/man/E.Rd	2018-08-10 13:55:48 UTC (rev 1265)
@@ -62,6 +62,7 @@
 \alias{E,Weibull,missing,missing-method}
 \alias{E,Gammad,function,missing-method}
 \alias{E,Weibull,function,missing-method}
+\alias{E,Cauchy,function,missing-method}
 \alias{.qtlIntegrate}
 
 \title{Generic Function for the Computation of (Conditional) Expectations}
@@ -194,6 +195,11 @@
 \S4method{E}{Beta,missing,missing}(object, low = NULL, upp = NULL, ...)
 \S4method{E}{Binom,missing,missing}(object, low = NULL, upp = NULL, ...)
 \S4method{E}{Cauchy,missing,missing}(object, low = NULL, upp = NULL, ...)
+\S4method{E}{Weibull,function,missing}(object, fun, low = NULL, upp = NULL,
+             rel.tol = getdistrExOption("ErelativeTolerance"),
+             lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
+             upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
+             IQR.fac = max(1e4,getdistrExOption("IQR.fac")), ...)
 \S4method{E}{Chisq,missing,missing}(object, low = NULL, upp = NULL, ...)
 \S4method{E}{Dirac,missing,missing}(object, low = NULL, upp = NULL, ...)
 \S4method{E}{DExp,missing,missing}(object, low = NULL, upp = NULL, ...)
@@ -267,11 +273,12 @@
   expectation; no conditioning with respect to \code{low <= object <= upp}
   is done.
 
-  For the Gamma and Weibull distribution for integration with missing argument
-  \code{cond} but given argument \code{fun}, we use integration on [0,1]
-  (i.e, via the respective probability transformation). This done via helper
+  For the Cauchy, the Gamma and Weibull distribution for integration with
+  missing argument \code{cond} but given argument \code{fun}, we use
+  integration on [0,1]  (i.e, via the respective probability transformation).
+  This done via helper
   function \code{.qtlIntegrate}, where both arguments \code{.withLeftTail}
-  and \code{.withRightTail} are \code{TRUE} for the Gamma distribution,
+  and \code{.withRightTail} are \code{TRUE} for the Cauchy and Gamma distributions,
   and only \code{.withRightTail} ist \code{TRUE} for the Weibull distribution.
   }
 



More information about the Distr-commits mailing list