getEdges: Calculate Histogram Edges

Description Usage Arguments Examples

Description

This is an internal function. The user may not use it.

Usage

1

Arguments

z

a grid a scalar, usually created by z = arma::linspace<arma::vec>(z0, z1, 1<<(int)p);

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
set.seed(123)
dat1 <- stats::rnorm(1e2)
h  <- bw.nrd0(dat1)
z0 <- min(dat1) - 3*h 
z1 <- max(dat1) + 3*h
ngrid <- 2^10
dt <- (z1 - z0) / (ngrid - 1)
z  <- z0 + (0:(ngrid-1)) * dt
## Same as using seq function
## seq(z0, z1, length.out=ngrid)

binedge1 <- c(z - 0.5*dt, z[ngrid] + 0.5*dt)
binedge2 <- as.vector(cpda::getEdges(z))
all.equal(binedge1, binedge2)
mean(binedge - as.vector(tmp))
## [1] 2.640334e-17

## 4.00 vs. 14.1 microseconds
## library(microbenchmark)
## res <- microbenchmark(
##    binedge1 <- c(z - 0.5*dt, z[ngrid] + 0.5*dt),
##    binedge2 <- as.vector(cpda::getEdges(z)),
##   times=10L)

TasCL/cpda documentation built on May 3, 2019, 11:48 p.m.