-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding frequentist numerical tests + Integrate StatsAPI #67
Merged
sourish-cmi
merged 7 commits into
xKDR:main
from
ShouvikGhosh2048:adding_numerical_tests
Dec 29, 2022
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58bec74
Integrate StatsAPI
ShouvikGhosh2048 be72c35
Add simple frequentist numerical tests + 0 intercept tests
ShouvikGhosh2048 1370a30
Added predict to tests + added more formulae
ShouvikGhosh2048 2a5f5e4
Add AIC and BIC tests for Linear, Logistic and Poisson models.
ShouvikGhosh2048 0f701af
Merge branch 'xKDR:main' into adding_numerical_tests
ShouvikGhosh2048 2c74f60
Add AIC and BIC tests and update negative binomial tests
ShouvikGhosh2048 77db266
Merge branch 'main' into adding_numerical_tests
ShouvikGhosh2048 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
mtcars = dataset("datasets", "mtcars") | ||
|
||
tests = [ | ||
(@formula(MPG ~ HP + WT + Gear), 157.052778719219475, 164.381458233218098), | ||
(@formula(MPG ~ 0 + HP + WT + Gear), 186.905400588726366, 192.768344199925281), | ||
(@formula(MPG ~ HP + HP^2 + WT + WT * HP), 145.922971789355415, 154.717387206153774), | ||
(@formula(log(MPG) ~ log(HP) + log(WT)), -48.353276320549490, -42.490332709350582) | ||
] | ||
|
||
for (test_formula, test_aic, test_bic) in tests | ||
crrao_model = fit(test_formula, mtcars, LinearRegression()) | ||
glm_model = lm(test_formula, mtcars) | ||
compare_models(crrao_model, glm_model, mtcars) | ||
@test isapprox(aic(crrao_model), test_aic) | ||
@test isapprox(bic(crrao_model), test_bic) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
turnout = dataset("Zelig", "turnout") | ||
|
||
tests = [ | ||
(Logit(), LogitLink(), [ | ||
(@formula(Vote ~ Age + Race + Income + Educate), 2033.981263703107970, 2061.985776000818532), | ||
(@formula(Vote ~ 0 + Age + Race + Income + Educate), 2033.981263703107970, 2061.985776000818532), | ||
(@formula(Vote ~ Age + Age^2 + Race + Income * Educate), 2023.429129040224325, 2062.635446257018884), | ||
(@formula(Vote ~ log(Age) + Educate), 2069.570124645007581, 2086.372832023633691) | ||
]), | ||
(Probit(), ProbitLink(), [ | ||
(@formula(Vote ~ Age + Race + Income + Educate), 2034.196513858159960, 2062.201026155870295), | ||
(@formula(Vote ~ 0 + Age + Race + Income + Educate), 2034.196513858159960, 2062.201026155870295), | ||
(@formula(Vote ~ Age + Age^2 + Race + Income * Educate), 2023.024253890667069, 2062.230571107461856), | ||
(@formula(Vote ~ log(Age) + Educate), 2068.082640703962625, 2084.885348082588735) | ||
]), | ||
(Cloglog(), CloglogLink(), [ | ||
(@formula(Vote ~ Age + Race + Income + Educate), 2036.690120606579512, 2064.694632904289847), | ||
(@formula(Vote ~ 0 + Age + Race + Income + Educate), 2036.690120606579512, 2064.694632904289847), | ||
(@formula(Vote ~ log(Age) + Educate), 2067.047234348701750, 2083.849941727327860) | ||
]), | ||
(Cauchit(), CauchitLink(), [ | ||
(@formula(Vote ~ Age + Race + Income + Educate), 2050.941937867712113, 2078.946450165422448), | ||
(@formula(Vote ~ 0 + Age + Race + Income + Educate), 2050.941937867712113, 2078.946450165422448), | ||
(@formula(Vote ~ Age + Age^2 + Race + Income * Educate), 2036.876992804688371, 2076.083310021483157), | ||
(@formula(Vote ~ log(Age) + Educate), 2085.365660144347203, 2102.168367522973313) | ||
]) | ||
] | ||
|
||
for (crrao_link, glm_link, formulae_and_values) in tests | ||
for (test_formula, test_aic, test_bic) in formulae_and_values | ||
crrao_model = fit(test_formula, turnout, LogisticRegression(), crrao_link) | ||
glm_model = glm(test_formula, turnout, Binomial(), glm_link) | ||
compare_models(crrao_model, glm_model, turnout) | ||
@test isapprox(aic(crrao_model), test_aic) | ||
@test isapprox(bic(crrao_model), test_bic) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
sanction = dataset("Zelig", "sanction") | ||
|
||
tests = [ | ||
(@formula(Num ~ Target + Coop + NCost), 344.8795500751855, 361.37651186201265), | ||
(@formula(Num ~ 0 + Target + Coop + NCost), 344.87955007518536, 361.37651186201253), | ||
(@formula(Num ~ Target + Target^2 + Coop + Coop * Target), 362.262357097934, 376.40261005807156), | ||
(@formula(Num ~ log(Target) + log(Coop)), 367.1949690199781, 376.6218043267365) | ||
] | ||
|
||
for (test_formula, test_aic, test_bic) in tests | ||
crrao_model = fit(test_formula, sanction, NegBinomRegression()) | ||
glm_model = negbin(test_formula, sanction, LogLink()) | ||
compare_models(crrao_model, glm_model, sanction) | ||
@test isapprox(aic(crrao_model), test_aic) | ||
@test isapprox(bic(crrao_model), test_bic) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
sanction = dataset("Zelig", "sanction") | ||
|
||
tests = [ | ||
(@formula(Num ~ Target + Coop + NCost), 580.673868966946884, 594.814121927084443), | ||
(@formula(Num ~ 0 + Target + Coop + NCost), 580.673868966946770, 594.814121927084329), | ||
(@formula(Num ~ Target + Target^2 + Coop + Coop * Target), 871.418230125844502, 883.201774259292506), | ||
(@formula(Num ~ log(Target) + log(Coop)), 944.326386272138961, 951.396512752207741) | ||
] | ||
|
||
for (test_formula, test_aic, test_bic) in tests | ||
crrao_model = fit(test_formula, sanction, PoissonRegression()) | ||
glm_model = glm(test_formula, sanction, Poisson(), LogLink()) | ||
compare_models(crrao_model, glm_model, sanction) | ||
@test isapprox(aic(crrao_model), test_aic) | ||
@test isapprox(bic(crrao_model), test_bic) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function compare_models(crrao_model, glm_model, df) | ||
@test isapprox(coeftable(crrao_model).cols, coeftable(glm_model).cols) | ||
@test isapprox(predict(crrao_model, df), predict(glm_model, df)) | ||
end | ||
|
||
@testset "Linear Regression" begin | ||
include("LinearRegression.jl") | ||
end | ||
|
||
@testset "Logistic Regression" begin | ||
include("LogisticRegression.jl") | ||
end | ||
|
||
@testset "Poisson Regression" begin | ||
include("PoissonRegression.jl") | ||
end | ||
|
||
@testset "Negative Binomial Regression" begin | ||
include("NegBinomialRegression.jl") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a change to src/frequentist/getter.jl - I think it should be CloglogLink instead of Cloglog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay -- great. thanks.