Last updated on 2019-11-26 00:51:57 CET.
Flavor | Version | Tinstall | Tcheck | Ttotal | Status | Flags |
---|---|---|---|---|---|---|
r-devel-linux-x86_64-debian-clang | 1.3-6 | 7.37 | 48.38 | 55.75 | ERROR | |
r-devel-linux-x86_64-debian-gcc | 1.3-6 | 4.93 | 37.00 | 41.93 | ERROR | |
r-devel-linux-x86_64-fedora-clang | 1.3-6 | 62.85 | OK | |||
r-devel-linux-x86_64-fedora-gcc | 1.3-6 | 60.82 | OK | |||
r-devel-windows-ix86+x86_64 | 1.3-6 | 16.00 | 77.00 | 93.00 | OK | |
r-devel-windows-ix86+x86_64-gcc8 | 1.3-6 | 16.00 | 60.00 | 76.00 | OK | |
r-patched-linux-x86_64 | 1.3-6 | 5.70 | 45.50 | 51.20 | OK | |
r-patched-solaris-x86 | 1.3-6 | 81.00 | OK | |||
r-release-linux-x86_64 | 1.3-6 | 5.94 | 46.14 | 52.08 | OK | |
r-release-windows-ix86+x86_64 | 1.3-6 | 11.00 | 59.00 | 70.00 | OK | |
r-release-osx-x86_64 | 1.3-6 | OK | ||||
r-oldrel-windows-ix86+x86_64 | 1.3-6 | 7.00 | 71.00 | 78.00 | OK | |
r-oldrel-osx-x86_64 | 1.3-6 | OK |
Version: 1.3-6
Check: tests
Result: ERROR
Running 'BFGSR.R' [1s/1s]
Comparing 'BFGSR.Rout' to 'BFGSR.Rout.save' ... OK
Running 'basicTest.R' [1s/2s]
Running 'constraints.R' [4s/5s]
Comparing 'constraints.Rout' to 'constraints.Rout.save' ... OK
Running 'finalHessian.R' [1s/1s]
Comparing 'finalHessian.Rout' to 'finalHessian.Rout.save' ... OK
Running 'methods.R' [2s/3s]
Comparing 'methods.Rout' to 'methods.Rout.save' ... OK
Running 'numericGradient.R' [1s/1s]
Comparing 'numericGradient.Rout' to 'numericGradient.Rout.save' ... OK
Running the tests in 'tests/basicTest.R' failed.
Complete output:
> ### general optimization tests for the functions of various forms
> ### test for:
> ### 1. numeric gradient, Hessian
> ### 2. analytic gradient, numeric Hessian
> ### 3. analytic gradient, Hessian
> ###
> ### a) maxLik(, method="NR")
> ### c) maxLik(, method="BFGS")
> ### b) maxLik(, method="BHHH")
> ###
> ### i) maxNR()
> ### ii) maxBFGS()
>
> library(maxLik)
Loading required package: miscTools
Please cite the 'maxLik' package as:
Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihood estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.
If you have questions, suggestions, or comments regarding the 'maxLik' package, please use a forum or 'tracker' at maxLik's R-Forge site:
https://r-forge.r-project.org/projects/maxlik/
> library(testthat)
>
> # log-likelihood function(s)
> logLL <- function(x, X) # per observation for maxLik
+ dgamma(x = X, shape = x[1], scale = x[2], log = TRUE)
> logLLSum <- function(x, X)
+ sum(logLL(x, X))
>
> # gradient of log-likelihood function
> d.logLL <- function(x, X){ # analytic 1. derivatives
+ shape <- x[1]
+ scale <- x[2]
+ cbind(shape= log(X) - log(scale) - psigamma(shape, 0),
+ scale= (X/scale - shape)/scale
+ )
+ }
> d.logLLSum <- function(x, X) {
+ ## analytic 1. derivatives, summed
+ colSums(d.logLL(x, X))
+ }
>
> ## Hessian of log-likelihood function
> dd.logLL <- function(x, X){ # analytic 2. derivatives
+ shape <- x[1]
+ scale <- x[2]
+ hessian <- matrix(0, 2, 2)
+ hessian[1,1] <- -psigamma(shape, 1)*length(X)
+ hessian[2,2] <- (shape*length(X) - 2*sum(X)/scale)/scale^2
+ hessian[cbind(c(2,1), c(1,2))] <- -length(X)/scale
+ return(hessian)
+ }
>
> ## create data
> ## sample size 1000 should give precision 0.1 or better
> param <- c(1.5, 2)
> set.seed(100)
> someData <- rgamma(1000, shape=param[1], scale=param[2])
> start <- c(1,1)
> mTol <- .Machine$double.eps^0.25
>
> ## estimation with maxLik() / NR
> doTests <- function(method="NR") {
+ suppressWarnings(rLLSum <- maxLik( logLLSum, start=start, method=method, X=someData ))
+ stdDev <- stdEr(rLLSum)
+ tol <- 2*max(stdDev)
+ expect_equal(coef(rLLSum), param, tolerance=tol,
+ info=paste("coefficient values should be close to the true values", paste(param, collapse=", ")))
+ # should equal to param, but as N is small, it may be way off
+ ##
+ rLL <- suppressWarnings(maxLik( logLL, start = start, method=method, X=someData ))
+ expect_equal(coef(rLL), coef(rLLSum), tolerance=mTol)
+ ##
+ rLLSumGSum <- suppressWarnings(maxLik( logLLSum, grad=d.logLLSum, start = start, method=method, X=someData ))
+ expect_equal(coef(rLLSumGSum), coef(rLLSum), tolerance=mTol)
+ rLLG <- suppressWarnings(maxLik( logLL, grad=d.logLL, start = start, method=method, X=someData ))
+ expect_equal(coef(rLLG), coef(rLLSum), tolerance=mTol)
+ rLLGH <- suppressWarnings(maxLik( logLL, grad=d.logLL, hess=dd.logLL, start = start, method=method, X=someData ))
+ expect_equal(coef(rLLGH), coef(rLLSum), tolerance=mTol)
+ }
>
> doTests("NR")
> doTests("BFGS")
> ## maxBHHH: cannot run the same tests
> method <- "BHHH"
> tryCatch(maxLik( logLLSum, start=start, method=method, X=someData ),
+ error = function(e) cat(as.character(e))
+ # should output error about gradient size
+ )
Error in checkBhhhGrad(g = gr, theta = theta, analytic = (!is.null(attr(f, : if the gradients (argument 'grad') are not provided by the user, the BHHH method requires that the log-likelihood function (argument 'fn') returns a numeric vector, where each element must be the log-likelihood value corresponding to an individual (independent) observation
> rLL <- suppressWarnings(maxLik( logLL, start = start, method=method, X=someData ))
> stdDev <- stdEr(rLL)
> tol <- 2*max(stdDev)
> expect_equal(coef(rLL), param, tolerance=tol,
+ info=paste("coefficient values should be close to the true values", paste(param, collapse=", ")))
> # should equal to param, but as N is small, it may be way off
> ##
> rLLG <- suppressWarnings(maxLik( logLL, grad=d.logLL, start = start, method=method, X=someData ))
> expect_equal(coef(rLLG), coef(rLL), tolerance=mTol)
>
> ## Do the other basic functions work?
> expect_equal(class(logLik(rLL)), "numeric")
> expect_equal(class(gradient(rLL)), "numeric")
> expect_equal(class(hessian(rLL)), "matrix")
Error: class(hessian(rLL)) not equal to "matrix".
Lengths differ: 2 is not 1
Execution halted
Flavor: r-devel-linux-x86_64-debian-clang
Version: 1.3-6
Check: tests
Result: ERROR
Running ‘BFGSR.R’ [1s/1s]
Comparing ‘BFGSR.Rout’ to ‘BFGSR.Rout.save’ ... OK
Running ‘basicTest.R’ [1s/1s]
Running ‘constraints.R’ [3s/4s]
Comparing ‘constraints.Rout’ to ‘constraints.Rout.save’ ... OK
Running ‘finalHessian.R’ [1s/1s]
Comparing ‘finalHessian.Rout’ to ‘finalHessian.Rout.save’ ... OK
Running ‘methods.R’ [1s/2s]
Comparing ‘methods.Rout’ to ‘methods.Rout.save’ ... OK
Running ‘numericGradient.R’ [0s/1s]
Comparing ‘numericGradient.Rout’ to ‘numericGradient.Rout.save’ ... OK
Running the tests in ‘tests/basicTest.R’ failed.
Complete output:
> ### general optimization tests for the functions of various forms
> ### test for:
> ### 1. numeric gradient, Hessian
> ### 2. analytic gradient, numeric Hessian
> ### 3. analytic gradient, Hessian
> ###
> ### a) maxLik(, method="NR")
> ### c) maxLik(, method="BFGS")
> ### b) maxLik(, method="BHHH")
> ###
> ### i) maxNR()
> ### ii) maxBFGS()
>
> library(maxLik)
Loading required package: miscTools
Please cite the 'maxLik' package as:
Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihood estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.
If you have questions, suggestions, or comments regarding the 'maxLik' package, please use a forum or 'tracker' at maxLik's R-Forge site:
https://r-forge.r-project.org/projects/maxlik/
> library(testthat)
>
> # log-likelihood function(s)
> logLL <- function(x, X) # per observation for maxLik
+ dgamma(x = X, shape = x[1], scale = x[2], log = TRUE)
> logLLSum <- function(x, X)
+ sum(logLL(x, X))
>
> # gradient of log-likelihood function
> d.logLL <- function(x, X){ # analytic 1. derivatives
+ shape <- x[1]
+ scale <- x[2]
+ cbind(shape= log(X) - log(scale) - psigamma(shape, 0),
+ scale= (X/scale - shape)/scale
+ )
+ }
> d.logLLSum <- function(x, X) {
+ ## analytic 1. derivatives, summed
+ colSums(d.logLL(x, X))
+ }
>
> ## Hessian of log-likelihood function
> dd.logLL <- function(x, X){ # analytic 2. derivatives
+ shape <- x[1]
+ scale <- x[2]
+ hessian <- matrix(0, 2, 2)
+ hessian[1,1] <- -psigamma(shape, 1)*length(X)
+ hessian[2,2] <- (shape*length(X) - 2*sum(X)/scale)/scale^2
+ hessian[cbind(c(2,1), c(1,2))] <- -length(X)/scale
+ return(hessian)
+ }
>
> ## create data
> ## sample size 1000 should give precision 0.1 or better
> param <- c(1.5, 2)
> set.seed(100)
> someData <- rgamma(1000, shape=param[1], scale=param[2])
> start <- c(1,1)
> mTol <- .Machine$double.eps^0.25
>
> ## estimation with maxLik() / NR
> doTests <- function(method="NR") {
+ suppressWarnings(rLLSum <- maxLik( logLLSum, start=start, method=method, X=someData ))
+ stdDev <- stdEr(rLLSum)
+ tol <- 2*max(stdDev)
+ expect_equal(coef(rLLSum), param, tolerance=tol,
+ info=paste("coefficient values should be close to the true values", paste(param, collapse=", ")))
+ # should equal to param, but as N is small, it may be way off
+ ##
+ rLL <- suppressWarnings(maxLik( logLL, start = start, method=method, X=someData ))
+ expect_equal(coef(rLL), coef(rLLSum), tolerance=mTol)
+ ##
+ rLLSumGSum <- suppressWarnings(maxLik( logLLSum, grad=d.logLLSum, start = start, method=method, X=someData ))
+ expect_equal(coef(rLLSumGSum), coef(rLLSum), tolerance=mTol)
+ rLLG <- suppressWarnings(maxLik( logLL, grad=d.logLL, start = start, method=method, X=someData ))
+ expect_equal(coef(rLLG), coef(rLLSum), tolerance=mTol)
+ rLLGH <- suppressWarnings(maxLik( logLL, grad=d.logLL, hess=dd.logLL, start = start, method=method, X=someData ))
+ expect_equal(coef(rLLGH), coef(rLLSum), tolerance=mTol)
+ }
>
> doTests("NR")
> doTests("BFGS")
> ## maxBHHH: cannot run the same tests
> method <- "BHHH"
> tryCatch(maxLik( logLLSum, start=start, method=method, X=someData ),
+ error = function(e) cat(as.character(e))
+ # should output error about gradient size
+ )
Error in checkBhhhGrad(g = gr, theta = theta, analytic = (!is.null(attr(f, : if the gradients (argument 'grad') are not provided by the user, the BHHH method requires that the log-likelihood function (argument 'fn') returns a numeric vector, where each element must be the log-likelihood value corresponding to an individual (independent) observation
> rLL <- suppressWarnings(maxLik( logLL, start = start, method=method, X=someData ))
> stdDev <- stdEr(rLL)
> tol <- 2*max(stdDev)
> expect_equal(coef(rLL), param, tolerance=tol,
+ info=paste("coefficient values should be close to the true values", paste(param, collapse=", ")))
> # should equal to param, but as N is small, it may be way off
> ##
> rLLG <- suppressWarnings(maxLik( logLL, grad=d.logLL, start = start, method=method, X=someData ))
> expect_equal(coef(rLLG), coef(rLL), tolerance=mTol)
>
> ## Do the other basic functions work?
> expect_equal(class(logLik(rLL)), "numeric")
> expect_equal(class(gradient(rLL)), "numeric")
> expect_equal(class(hessian(rLL)), "matrix")
Error: class(hessian(rLL)) not equal to "matrix".
Lengths differ: 2 is not 1
Execution halted
Flavor: r-devel-linux-x86_64-debian-gcc