Skip to contents

Statistical functions on DelayedArray objects.

All these functions are implemented as delayed operations.

Usage

## --- The Normal Distribution ----- ##

# S4 method for class 'DelayedArray'
dnorm(x, mean=0, sd=1, log=FALSE)
# S4 method for class 'DelayedArray'
pnorm(q, mean=0, sd=1, lower.tail=TRUE, log.p=FALSE)
# S4 method for class 'DelayedArray'
qnorm(p, mean=0, sd=1, lower.tail=TRUE, log.p=FALSE)

## --- The Binomial Distribution --- ##

# S4 method for class 'DelayedArray'
dbinom(x, size, prob, log=FALSE)
# S4 method for class 'DelayedArray'
pbinom(q, size, prob, lower.tail=TRUE, log.p=FALSE)
# S4 method for class 'DelayedArray'
qbinom(p, size, prob, lower.tail=TRUE, log.p=FALSE)

## --- The Poisson Distribution ---- ##

# S4 method for class 'DelayedArray'
dpois(x, lambda, log=FALSE)
# S4 method for class 'DelayedArray'
ppois(q, lambda, lower.tail=TRUE, log.p=FALSE)
# S4 method for class 'DelayedArray'
qpois(p, lambda, lower.tail=TRUE, log.p=FALSE)

## --- The Logistic Distribution --- ##

# S4 method for class 'DelayedArray'
dlogis(x, location=0, scale=1, log=FALSE)
# S4 method for class 'DelayedArray'
plogis(q, location=0, scale=1, lower.tail=TRUE, log.p=FALSE)
# S4 method for class 'DelayedArray'
qlogis(p, location=0, scale=1, lower.tail=TRUE, log.p=FALSE)

Arguments

x, q, p

A DelayedArray object.

mean, sd, log, lower.tail, log.p, size, prob, lambda, location, scale

See ?stats::dnorm, ?stats::dbinom, ?stats::dpois, and ?stats::dlogis, for a description of these arguments.

See also

Examples

a <- array(4 * runif(1500000), dim=c(10000, 30, 5))
A <- DelayedArray(a)
A
#> <10000 x 30 x 5> DelayedArray object of type "double":
#> ,,1
#>               [,1]      [,2]      [,3] ...     [,29]     [,30]
#>     [1,] 1.5362024 0.5469866 0.4568076   .  2.989484  1.154675
#>     [2,] 1.4667852 3.0881905 2.5484856   .  2.396961  2.964511
#>      ...         .         .         .   .         .         .
#>  [9999,] 2.3608315 0.3523233 2.6614124   . 2.2095511 0.6253608
#> [10000,] 0.7640061 1.3176988 1.0634373   . 3.7438542 3.3837529
#> 
#> ...
#> 
#> ,,5
#>                [,1]       [,2]       [,3] ...    [,29]    [,30]
#>     [1,]  0.2095795  2.6088468  1.2385747   . 1.448729 3.979290
#>     [2,]  1.0263017  3.8875009  1.7752993   . 2.298936 3.398998
#>      ...          .          .          .   .        .        .
#>  [9999,] 3.95198534 0.09517774 2.27268694   . 2.924414 3.040567
#> [10000,] 1.83268908 1.57885293 3.50798213   . 1.162985 1.851037
#> 

A2 <- dnorm(A + 1)[ , , -3]  # very fast! (operations are delayed)
A2
#> <10000 x 30 x 4> DelayedArray object of type "double":
#> ,,1
#>                  [,1]         [,2]         [,3] ...        [,29]        [,30]
#>     [1,] 0.0160010657 0.1205703047 0.1380578176   . 0.0001395723 0.0391540378
#>     [2,] 0.0190354315 0.0000936834 0.0007356078   . 0.0012450100 0.0001541456
#>      ...            .            .            .   .            .            .
#>  [9999,] 0.0014066664 0.1598806389 0.0004896063   . 2.312219e-03 1.064758e-01
#> [10000,] 0.0841800589 0.0271928185 0.0474620320   . 5.178399e-06 2.678728e-05
#> 
#> ...
#> 
#> ,,4
#>                  [,1]         [,2]         [,3] ...        [,29]        [,30]
#>     [1,] 1.919578e-01 5.926976e-04 3.256403e-02   . 1.989921e-02 1.648571e-06
#>     [2,] 5.120655e-02 2.592802e-06 8.479687e-03   . 1.728627e-03 2.505267e-05
#>      ...            .            .            .   .            .            .
#>  [9999,] 1.887952e-06 2.190083e-01 1.884338e-03   . 0.0001805595 0.0001136906
#> [10000,] 7.219264e-03 1.434750e-02 1.541931e-05   . 0.0384579499 0.0068524789
#> 

a2 <- as.array(A2)           # "realize" 'A2' in memory (as an ordinary
                             # array)

DelayedArray(a2) == A2       # DelayedArray object of type "logical"
#> <10000 x 30 x 4> DelayedArray object of type "logical":
#> ,,1
#>           [,1]  [,2]  [,3] ... [,29] [,30]
#>     [1,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#>     [2,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#>      ...     .     .     .   .     .     .
#>  [9999,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#> [10000,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#> 
#> ...
#> 
#> ,,4
#>           [,1]  [,2]  [,3] ... [,29] [,30]
#>     [1,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#>     [2,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#>      ...     .     .     .   .     .     .
#>  [9999,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#> [10000,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#> 
stopifnot(all(DelayedArray(a2) == A2))


library(HDF5Array)
A3 <- as(A2, "HDF5Array")    # "realize" 'A2' on disk (as an HDF5Array
                             # object)

A3 == A2                     # DelayedArray object of type "logical"
#> <10000 x 30 x 4> DelayedArray object of type "logical":
#> ,,1
#>           [,1]  [,2]  [,3] ... [,29] [,30]
#>     [1,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#>     [2,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#>      ...     .     .     .   .     .     .
#>  [9999,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#> [10000,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#> 
#> ...
#> 
#> ,,4
#>           [,1]  [,2]  [,3] ... [,29] [,30]
#>     [1,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#>     [2,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#>      ...     .     .     .   .     .     .
#>  [9999,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#> [10000,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
#> 
stopifnot(all(A3 == A2))

## See '?DelayedArray' for general information about DelayedArray objects
## and their "realization".