Skip to content

Commit

Permalink
test coverage ~70%
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Jun 18, 2024
1 parent 55b6c2d commit 16c1b84
Show file tree
Hide file tree
Showing 29 changed files with 511 additions and 232 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
^README\.html$
^pkgdown$
^Makefile$
^codemeta\.json$
^CODE_OF_CONDUCT\.md$
43 changes: 43 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Contributing to capybara

This outlines how to propose a change to capybara. For more detailed
info about contributing to this, and other tidyverse packages, please see the
[**development contributing guide**](https://rstd.io/tidy-contrib).

### Fixing typos

Small typos or grammatical errors in documentation may be edited directly using
the GitHub web interface, so long as the changes are made in the _source_ file.

* YES: you edit a roxygen comment in a `.R` file below `R/`.
* NO: you edit an `.Rd` file below `man/`.

### Prerequisites

Before you make a substantial pull request, you should always file an issue and
make sure someone from the team agrees that it’s a problem. If you’ve found a
bug, create an associated issue and illustrate the bug with a minimal
[reprex](https://www.tidyverse.org/help/#reprex).

### Pull request process

* We recommend that you create a Git branch for each pull request (PR).
* Look at the Travis and AppVeyor build status before and after making changes.
The `README` should contain badges for any continuous integration services used
by the package.
* New code should follow the tidyverse [style guide](https://style.tidyverse.org).
You can use the [styler](https://CRAN.R-project.org/package=styler) package to
apply these styles, but please don't restyle code that has nothing to do with
your PR.
* We use [roxygen2](https://cran.r-project.org/package=roxygen2), with
[Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/markdown.html),
for documentation.
* We use [testthat](https://cran.r-project.org/package=testthat). Contributions
with test cases included are easier to accept.
* For user-facing changes, add a bullet to the top of `NEWS.md` below the
current development version header describing the changes made followed by your
GitHub username, and links to relevant issue(s)/PR(s).

### Code of Conduct

Please note that the capybara project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
126 changes: 126 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at .
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of
actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the
community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
<https://www.contributor-covenant.org/version/2/1/code_of_conduct.html>.

Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion].

For answers to common questions about this code of conduct, see the FAQ at
<https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.

[homepage]: https://www.contributor-covenant.org
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export(apes)
export(augment)
export(bias_corr)
export(feglm)
export(feglm_control)
export(felm)
export(fenegbin)
export(fepoisson)
Expand Down
4 changes: 0 additions & 4 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,3 @@ solve_eta2_ <- function(yadj, myadj, offset, eta) {
sqrt_ <- function(w) {
.Call(`_capybara_sqrt_`, w)
}

pairwise_cor_ <- function(y, yhat) {
.Call(`_capybara_pairwise_cor_`, y, yhat)
}
2 changes: 0 additions & 2 deletions R/feglm_control.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#' @return A named list of control parameters.
#'
#' @seealso \code{\link{feglm}}
#'
#' @export
feglm_control <- function(
dev.tol = 1.0e-08,
center.tol = 1.0e-08,
Expand Down
3 changes: 3 additions & 0 deletions R/fenegbin.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#' )
#'
#' summary(mod)
#'
#' @return A named list of class \code{"feglm"}.
#'
#' @export
fenegbin <- function(
formula = NULL,
Expand Down
3 changes: 3 additions & 0 deletions R/fepoisson.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#' )
#'
#' summary(mod)
#'
#' @return A named list of class \code{"feglm"}.
#'
#' @export
fepoisson <- function(
formula = NULL,
Expand Down
18 changes: 9 additions & 9 deletions R/generics_print.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ summary_r2_ <- function(x, digits) {
)
}

summary_pseudo_rsq_ <- function(x, digits) {
if (x[["family"]][["family"]] == "poisson") {
cat(
"\nPseudo R-squared:",
format(x[["pseudo.rsq"]], digits = digits, nsmall = 2L), "\n"
)
}
}
# summary_pseudo_rsq_ <- function(x, digits) {
# if (x[["family"]][["family"]] == "poisson") {
# cat(
# "\nPseudo R-squared:",
# format(x[["pseudo.rsq"]], digits = digits, nsmall = 2L), "\n"
# )
# }
# }

summary_nobs_ <- function(x) {
cat(
Expand Down Expand Up @@ -202,7 +202,7 @@ print.summary.feglm <- function(

summary_estimates_(x, digits)

summary_pseudo_rsq_(x, digits)
# summary_pseudo_rsq_(x, digits)

summary_nobs_(x)

Expand Down
18 changes: 10 additions & 8 deletions R/generics_summary.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' @title Summary method for fixed effects APEs
#' @inherit vcov.apes
#' @export
#' @noRd
summary.apes <- function(object, ...) {
# Compute coefficent matrix
est <- object[["delta"]]
Expand All @@ -18,6 +19,7 @@ summary.apes <- function(object, ...) {
#' @title Summary method for fixed effects GLMs
#' @inherit vcov.feglm
#' @export
#' @noRd
summary.feglm <- function(
object,
type = c("hessian", "outer.product", "sandwich", "clustered"),
Expand All @@ -43,14 +45,13 @@ summary.feglm <- function(
family = object[["family"]]
)

if (object[["family"]][["family"]] == "poisson") {
# Compute pseudo R-squared
# http://personal.lse.ac.uk/tenreyro/r2.do
y <- unlist(object$data[, 1], use.names = FALSE)
yhat <- predict(object, type = "response")
res[["pseudo.rsq"]] <- (pairwise_cor_(y, yhat))^2
# res[["pseudo.rsq"]] <- 0
}
# if (object[["family"]][["family"]] == "poisson") {
# # Compute pseudo R-squared
# # http://personal.lse.ac.uk/tenreyro/r2.do
# y <- unlist(object$data[, 1], use.names = FALSE)
# yhat <- predict(object, type = "response")
# # res[["pseudo.rsq"]] <- (pairwise_cor_(y, yhat))^2
# }

if (inherits(object, "fenegbin")) {
res[["theta"]] <- object[["theta"]]
Expand All @@ -64,6 +65,7 @@ summary.feglm <- function(
#' @title Summary method for fixed effects LMs
#' @inherit vcov.felm
#' @export
#' @noRd
summary.felm <- function(
object,
type = "hessian",
Expand Down
13 changes: 12 additions & 1 deletion R/generics_vcov.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#' @return A named matrix of covariance estimates.
#' @seealso \code{\link{apes}}
#' @export
#' @noRd
vcov.apes <- function(object, ...) {
object[["vcov"]]
}
Expand All @@ -26,6 +27,16 @@ vcov.apes <- function(object, ...) {
#' @references Cameron, C., J. Gelbach, and D. Miller (2011). "Robust Inference
#' With Multiway Clustering". Journal of Business & Economic Statistics 29(2).
#' @seealso \code{\link{feglm}}
#' @examples
#' mod <- fepoisson(
#' trade ~ log_dist + lang + cntg + clny | exp_year + imp_year | pair,
#' trade_panel
#' )
#'
#' vcov(mod, type = "clustered")
#'
#' @return A named matrix of covariance estimates.
#'
#' @export
vcov.feglm <- function(
object,
Expand Down Expand Up @@ -150,7 +161,7 @@ vcov.feglm <- function(
V
}

#' @title Covariance matrix for GLMs
#' @title Covariance matrix for LMs
#' @inherit vcov.feglm
#' @seealso \code{\link{felm}}
#' @export
Expand Down
4 changes: 4 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,7 @@ create memory leaks.
initialized values and all kinds of problems that result in memory leaks.

When you are ready testing, you need to remove `-UDEGUG` from `src/Makevars`.

## Code of Conduct

Please note that the capybara project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
Loading

0 comments on commit 16c1b84

Please sign in to comment.