[Distr-commits] r676 - in branches/distr-2.3/pkg/distr: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Sep 3 03:53:29 CEST 2010
Author: ruckdeschel
Date: 2010-09-03 03:53:29 +0200 (Fri, 03 Sep 2010)
New Revision: 676
Modified:
branches/distr-2.3/pkg/distr/R/ContDistribution.R
branches/distr-2.3/pkg/distr/R/UnivarLebDecDistribution.R
branches/distr-2.3/pkg/distr/R/UtilitiesDistributions.R
branches/distr-2.3/pkg/distr/R/internalUtils.R
branches/distr-2.3/pkg/distr/man/RtoDPQ.LC.Rd
branches/distr-2.3/pkg/distr/man/RtoDPQ.Rd
branches/distr-2.3/pkg/distr/man/UnivarLebDecDistribution.Rd
branches/distr-2.3/pkg/distr/man/igamma.Rd
Log:
distr: implemented Nataliya's quantile trick to avoid simulated grid points
Modified: branches/distr-2.3/pkg/distr/R/ContDistribution.R
===================================================================
--- branches/distr-2.3/pkg/distr/R/ContDistribution.R 2010-08-26 12:48:48 UTC (rev 675)
+++ branches/distr-2.3/pkg/distr/R/ContDistribution.R 2010-09-03 01:53:29 UTC (rev 676)
@@ -418,10 +418,19 @@
## Group Math for absolutly continuous distributions
setMethod("Math", "AbscontDistribution",
- function(x){ rnew <- function(n, ...){}
+ function(x){
+
+ rnew <- function(n, ...){}
body(rnew) <- substitute({ f(g(n, ...)) },
list(f = as.name(.Generic), g = x at r))
- object <- AbscontDistribution( r = rnew,
+
+ n <- 10^getdistrOption("RtoDPQ.e")+1
+ u <- seq(0,1,length=n+1); u <- (u[1:n]+u[2:(n+1)])/2
+ y <- callGeneric(q(x)(u))
+ DPQnew <- RtoDPQ(r=rnew, y=y)
+
+ object <- AbscontDistribution(d = DPQnew$d, p = DPQnew$p,
+ r = rnew, q = DPQnew$q,
.withSim = TRUE, .withArith = TRUE)
object
})
@@ -638,8 +647,14 @@
function(x){
rnew <- function(n, ...){}
body(rnew) <- substitute({ lgamma(g(n, ...)) }, list(g = x at r))
- object <- AbscontDistribution( r = rnew,
- .withSim = TRUE, .withArith = TRUE)
+
+ n <- 10^getdistrOption("RtoDPQ.e")+1
+ u <- seq(0,1,length=n+1); u <- (u[1:n]+u[2:(n+1)])/2
+ y <- lgamma(q(x)(u))
+ DPQnew <- RtoDPQ(r=rnew, y=y)
+
+ object <- AbscontDistribution( r = rnew, d = DPQnew$d, p = DPQnew$p,
+ q=DPQnew$q, .withSim = TRUE, .withArith = TRUE)
object
})
@@ -647,10 +662,16 @@
function(x){
rnew <- function(n, ...){}
body(rnew) <- substitute({ gamma(g(n, ...)) }, list(g = x at r))
- object <- AbscontDistribution( r = rnew,
- .withSim = TRUE, .withArith = TRUE)
+ n <- 10^getdistrOption("RtoDPQ.e")+1
+ u <- seq(0,1,length=n+1); u <- (u[1:n]+u[2:(n+1)])/2
+ y <- gamma(q(x)(u))
+ DPQnew <- RtoDPQ(r=rnew, y=y)
+
+ object <- AbscontDistribution( r = rnew, d = DPQnew$d, p = DPQnew$p,
+ q=DPQnew$q, .withSim = TRUE, .withArith = TRUE)
object
})
+
setMethod("sqrt", "AbscontDistribution",
function(x) x^0.5)
Modified: branches/distr-2.3/pkg/distr/R/UnivarLebDecDistribution.R
===================================================================
--- branches/distr-2.3/pkg/distr/R/UnivarLebDecDistribution.R 2010-08-26 12:48:48 UTC (rev 675)
+++ branches/distr-2.3/pkg/distr/R/UnivarLebDecDistribution.R 2010-09-03 01:53:29 UTC (rev 676)
@@ -1,12 +1,12 @@
UnivarLebDecDistribution <- function(acPart, discretePart, acWeight, discreteWeight,
- r = NULL, e = NULL, n = NULL){
+ r = NULL, e = NULL, n = NULL, y = NULL){
if(missing(discretePart) && missing(acPart) && missing(r) )
stop("at least one of 'discretePart' resp. 'acPart' resp. 'r' must be given")
if(missing(discretePart) && missing(acPart))
{if(missing(e)) e <- getdistrOption("RtoDPQ.e")
if(missing(n)) n <- getdistrOption("DefaultNrGridPoints")
- return(RtoDPQ.LC(r = r, e = e, n = n))}
+ return(RtoDPQ.LC(r = r, e = e, n = n, y = y))}
if(missing(discretePart)) {discreteWeight <- 0; acWeight <- 1;
discretePart <- new("Dirac")}
Modified: branches/distr-2.3/pkg/distr/R/UtilitiesDistributions.R
===================================================================
--- branches/distr-2.3/pkg/distr/R/UtilitiesDistributions.R 2010-08-26 12:48:48 UTC (rev 675)
+++ branches/distr-2.3/pkg/distr/R/UtilitiesDistributions.R 2010-09-03 01:53:29 UTC (rev 676)
@@ -25,8 +25,8 @@
## density should use DefaultNrGridPoints equally spaced points for evaluation
RtoDPQ <- function(r, e = getdistrOption("RtoDPQ.e"),
- n = getdistrOption("DefaultNrGridPoints")){
- zz <- r(10^e)
+ n = getdistrOption("DefaultNrGridPoints"), y = NULL){
+ zz <- if(!is.null(y)) y else r(10^e)
zz <- zz[!is.na(zz)]
dxy <- xy.coords(density(zz, n = n))
@@ -72,8 +72,9 @@
### new from 2.0:
RtoDPQ.LC <- function(r, e = getdistrOption("RtoDPQ.e"),
- n = getdistrOption("DefaultNrGridPoints")){
- zz <- r(10^e)
+ n = getdistrOption("DefaultNrGridPoints"), y = NULL){
+
+ zz <- if(!is.null(y)) y else r(10^e)
hasDis <- FALSE
zz.nr <- zz
Modified: branches/distr-2.3/pkg/distr/R/internalUtils.R
===================================================================
--- branches/distr-2.3/pkg/distr/R/internalUtils.R 2010-08-26 12:48:48 UTC (rev 675)
+++ branches/distr-2.3/pkg/distr/R/internalUtils.R 2010-09-03 01:53:29 UTC (rev 676)
@@ -1137,3 +1137,6 @@
# newDistribution <- DiscreteDistribution(supp=supp,prob=prob)
# return(newDistribution)
}
+
+
+
\ No newline at end of file
Modified: branches/distr-2.3/pkg/distr/man/RtoDPQ.LC.Rd
===================================================================
--- branches/distr-2.3/pkg/distr/man/RtoDPQ.LC.Rd 2010-08-26 12:48:48 UTC (rev 675)
+++ branches/distr-2.3/pkg/distr/man/RtoDPQ.LC.Rd 2010-09-03 01:53:29 UTC (rev 676)
@@ -4,18 +4,25 @@
\description{
function to do get empirical density, cumulative distribution and quantile function from random numbers}
\usage{
-RtoDPQ.LC(r, e = getdistrOption("RtoDPQ.e"), n = getdistrOption("DefaultNrGridPoints"))
+RtoDPQ.LC(r, e = getdistrOption("RtoDPQ.e"), n = getdistrOption("DefaultNrGridPoints"), y = NULL)
}
\arguments{
\item{r}{ the random number generator }
\item{e}{ \eqn{10^e} numbers are generated, a higher number leads to a better result. }
\item{n}{ The number of grid points used to create the approximated functions, a higher number leads to a better result.}
+ \item{y}{a (numeric) vector or \code{NULL}}
}
\details{
RtoDPQ.LC generates \eqn{10^e} random numbers, by default \deqn{e = RtoDPQ.e}.
Replicates are assumed to be part of the discrete part, unique values to be
part of the a.c. part of the distribution. For the replicated ones,
we generate a discrete distribution by a call to \code{\link{DiscreteDistribution}}.
+
+For the a.c. part, similarly to \code{\link{RtoDPQ}} we have an optional parameter \code{y}
+for using N. Horbenko's quantile trick: i.e.; on an equally spaced grid \code{x.grid} on [0,1], apply
+\code{f(q(x)(x.grid))}, write the result to \code{y} and use these
+values instead of simulated ones.
+
The a.c. density is formed on the basis of \eqn{n}
points using approxfun and density (applied to the unique values), by default \deqn{n = DefaultNrGridPoints}.
The cumulative distribution function is based on all random variables,
Modified: branches/distr-2.3/pkg/distr/man/RtoDPQ.Rd
===================================================================
--- branches/distr-2.3/pkg/distr/man/RtoDPQ.Rd 2010-08-26 12:48:48 UTC (rev 675)
+++ branches/distr-2.3/pkg/distr/man/RtoDPQ.Rd 2010-09-03 01:53:29 UTC (rev 676)
@@ -4,15 +4,22 @@
\description{
function to do get empirical density, cumulative distribution and quantile function from random numbers}
\usage{
-RtoDPQ(r, e = getdistrOption("RtoDPQ.e"), n = getdistrOption("DefaultNrGridPoints"))
+RtoDPQ(r, e = getdistrOption("RtoDPQ.e"), n = getdistrOption("DefaultNrGridPoints"), y = NULL)
}
\arguments{
\item{r}{ the random number generator }
\item{e}{ \eqn{10^e} numbers are generated, a higher number leads to a better result. }
\item{n}{ The number of grid points used to create the approximated functions, a higher number leads to a better result.}
+ \item{y}{a (numeric) vector or \code{NULL}}
}
\details{
-RtoDPQ generates \eqn{10^e} random numbers, by default \deqn{e = RtoDPQ.e}. The density is formed on the basis of \eqn{n}
+RtoDPQ generates \eqn{10^e} random numbers, by default \deqn{e = RtoDPQ.e}.
+Instead of using simulated grid points, we have an optional parameter \code{y}
+for using N. Horbenko's quantile trick: i.e.; on an equally spaced grid \code{x.grid} on [0,1], apply
+\code{f(q(x)(x.grid))} and write the result to \code{y} and produce density and cdf from this
+value \code{y} given to \code{RtoDPQ} as argument (instead of simulating grid points).
+
+The density is formed on the basis of \eqn{n}
points using approxfun and density, by default \deqn{n = DefaultNrGridPoints}.
The cumulative distribution function and the quantile function are also created on the basis of \eqn{n} points using
\code{approxfun} and \code{ecdf}. Of course, the results are usually not exact as they rely on random numbers.}
Modified: branches/distr-2.3/pkg/distr/man/UnivarLebDecDistribution.Rd
===================================================================
--- branches/distr-2.3/pkg/distr/man/UnivarLebDecDistribution.Rd 2010-08-26 12:48:48 UTC (rev 675)
+++ branches/distr-2.3/pkg/distr/man/UnivarLebDecDistribution.Rd 2010-09-03 01:53:29 UTC (rev 676)
@@ -5,7 +5,7 @@
\description{Generates an object of class \code{"UnivarLebDecDistribution"}.}
\usage{
UnivarLebDecDistribution(acPart, discretePart, acWeight, discreteWeight,
- r = NULL, e = NULL, n = NULL)
+ r = NULL, e = NULL, n = NULL, y = NULL)
}
\arguments{
\item{acPart}{Object of class \code{"AbscontDistribution"} (or subclasses);
@@ -26,14 +26,21 @@
\item{n}{optional argument; if argument \code{r} is given, this is the number
gridpoints used in filling the empty p,d,q slots of this object; if missing filled
with \code{getdistrOption("DefaultNrGridPoints")}.}
+ \item{y}{a (numeric) vector or \code{NULL}}
}
\details{At least one of arguments \code{discretePart}, \code{acPart}, or \code{r}
must be given; if the first two are missing, slots are filled by a call
- to \code{RtoDPQ.LV}. For this purpose argument \code{r} is used together
+ to \code{RtoDPQ.LC}. For this purpose argument \code{r} is used together
with arguments \code{e} and \code{n}. If the latter are missing they are
filled with \code{getdistrOption("RtoDPQ.e")} and
\code{getdistrOption("DefaultNrGridPoints")}, respectively.
+ For the a.c. part, similarly to \code{\link{RtoDPQ}} we have an optional
+ parameter \code{y} for using N. Horbenko's quantile trick: i.e.; on an
+ equally spaced grid \code{x.grid} on [0,1], apply
+ \code{f(q(x)(x.grid))}, write the result to \code{y} and use these
+ values instead of simulated ones.
+
If argument \code{discretePart} is missing but \code{acPart} is not,
\code{discreteWeight} is set to 0 and \code{discretePart} is set to \code{Dirac(0)}.
If argument \code{acPart} is missing but \code{discretePart} is not,
Modified: branches/distr-2.3/pkg/distr/man/igamma.Rd
===================================================================
--- branches/distr-2.3/pkg/distr/man/igamma.Rd 2010-08-26 12:48:48 UTC (rev 675)
+++ branches/distr-2.3/pkg/distr/man/igamma.Rd 2010-09-03 01:53:29 UTC (rev 676)
@@ -6,10 +6,10 @@
Function \code{igamma} is a numerical inverse of \code{digamma}.
}
\usage{
-igamma(x)
+igamma(v)
}
\arguments{
- \item{x}{ a numeric in the range [-100000,18] }
+ \item{v}{ a numeric in the range [-100000,18] }
}
\details{
\code{igamma} is vectorized; it is won
More information about the Distr-commits
mailing list