Skip to content

Commit

Permalink
added unit tests for valid pdf estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
rajitachandak committed Oct 10, 2024
1 parent 7278e44 commit a642f48
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions R/lpcde/tests/testthat/test-lpcde.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit a642f48

Please sign in to comment.