R Under development (unstable) (2023-12-13 r85679 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > library(aster) > > alpha <- 2.222 > ifam <- fam.negative.binomial(alpha) > > ##### usual size theta ##### > > p <- seq(0.9, 0.1, -0.1) > theta <- log(1 - p) > qq <- exp(theta) > pp <- (- expm1(theta)) > all.equal(p, pp) [1] TRUE > all.equal(pp, 1 - qq) [1] TRUE > > zeroth <- double(length(theta)) > first <- double(length(theta)) > second <- double(length(theta)) > > for (i in seq(along = theta)) { + zeroth[i] <- famfun(ifam, 0, theta[i]) + first[i] <- famfun(ifam, 1, theta[i]) + second[i] <- famfun(ifam, 2, theta[i]) + } > > all.equal(zeroth, alpha * (- log(pp))) [1] TRUE > all.equal(first, alpha * qq / pp) [1] TRUE > all.equal(second, alpha * qq / pp^2) [1] TRUE > > ##### very large negative theta ##### > > rm(p) > > theta <- seq(-100, -10, 10) > qq <- exp(theta) > pp <- (- expm1(theta)) > > zeroth <- double(length(theta)) > first <- double(length(theta)) > second <- double(length(theta)) > > for (i in seq(along = theta)) { + zeroth[i] <- famfun(ifam, 0, theta[i]) + first[i] <- famfun(ifam, 1, theta[i]) + second[i] <- famfun(ifam, 2, theta[i]) + } > > all.equal(zeroth, alpha * (- log(pp))) [1] TRUE > all.equal(first, alpha * qq / pp) [1] TRUE > all.equal(second, alpha * qq / pp^2) [1] TRUE > > ##### very small negative theta ##### > > theta <- (- 10^(- c(1:9, seq(10, 100, 10)))) > qq <- exp(theta) > pp <- (- expm1(theta)) > > zeroth <- double(length(theta)) > first <- double(length(theta)) > second <- double(length(theta)) > > for (i in seq(along = theta)) { + zeroth[i] <- famfun(ifam, 0, theta[i]) + first[i] <- famfun(ifam, 1, theta[i]) + second[i] <- famfun(ifam, 2, theta[i]) + } > > all.equal(zeroth, alpha * (- log(pp))) [1] TRUE > all.equal(first, alpha * qq / pp) [1] TRUE > all.equal(second, alpha * qq / pp^2) [1] TRUE > > ##### random ##### > > nind <- 50 > theta <- rep(- 1.75, nind) > pred <- 0 > fam <- 1 > root <- seq(1, by = 0.5, length = nind) > theta <- cbind(theta) > root <- cbind(root) > > set.seed(42) > rout <- raster(theta, pred, fam, root, famlist = list(ifam)) > > set.seed(42) > rout.too <- rnbinom(nind, size = alpha * as.numeric(root), + prob = as.numeric(1 - exp(theta))) > > all.equal(as.numeric(rout), rout.too) [1] TRUE > > > > > proc.time() user system elapsed 0.17 0.03 0.20