-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3451ca
commit aad78e1
Showing
5 changed files
with
232 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: test-coverage | ||
|
||
jobs: | ||
test-coverage: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
use-public-rspm: true | ||
|
||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: any::covr | ||
needs: coverage | ||
|
||
- name: Test coverage | ||
run: covr::codecov(quiet = FALSE) | ||
shell: Rscript {0} |
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,197 @@ | ||
test_that("multiplication works", { | ||
trade_panel_2002 <- trade_panel[trade_panel$year == 2002, ] | ||
trade_panel_2002$trade_100 <- ifelse(trade_panel_2002$trade >= 100, 1, 0) | ||
trade_panel_2002$trade_200_100 <- as.factor(ifelse(trade_panel_2002$trade >= 200, 1, | ||
ifelse(trade_panel_2002$trade >= 100, 0.5, 0) | ||
)) | ||
trade_panel_2002$trade_1_minus1 <- ifelse(trade_panel_2002$trade >= 100, 1, -1) | ||
|
||
|
||
# APEs ---- | ||
|
||
# TODO: test n.pop argument and the rest of apes() | ||
|
||
expect_error(apes(), "specified") | ||
|
||
expect_error( | ||
apes(lm(trade ~ log_dist, data = trade_panel_2002)), | ||
"non-'feglm'" | ||
) | ||
|
||
expect_error( | ||
apes(fepoisson(trade ~ log_dist | rta, data = trade_panel_2002)), | ||
"binary choice" | ||
) | ||
|
||
expect_error( | ||
apes( | ||
feglm( | ||
trade_100 ~ log_dist | rta + cntg + clny + lang, | ||
data = trade_panel_2002, | ||
family = binomial() | ||
), | ||
panel.structure = "classic" | ||
), "two-way" | ||
) | ||
|
||
expect_error( | ||
apes( | ||
feglm( | ||
trade_100 ~ log_dist | rta + cntg + clny + lang, | ||
data = trade_panel_2002, | ||
family = binomial() | ||
), | ||
panel.structure = "network" | ||
), "three-way" | ||
) | ||
|
||
# GLMs ---- | ||
|
||
expect_error( | ||
fepoisson( | ||
trade ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
control = list(dev.tol = -1.0) | ||
), | ||
"greater than zero" | ||
) | ||
|
||
expect_error( | ||
fepoisson( | ||
trade ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
control = list(iter.max = 0) | ||
), | ||
"at least one" | ||
) | ||
|
||
expect_error( | ||
fepoisson( | ||
trade ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
control = list(limit = 0) | ||
), | ||
"at least one" | ||
) | ||
|
||
# Helpers ---- | ||
|
||
# TODO: | ||
# weights | ||
# linear dependence | ||
# init.theta | ||
# beta.start | ||
# eta.start | ||
|
||
expect_error( | ||
feglm(data = trade_panel_2002), "'formula' has to be specified" | ||
) | ||
|
||
expect_error( | ||
feglm(formula = "a ~ b", data = trade_panel_2002), "'formula' has to be of class 'formula'" | ||
) | ||
|
||
expect_error( | ||
fepoisson( | ||
trade ~ log_dist | rta, | ||
data = NULL | ||
), | ||
"'data' has to be specified" | ||
) | ||
|
||
expect_error( | ||
fepoisson( | ||
trade ~ log_dist | rta, | ||
data = list() | ||
), | ||
"'data' has to be of class data.frame" | ||
) | ||
|
||
expect_error( | ||
fepoisson( | ||
trade ~ log_dist | rta, | ||
data = list() | ||
), | ||
"'data' has to be of class data.frame" | ||
) | ||
|
||
expect_error( | ||
fepoisson( | ||
trade ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
control = c(1, 2) | ||
), | ||
"'control' has to be a list" | ||
) | ||
|
||
expect_error( | ||
feglm( | ||
trade ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
family = "poisson" | ||
), | ||
"'family' has to be of class family" | ||
) | ||
|
||
expect_error( | ||
feglm( | ||
trade ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
family = quasipoisson() | ||
), | ||
"Quasi-variants of 'family' are not supported" | ||
) | ||
|
||
expect_error( | ||
feglm( | ||
trade ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
family = MASS::neg.bin(theta = 1) | ||
), | ||
"use 'fenegbin' instead" | ||
) | ||
|
||
expect_error( | ||
fepoisson( | ||
trade ~ log_dist, | ||
data = trade_panel_2002 | ||
), | ||
"'formula' incorrectly specified" | ||
) | ||
|
||
expect_error( | ||
feglm( | ||
trade ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
family = binomial() | ||
), | ||
"response has to be within the unit interval" | ||
) | ||
|
||
expect_error( | ||
feglm( | ||
trade_200_100 ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
family = binomial() | ||
), | ||
"response has to be binary" | ||
) | ||
|
||
expect_error( | ||
feglm( | ||
trade_1_minus1 ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
family = Gamma() | ||
), | ||
"response has to be strictly positive" | ||
) | ||
|
||
expect_error( | ||
feglm( | ||
trade_1_minus1 ~ log_dist | rta, | ||
data = trade_panel_2002, | ||
family = inverse.gaussian() | ||
), | ||
"response has to be strictly positive" | ||
) | ||
}) |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
test_that("cor(x,x) = 1", { | ||
x <- c(1, 2, 3, 4, 5) | ||
expect_equal(pairwise_cor_(x, x), 1) | ||
expect_equal(pairwise_cor_(x, -x), -1) | ||
}) |