R Under development (unstable) (2026-02-10 r89394 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 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. > options(digits=12) > if(!require("BB"))stop("this test requires package BB.") Loading required package: BB > if(!require("setRNG"))stop("this test requires setRNG.") Loading required package: setRNG > > # Use a preset seed so test values are reproducable. > test.rng <- list(kind="Wichmann-Hill", normal.kind="Box-Muller", seed=c(979,1479,1542)) > old.seed <- setRNG(test.rng) > > > ############################################################### > cat("BB test poissmix.loglik ...\n") BB test poissmix.loglik ... > > # Use a preset seed so test values are reproducable. > test.rng <- list(kind="Wichmann-Hill", normal.kind="Box-Muller", seed=c(979,1479,1542)) > old.seed <- setRNG(test.rng) > > poissmix.loglik <- function(p,y) { + i <- 0:(length(y)-1) + loglik <- y*log(p[1]*exp(-p[2])*p[2]^i/exp(lgamma(i+1)) + + (1 - p[1])*exp(-p[3])*p[3]^i/exp(lgamma(i+1))) + return ( -sum(loglik) ) + } > > #################### > > # Real data from Hasselblad (JASA 1969) > poissmix.dat <- data.frame(death=0:9, freq=c(162,267,271,185,111,61,27,8,3,1)) > > lo <- c(0.001,0,0) > hi <- c(0.999, Inf, Inf) > > y <- poissmix.dat$freq > p <- runif(3,c(0.3,1,1),c(0.7,5,8)) > system.time(ans.spg <- spg(par=p, fn=poissmix.loglik, y=y, + projectArgs=list(lower=lo, upper=hi), + control=list(maxit=2500, M=20)))[1] iter: 0 f-value: 2184.66313697 pgrad: 304.651316583 iter: 10 f-value: 1990.41389535 pgrad: 4.21838194598 iter: 20 f-value: 1991.46363999 pgrad: 34.7670061274 iter: 30 f-value: 1989.94686781 pgrad: 0.0752197593101 iter: 40 f-value: 1989.94605997 pgrad: 0.565703430766 iter: 50 f-value: 1989.94586872 pgrad: 0.00599584382144 iter: 60 f-value: 1989.94587446 pgrad: 0.16028252503 iter: 70 f-value: 1989.9458601 pgrad: 0.00110503606265 iter: 80 f-value: 1989.94586013 pgrad: 0.00670979716233 user.self 0.03 > > z <- sum(ans.spg$par) > good <- 4.55961554279947 > #on Windows > #on Linux64 4.55961554279947 > #on Linux32 4.559616090962986 > print(z, digits=16) [1] 4.55962421015194 > if(any(abs(good - z) > 1e-4)) stop("BB test poissmix.loglik a FAILED") > > > proc.time() user system elapsed 0.18 0.03 0.20