From f237be8de528a16bf9cf905815b5e3a7e32b5f85 Mon Sep 17 00:00:00 2001 From: Shouvik Ghosh Date: Mon, 6 May 2024 11:46:30 +0530 Subject: [PATCH] Updated tests to use standard deviation --- test/numerical/bayesian/LinearRegression.jl | 8 ++++---- test/numerical/bayesian/LogisticRegression.jl | 4 ++-- test/numerical/bayesian/NegBinomialRegression.jl | 4 ++-- test/numerical/bayesian/PoissonRegression.jl | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/numerical/bayesian/LinearRegression.jl b/test/numerical/bayesian/LinearRegression.jl index 8758c25..3930434 100644 --- a/test/numerical/bayesian/LinearRegression.jl +++ b/test/numerical/bayesian/LinearRegression.jl @@ -11,13 +11,13 @@ tests = [ for (prior, test_mean) in tests CRRao.set_rng(StableRNG(123)) model = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression(), prior) - - @test mean(predict(model, mtcars)) ≈ test_mean + prediction = predict(model, mtcars) + @test mean(prediction) - 2 * std(prediction) <= test_mean && test_mean <= mean(prediction) + 2 * std(prediction) end gauss_test = 20.0796026428345 CRRao.set_rng(StableRNG(123)) model = fit(@formula(MPG ~ HP + WT + Gear), mtcars, LinearRegression(), Prior_Gauss(), 30.0, [0.0,-3.0,1.0], 1000) - -@test mean(predict(model, mtcars)) ≈ gauss_test \ No newline at end of file +prediction = predict(model, mtcars) +@test mean(prediction) - 2 * std(prediction) <= gauss_test && gauss_test <= mean(prediction) + 2 * std(prediction) diff --git a/test/numerical/bayesian/LogisticRegression.jl b/test/numerical/bayesian/LogisticRegression.jl index 2708cfa..07aa246 100644 --- a/test/numerical/bayesian/LogisticRegression.jl +++ b/test/numerical/bayesian/LogisticRegression.jl @@ -52,7 +52,7 @@ for (prior, prior_testcases) in tests for (link, test_mean) in prior_testcases CRRao.set_rng(StableRNG(123)) model = fit(@formula(Vote ~ Age + Race + Income + Educate), turnout, LogisticRegression(), link, prior) - - @test mean(predict(model, turnout)) ≈ test_mean + prediction = predict(model, turnout) + @test mean(prediction) - 2 * std(prediction) <= test_mean && test_mean <= mean(prediction) + 2 * std(prediction) end end \ No newline at end of file diff --git a/test/numerical/bayesian/NegBinomialRegression.jl b/test/numerical/bayesian/NegBinomialRegression.jl index 0d75a20..165d2cf 100644 --- a/test/numerical/bayesian/NegBinomialRegression.jl +++ b/test/numerical/bayesian/NegBinomialRegression.jl @@ -11,6 +11,6 @@ tests = [ for (prior, test_mean) in tests CRRao.set_rng(StableRNG(123)) model = fit(@formula(Num ~ Target + Coop + NCost), sanction, NegBinomRegression(), prior) - - @test mean(predict(model, sanction)) ≈ test_mean + prediction = predict(model, sanction) + @test mean(prediction) - 2 * std(prediction) <= test_mean && test_mean <= mean(prediction) + 2 * std(prediction) end \ No newline at end of file diff --git a/test/numerical/bayesian/PoissonRegression.jl b/test/numerical/bayesian/PoissonRegression.jl index d80b490..5ba4457 100644 --- a/test/numerical/bayesian/PoissonRegression.jl +++ b/test/numerical/bayesian/PoissonRegression.jl @@ -11,6 +11,6 @@ tests = [ for (prior, test_mean) in tests CRRao.set_rng(StableRNG(123)) model = fit(@formula(Num ~ Target + Coop + NCost), sanction, PoissonRegression(), prior) - - @test mean(predict(model, sanction)) ≈ test_mean + prediction = predict(model, sanction) + @test mean(prediction) - 2 * std(prediction) <= test_mean && test_mean <= mean(prediction) + 2 * std(prediction) end \ No newline at end of file