tests/testthat/test-emplik.R

UNITEST_el.cen.EM <- function(){
    x <- c(1, 1.5, 2, 3, 4, 5, 6, 5, 4, 1, 2, 4.5)
    d <- c(1,   1, 0, 1, 0, 1, 1, 1, 1, 0, 0,   1)
    result = el.cen.EM(x,d,mu=3.5)
    return(sprintf('%0.5f', result[["lam"]][1]));

}

UNITEST_findUL <- function(){
     x <- c(1, 1.5, 2, 3, 4, 5, 6, 5, 4, 1, 2, 4.5)
     d <- c(1,   1, 0, 1, 0, 1, 1, 1, 1, 0, 0,  1)
     myfun6 <- function(theta, x, d) {
     el.cen.EM2(x, d, fun=function(t){t}, mu=theta)
     }
    result = findUL(step=0.2, fun=myfun6, MLE=4.0659, x=x, d=d)
    return(sprintf('%0.5f', result[["Low"]][1]));
}

UNITEST_el.cen.kmc1d <- function(){
     x <- c(1, 1.5, 2, 3, 4.2, 5, 6.1, 5.3, 4.5, 0.9, 2.1, 4.3)
     d <- c(1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1)
     ff <- function(x) {
         x - 3.7
     }
     
    result = el.cen.kmc1d(x=x, d=d, fun=ff, mu=0)
    return(sprintf('%0.5f', result[["-2LLR"]][1]));
}



test_that("emplik works", {
  expect_equal(UNITEST_el.cen.EM(), "2.11514");
  expect_equal(UNITEST_findUL(), "3.04973");
  expect_equal(UNITEST_el.cen.kmc1d(), "0.61496")
  
})

Try the emplik package in your browser

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

emplik documentation built on Sept. 8, 2023, 5:06 p.m.