Skip to content

Commit

Permalink
apply proper ssr documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Nov 17, 2024
1 parent a460b61 commit 2a8d78e
Show file tree
Hide file tree
Showing 25 changed files with 560 additions and 421 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ License: Apache License (>= 2)
BugReports: https://github.com/pachadotdev/capybara/issues
URL: https://pacha.dev/capybara/, https://github.com/pachadotdev/capybara
LazyData: true
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Encoding: UTF-8
NeedsCompilation: yes
LinkingTo: cpp11, cpp11armadillo
Expand Down
18 changes: 12 additions & 6 deletions R/apes.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#' srr_stats (tests)
#' @srrstats {G1.0} Statistical Software should list at least one primary
#' reference from published academic literature.
#' @srrstats {G2.3} For univariate character input:
#' @srrstats {G2.3a} Use `match.arg()` or equivalent where applicable to only
#' permit expected values.
#' @srrstats {G2.3b} Either: use `tolower()` or equivalent to ensure input of
#' character parameters is not case dependent; or explicitly document that
#' parameters are strictly case-sensitive.
#' @noRd
NULL

#' @title Compute average partial effects after fitting binary choice models
#' with a 1,2,3-way error component
#'
Expand All @@ -10,10 +22,6 @@
#'
#' \strong{Remark:} The routine currently does not allow to compute average
#' partial effects based on functional forms like interactions and polynomials.
#'
#' @srrstats {G2.3} *For univariate character input:*
#' @srrstats {G2.3a} *Use `match.arg()` or equivalent where applicable to only permit expected values.*
#' @srrstats {G2.3b} *Either: use `tolower()` or equivalent to ensure input of character parameters is not case dependent; or explicitly document that parameters are strictly case-sensitive.*
#'
#' @param object an object of class \code{"bias_corr"} or \code{"feglm"};
#' currently restricted to \code{\link[stats]{binomial}}.
Expand Down Expand Up @@ -46,8 +54,6 @@
#'
#' @return The function \code{\link{apes}} returns a named list of class
#' \code{"apes"}.
#'
#' @srrstats {G1.0} *Statistical Software should list at least one primary reference from published academic literature.*
#'
#' @references Cruz-Gonzalez, M., I. Fernández-Val, and M. Weidner (2017). "Bias
#' corrections for probit and logit models with two-way fixed effects". The
Expand Down
9 changes: 8 additions & 1 deletion R/apes_bias_helpers.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#' srr_stats (tests)
#' @srrstats {G1.4a} All internal (non-exported) functions should also be
#' documented in standard [`roxygen2`](https://roxygen2.r-lib.org/) format,
#' along with a final `@noRd` tag to suppress automatic generation of `.Rd`
#' files.
#' @noRd
NULL

#' @title Checks if the object is an `feglm` object
#' @description Internal check
#' @param object Object to check
#' @param fun Function name (e.g., "apes")
#' @srrstats {G1.4a} *All internal (non-exported) functions should also be documented in standard [`roxygen2`](https://roxygen2.r-lib.org/) format, along with a final `@noRd` tag to suppress automatic generation of `.Rd` files.*
#' @noRd
apes_bias_check_object_ <- function(object, fun) {
if (is.null(object)) {
Expand Down
18 changes: 12 additions & 6 deletions R/bias_corr.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#' srr_stats (tests)
#' @srrstats {G1.0} Statistical Software should list at least one primary
#' reference from published academic literature.
#' @srrstats {G2.3} For univariate character input:
#' @srrstats {G2.3a} Use `match.arg()` or equivalent where applicable to only
#' permit expected values.
#' @srrstats {G2.3b} Either: use `tolower()` or equivalent to ensure input of
#' character parameters is not case dependent; or explicitly document that
#' parameters are strictly case-sensitive.
#' @noRd
NULL

#' @title Asymptotic bias correction after fitting binary choice models with a
#' 1,2,3-way error component
#'
Expand All @@ -7,10 +19,6 @@
#' obtain bias-corrected estimates of the structural parameters and is
#' currently restricted to \code{\link[stats]{binomial}} with 1,2,3-way fixed
#' effects.
#'
#' @srrstats {G2.3} *For univariate character input:*
#' @srrstats {G2.3a} *Use `match.arg()` or equivalent where applicable to only permit expected values.*
#' @srrstats {G2.3b} *Either: use `tolower()` or equivalent to ensure input of character parameters is not case dependent; or explicitly document that parameters are strictly case-sensitive.*
#'
#' @param object an object of class \code{"feglm"}.
#' @param l unsigned integer indicating a bandwidth for the estimation of
Expand All @@ -28,8 +36,6 @@
#' observed for several time periods. Default is \code{"classic"}.
#'
#' @return A named list of classes \code{"bias_corr"} and \code{"feglm"}.
#'
#' @srrstats {G1.0} *Statistical Software should list at least one primary reference from published academic literature.*
#'
#' @references Czarnowske, D. and A. Stammann (2020). "Fixed Effects Binary
#' Choice Models: Estimation and Inference with Long Panels". ArXiv e-prints.
Expand Down
20 changes: 16 additions & 4 deletions R/capybara-package.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#' srr_stats (tests)
#' @srrstats {G1.1} The algorithm is a full refactor with memory and speed
#' improvements for a previous R implementation (Stammann, 2018).
#' @srrstats {G1.2} Describes the current and anticipated future states of
#' development.
#' @srrstats {G1.4} The package uses [`roxygen2`](https://roxygen2.r-lib.org/)
#' to document all functions (see ./DESCRIPTION).
#' @noRd
NULL

#' @title Generalized Linear Models (GLMs) with high-dimensional k-way fixed
#' effects
#'
#' @srrstats {G1.1} *Statistical Software should document whether the algorithm(s) it implements are:* - *The first implementation of a novel algorithm*; or - *The first implementation within **R** of an algorithm which has previously been implemented in other languages or contexts*; or - *An improvement on other implementations of similar algorithms in **R***.
#' @srrstats {G1.2} *Statistical Software should include a* Life Cycle Statement *describing current and anticipated future states of development.*
#' @srrstats {G1.4} *Software should use [`roxygen2`](https://roxygen2.r-lib.org/) to document all functions.*
#'
#' @description
#' Provides a routine to partial out factors with many levels during the
Expand Down Expand Up @@ -34,6 +40,11 @@
#' @useDynLib capybara, .registration = TRUE
"_PACKAGE"

#' srr_stats (tests)
#' @srrstats {G5.1} The panel is exported and used in the package examples.
#' @noRd
NULL

#' Trade Panel 1986-2006
#'
#' Aggregated exports at origin-destination-year level for 1986-2006.
Expand All @@ -54,5 +65,6 @@
#' \item{exp_year}{Exporter ISO country code and year}
#' \item{imp_year}{Importer ISO country code and year}
#' }
#'
#' @source Advanced Guide to Trade Policy Analysis (ISBN: 978-92-870-4367-2)
"trade_panel"
78 changes: 55 additions & 23 deletions R/feglm.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
#' srr_stats (tests)
#' @srrstats {G1.0} Statistical Software should list at least one primary
#' reference from published academic literature.
#' @srrstats {G1.3} All statistical terminology should be clarified and
#' unambiguously defined.
#' @srrstats {G2.3} For univariate character input:
#' @srrstats {G2.3a} Use `match.arg()` or equivalent where applicable to only
#' permit expected values.
#' @srrstats {G2.3b} Either: use `tolower()` or equivalent to ensure input of
#' character parameters is not case dependent; or explicitly document that
#' parameters are strictly case-sensitive.
#' @srrstats {RE4.4} The specification of the model, generally as a formula
#' (via `formula()`)
#' @srrstats {RE1.0} Regression Software should enable models to be specified
#' via a formula interface, unless reasons for not doing so are explicitly
#' documented.
#' @srrstats {RE1.1} Regression Software should document how formula interfaces
#' are converted to matrix representations of input data.
#' @srrstats {RE1.2} Regression Software should document expected format (types
#' or classes) for inputting predictor variables, including descriptions of
#' types or classes which are not accepted.
#' @srrstats {RE1.3} Regression Software which passes or otherwise transforms
#' aspects of input data onto output structures should ensure that those output
#' structures retain all relevant aspects of input data, notably including row
#' and column names, and potentially information from other `attributes()`.
#' @srrstats {RE1.3a} Where otherwise relevant information is not transferred,
#' this should be explicitly documented.
#' @srrstats {RE1.4} Regression Software should document any assumptions made
#' with regard to input data; for example distributional assumptions, or
#' assumptions that predictor data have mean values of zero. Implications of
#' violations of these assumptions should be both documented and tested.
#' @srrstats {RE2.3} Where applicable, Regression Software should enable data to
#' be centred (for example, through converting to zero-mean equivalent values;
#' or to z-scores) or offset (for example, to zero-intercept equivalent values)
#' via additional parameters, with the effects of any such parameters clearly
#' documented and tested.
#' @srrstats {RE3.0} Issue appropriate warnings or other diagnostic messages for
#' models which fail to converge.
#' @srrstats {RE3.1} Enable such messages to be optionally suppressed, yet
#' should ensure that the resultant model object nevertheless includes
#' sufficient data to identify lack of convergence.
#' @srrstats {RE3.2} Ensure that convergence thresholds have sensible default
#' values, demonstrated through explicit documentation.
#' @srrstats {RE3.3} Allow explicit setting of convergence thresholds, unless
#' reasons against doing so are explicitly documented.
#' @srrstats {RE4.0} Regression Software should return some form of "model"
#' object, generally through using or modifying existing class structures for
#' model objects (such as `lm`, `glm`, or model objects from other packages),
#' or creating a new class of model objects.
#' @noRd
NULL

#' @title GLM fitting with high-dimensional k-way fixed effects
#'
#' @description \code{\link{feglm}} can be used to fit generalized linear models
Expand All @@ -8,22 +60,6 @@
#' \strong{Remark:} The term fixed effect is used in econometrician's sense of
#' having intercepts for each level in each category.
#'
#' @srrstats {G2.3} *For univariate character input:*
#' @srrstats {G2.3a} *Use `match.arg()` or equivalent where applicable to only permit expected values.*
#' @srrstats {G2.3b} *Either: use `tolower()` or equivalent to ensure input of character parameters is not case dependent; or explicitly document that parameters are strictly case-sensitive.*
#' @srrstats {RE4.4} *The specification of the model, generally as a formula (via `formula()`)*
#' @srrstats {RE1.0} *Regression Software should enable models to be specified via a formula interface, unless reasons for not doing so are explicitly documented.*
#' @srrstats {RE1.1} *Regression Software should document how formula interfaces are converted to matrix representations of input data.*
#' @srrstats {RE1.2} *Regression Software should document expected format (types or classes) for inputting predictor variables, including descriptions of types or classes which are not accepted.*
#' @srrstats {RE1.3} *Regression Software which passes or otherwise transforms aspects of input data onto output structures should ensure that those output structures retain all relevant aspects of input data, notably including row and column names, and potentially information from other `attributes()`.*
#' @srrstats {RE1.3a} *Where otherwise relevant information is not transferred, this should be explicitly documented.*
#' @srrstats {RE1.4} *Regression Software should document any assumptions made with regard to input data; for example distributional assumptions, or assumptions that predictor data have mean values of zero. Implications of violations of these assumptions should be both documented and tested.*
#' @srrstats {RE2.3} *Where applicable, Regression Software should enable data to be centred (for example, through converting to zero-mean equivalent values; or to z-scores) or offset (for example, to zero-intercept equivalent values) via additional parameters, with the effects of any such parameters clearly documented and tested.*
#' @srrstats {RE3.0} *Issue appropriate warnings or other diagnostic messages for models which fail to converge.*
#' @srrstats {RE3.1} *Enable such messages to be optionally suppressed, yet should ensure that the resultant model object nevertheless includes sufficient data to identify lack of convergence.*
#' @srrstats {RE3.2} *Ensure that convergence thresholds have sensible default values, demonstrated through explicit documentation.*
#' @srrstats {RE3.3} *Allow explicit setting of convergence thresholds, unless reasons against doing so are explicitly documented.*
#'
#' @param formula an object of class \code{"formula"}: a symbolic description of
#' the model to be fitted. \code{formula} must be of type \code{y ~ x | k},
#' where the second part of the formula refers to factors to be concentrated
Expand Down Expand Up @@ -51,9 +87,6 @@
#' linear dependence between one or more regressors and a fixed effects
#' category. In this case, you should carefully inspect your model
#' specification.
#'
#' @srrstats {G1.3} *All statistical terminology should be clarified and unambiguously defined.*
#' @srrstats {RE4.0} *Regression Software should return some form of "model" object, generally through using or modifying existing class structures for model objects (such as `lm`, `glm`, or model objects from other packages), or creating a new class of model objects.*
#'
#' @return A named list of class \code{"feglm"}. The list contains the following
#' fifteen elements:
Expand All @@ -75,8 +108,6 @@
#' observations}
#' \item{family}{the family used in the model}
#' \item{control}{the control list used in the model}
#'
#' @srrstats {G1.0} *Statistical Software should list at least one primary reference from published academic literature.*
#'
#' @references Gaure, S. (2013). "OLS with Multiple High Dimensional Category
#' Variables". Computational Statistics and Data Analysis, 66.
Expand Down Expand Up @@ -163,8 +194,9 @@ feglm <- function(
p <- NA
model_response_(data, formula)

# Check for linear dependence in 'x' ----
check_linear_dependence_(x, p)
# Check for linear dependence ----
# check_linear_dependence_(x, p)
check_linear_dependence_(cbind(y,x), p + 1L)

# Extract weights if required ----
if (is.null(weights)) {
Expand Down
Loading

0 comments on commit 2a8d78e

Please sign in to comment.