tests/testthat/test-newton.R

library(Temporal)
library(testthat)

test_that("Check Newton-Raphson maximization.", {
  
  # Normal density.
  f <- function(x){return(stats::dnorm(x, log = TRUE))}
  fit <- NewtonRaphson(init = 1, obj = f)
  expect_equal(fit, 0, tolerance = 1e-6)
  
  # Chi-squared density.
  f <- function(x){return(stats::dchisq(x, df = 3, log = TRUE))}
  fit <- NewtonRaphson(init = 0.2, obj = f)
  expect_equal(fit, 1, tolerance = 1e-6)
  
})

Try the Temporal package in your browser

Any scripts or data that you put into this service are public.

Temporal documentation built on Sept. 24, 2023, 1:06 a.m.