diff --git a/R/lpcde/tests/testthat/test-lpcde.R b/R/lpcde/tests/testthat/test-lpcde.R index e415009..5f3a7b5 100644 --- a/R/lpcde/tests/testthat/test-lpcde.R +++ b/R/lpcde/tests/testthat/test-lpcde.R @@ -79,3 +79,26 @@ test_that("lpcde multivariate output", { expect_equal(model2$opt$p_RBC, 3) expect_equal(model2$opt$q_RBC, 2) }) + +test_that("Properties of pdf estimator", { + #Setting up simulation + set.seed(30) + n=100 + x_data = matrix(rnorm(n, mean=0, sd=1)) + y_data = matrix(rnorm(n, mean=x_data, sd=1)) + y_grid = stats::quantile(y_data, seq(from=0.1, to=0.9, by=0.1)) + #Regularized density estimation + model_reg = lpcde::lpcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=0, bw=1, nonneg=TRUE, normalize=TRUE) + + #check integration to 1 + grid_diff = c(diff(y_grid), diff(utils::tail(y_grid, 2))) + c = sum(model_reg$Estimate[, 3]*grid_diff) + expect_equal(1, c) + + #check nonegativity + a_nng = any(model_reg$Estimate[,3]<0) + expect_equal(a_nng, FALSE) + + #check all probabilities are less than 1 + expect_equal(all(model_reg$Estimate[,3]<1), TRUE) +})