# Testing the GL functions
# Problem: fitting functions for GL do not return the standard error
# So the 95% confidence interval was replaced by +-20% accuracy
param <- c(45, 2.5) # Approximate parameters taken from the fit of the Narsjo "2.11" station data
CI <- 2 # +-2 times the Std_error to get 95% confidence interval
random_distrib <- rlogis(1000, param[1],param[2])
####
test <- logist_mle(random_distrib)
test_that("gl_mle return list of correct length", {
expect_length(test$estimate, 2)
expect_length(test$se, 2)
})
test_that("gl_mle returns reasonable estimates", {
# expected_min <- param * (1 - CI * test$se)
# expected_max <- param * (1 + CI * test$se)
expected_min <- param * (1 - 0.2)
expected_max <- param * (1 + 0.2)
expect_true(test$estimate[1] < expected_max[1] && test$estimate[1] > expected_min[1])
expect_true(test$estimate[2] < expected_max[2] && test$estimate[2] > expected_min[2])
# There is aproblem with the 3rd parameter returned by gl_mle which is 0.1 instead of -0.3
# Warning: Maybe a different distribution formulation?
# expect_true(test$estimate[3] < expected_min[3] && test$estimate[3] > expected_max[3]) # Test is the other way around because param is < 0
})
####
test <- logist_Lmom(random_distrib)
test_that("gl_Lmom return list of correct length", {
expect_length(test$estimate, 2)
expect_length(test$se, 2)
})
test_that("gl_Lmom returns reasonable estimates", {
# expected_min <- param * (1 - CI * test$se)
# expected_max <- param * (1 + CI * test$se)
expected_min <- param * (1 - 0.2)
expected_max <- param * (1 + 0.2)
expect_true(test$estimate[1] < expected_max[1] && test$estimate[1] > expected_min[1])
expect_true(test$estimate[2] < expected_max[2] && test$estimate[2] > expected_min[2])
# expect_true(test$estimate[3] < expected_min[3] && test$estimate[3] > expected_max[3]) # Test is the other way around because param is < 0
})
####
test <- logist_mom(random_distrib)
test_that("gl_mom return list of correct length", {
expect_length(test$estimate, 2)
expect_length(test$se, 2)
})
test_that("gl_mom returns reasonable estimates", {
# expected_min <- param * (1 - CI * test$se)
# expected_max <- param * (1 + CI * test$se)
expected_min <- param * (1 - 0.2)
expected_max <- param * (1 + 0.2)
expect_true(test$estimate[1] < expected_max[1] && test$estimate[1] > expected_min[1])
expect_true(test$estimate[2] < expected_max[2] && test$estimate[2] > expected_min[2])
# 3rd estimated parameter is negative but not very accurate...
# expect_true(test$estimate[3] < expected_min[3] && test$estimate[3] > expected_max[3]) # Test is the other way around because param is < 0
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.