diff --git a/NAMESPACE b/NAMESPACE index f28ec3e..b4c6af8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,12 +1,15 @@ # Generated by roxygen2: do not edit by hand S3method(augment,feglm) +S3method(augment,felm) S3method(coef,apes) S3method(coef,feglm) S3method(coef,felm) S3method(coef,summary.apes) S3method(coef,summary.feglm) S3method(coef,summary.felm) +S3method(confint,feglm) +S3method(confint,felm) S3method(fitted,feglm) S3method(fitted,felm) S3method(glance,feglm) @@ -69,6 +72,7 @@ importFrom(stats,pnorm) importFrom(stats,poisson) importFrom(stats,predict) importFrom(stats,printCoefmat) +importFrom(stats,qnorm) importFrom(stats,terms) importFrom(stats,vcov) importFrom(utils,combn) diff --git a/R/broom.R b/R/broom.R new file mode 100644 index 0000000..30b175d --- /dev/null +++ b/R/broom.R @@ -0,0 +1,76 @@ +#' Augment method for fepoisson (Broom) +#' +#' @param x A fitted model object. +#' @param newdata Optional argument to use data different from the data used to fit +#' the model. +#' @param ... Additional arguments passed to the method. +#' +#' @return A tibble with the input data and additional columns for the fitted +#' values and residuals. +#' +#' @rdname broom +#' +#' @examples +#' if (require("broom")) { +#' set.seed(123) +#' trade_2006 <- trade_panel[trade_panel$year == 2006, ] +#' trade_2006 <- trade_2006[sample(nrow(trade_2006), 1000), ] +#' +#' mod <- fepoisson( +#' trade ~ log_dist + lang + cntg + clny | exp_year + imp_year, +#' trade_2006 +#' ) +#' +#' broom::augment(mod) +#' } + +#' Glance method for fepoisson (Broom) +#' +#' @param x A fitted model object. +#' @param ... Additional arguments passed to the method. +#' +#' @return A tibble with the deviance, null deviance, and the number of +#' observations (full rows, missing values, and perfectly classified). +#' +#' @rdname broom +#' +#' @examples +#' if (require("broom")) { +#' set.seed(123) +#' trade_2006 <- trade_panel[trade_panel$year == 2006, ] +#' trade_2006 <- trade_2006[sample(nrow(trade_2006), 1000), ] +#' +#' mod <- fepoisson( +#' trade ~ log_dist + lang + cntg + clny | exp_year + imp_year, +#' trade_2006 +#' ) +#' +#' broom::glance(mod) +#' } + +#' Tidy method for fepoisson (Broom) +#' +#' @param x A fitted model object. +#' @param conf.int Logical indicating whether to include the confidence interval. +#' @param conf.level The confidence level for the confidence interval. +#' @param ... Additional arguments passed to the method. +#' +#' @return A tibble with the estimated coefficients, standard errors, test +#' statistics, p-values, and optionally the lower and upper bounds of the +#' confidence interval. +#' +#' @rdname broom +#' +#' @examples +#' if (require("broom")) { +#' set.seed(123) +#' trade_2006 <- trade_panel[trade_panel$year == 2006, ] +#' trade_2006 <- trade_2006[sample(nrow(trade_2006), 1000), ] +#' +#' mod <- fepoisson( +#' trade ~ log_dist + lang + cntg + clny | exp_year + imp_year, +#' trade_2006 +#' ) +#' +#' broom::tidy(mod) +#' } diff --git a/R/capybara-package.R b/R/capybara-package.R index b96fb65..2628e6b 100644 --- a/R/capybara-package.R +++ b/R/capybara-package.R @@ -19,7 +19,7 @@ #' @importFrom MASS negative.binomial theta.ml #' @importFrom rlang sym := #' @importFrom stats as.formula fitted.values gaussian model.matrix na.omit -#' pnorm poisson predict printCoefmat terms vcov +#' pnorm poisson predict printCoefmat qnorm terms vcov #' @importFrom utils combn #' @useDynLib capybara, .registration = TRUE "_PACKAGE" diff --git a/R/generics_confint.R b/R/generics_confint.R index 8b19abb..ff5ff07 100644 --- a/R/generics_confint.R +++ b/R/generics_confint.R @@ -15,9 +15,15 @@ confint.feglm <- function(object, parm, level = 0.95, ...) { conf.high = res[, "estimate"] + z * res[, "std.error"] ) - colnames(conf.int) <- paste(100 * (c(0, 1) + c(1, -1) * (1 - conf.level) / 2), + colnames(conf.int) <- paste(100 * (c(0, 1) + c(1, -1) * (1 - level) / 2), "%") # Return the confidence intervals conf.int } + +#' @export +#' @noRd +confint.felm <- function(object, parm, level = 0.95, ...) { + confint.feglm(object, parm, level, ...) +} diff --git a/R/srr-stats-standards.R b/R/srr-stats-standards.R index 3dbbd8f..7fac180 100644 --- a/R/srr-stats-standards.R +++ b/R/srr-stats-standards.R @@ -87,9 +87,8 @@ #' @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.* -#' @srrstatsTODO {RE4.1} *Regression Software may enable an ability to generate a model object without actually fitting values. This may be useful for controlling batch processing of computationally intensive fitting algorithms.* #' @srrstats {RE4.2} *Model coefficients (via `coef()` / `coefficients()`)* -#' @srrstatsTODO {RE4.3} *Confidence intervals on those coefficients (via `confint()`)* +#' @srrstats {RE4.3} *Confidence intervals on those coefficients (via `confint()`)* #' @srrstats {RE4.4} *The specification of the model, generally as a formula (via `formula()`)* #' @srrstats {RE4.5} *Numbers of observations submitted to model (via `nobs()`)* #' @srrstats {RE4.6} *The variance-covariance matrix of the model parameters (via `vcov()`)* @@ -102,10 +101,6 @@ #' @srrstats {RE4.13} *Predictor variables, and associated "metadata" where applicable.* #' @srrstats {RE4.18} *Regression Software may also implement `summary` methods for model objects, and in particular should implement distinct `summary` methods for any cases in which calculation of summary statistics is computationally non-trivial (for example, for bootstrapped estimates of confidence intervals).* #' @srrstats {RE5.0} *Scaling relationships between sizes of input data (numbers of observations, with potential extension to numbers of variables/columns) and speed of algorithm.* -#' @srrstatsTODO {RE6.0} *Model objects returned by Regression Software (see* **RE4***) should have default `plot` methods, either through explicit implementation, extension of methods for existing model objects, or through ensuring default methods work appropriately.* -#' @srrstatsTODO {RE6.1} *Where the default `plot` method is **NOT** a generic `plot` method dispatched on the class of return objects (that is, through an S3-type `plot.` function or equivalent), that method dispatch (or equivalent) should nevertheless exist in order to explicitly direct users to the appropriate function.* -#' @srrstatsTODO {RE6.2} *The default `plot` method should produce a plot of the `fitted` values of the model, with optional visualisation of confidence intervals or equivalent.* -#' @srrstatsTODO {RE6.3} *Where a model object is used to generate a forecast (for example, through a `predict()` method), the default `plot` method should provide clear visual distinction between modelled (interpolated) and forecast (extrapolated) values.* #' @srrstats {RE7.0} *Tests with noiseless, exact relationships between predictor (independent) data.* #' @srrstats {RE7.0a} In particular, these tests should confirm ability to reject perfectly noiseless input data. #' @srrstats {RE7.1} *Tests with noiseless, exact relationships between predictor (independent) and response (dependent) data.* @@ -130,9 +125,14 @@ NULL #' @srrstatsNA {G5.9b} *Running under different random seeds or initial conditions does not meaningfully change results* #' @srrstatsNA {G5.11a} *When any downloads of additional data necessary for extended tests fail, the tests themselves should not fail, rather be skipped and implicitly succeed with an appropriate diagnostic message.* #' @srrstatsNA {RE2.2} *Regression Software should provide different options for processing missing values in predictor and response data. For example, it should be possible to fit a model with no missing predictor data in order to generate values for all associated response points, even where submitted response values may be missing.* +#' @srrstatsNA {RE4.1} *Regression Software may enable an ability to generate a model object without actually fitting values. This may be useful for controlling batch processing of computationally intensive fitting algorithms.* #' @srrstatsNA {RE4.16} *Regression Software which models distinct responses for different categorical groups should include the ability to submit new groups to `predict()` methods.* #' @srrstatsNA {RE4.14} *Where possible, values should also be provided for extrapolation or forecast *errors*.* #' @srrstatsNA {RE4.15} *Sufficient documentation and/or testing should be provided to demonstrate that forecast errors, confidence intervals, or equivalent values increase with forecast horizons.* #' @srrstatsNA {RE4.17} *Model objects returned by Regression Software should implement or appropriately extend a default `print` method which provides an on-screen summary of model (input) parameters and (output) coefficients.* +#' @srrstatsNA {RE6.0} *Model objects returned by Regression Software (see* **RE4***) should have default `plot` methods, either through explicit implementation, extension of methods for existing model objects, or through ensuring default methods work appropriately.* +#' @srrstatsNA {RE6.1} *Where the default `plot` method is **NOT** a generic `plot` method dispatched on the class of return objects (that is, through an S3-type `plot.` function or equivalent), that method dispatch (or equivalent) should nevertheless exist in order to explicitly direct users to the appropriate function.* +#' @srrstatsNA {RE6.2} *The default `plot` method should produce a plot of the `fitted` values of the model, with optional visualisation of confidence intervals or equivalent.* +#' @srrstatsNA {RE6.3} *Where a model object is used to generate a forecast (for example, through a `predict()` method), the default `plot` method should provide clear visual distinction between modelled (interpolated) and forecast (extrapolated) values.* #' @noRd NULL