Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .aspell/defaults.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Rd_files <- vignettes <- R_files <- description <-
list(encoding = "UTF-8",
language = "en",
dictionaries = c("en_stats", "mydict"))
Binary file added .aspell/mydict.rds
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ README.html
/vignettes/figure/
/vignettes/*.bib.bak
/revdep/
\#*
.#*
24 changes: 11 additions & 13 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
Package: prediction
Type: Package
Title: Tidy, Type-Safe 'prediction()' Methods
Description: A one-function package containing 'prediction()', a type-safe alternative to 'predict()' that always returns a data frame. The 'summary()' method provides a data frame with average predictions, possibly over counterfactual versions of the data (a la the 'margins' command in 'Stata'). Marginal effect estimation is provided by the related package, 'margins' <https://cran.r-project.org/package=margins>. The package currently supports common model types (e.g., "lm", "glm") from the 'stats' package, as well as numerous other model classes from other add-on packages. See the README or main package documentation page for a complete listing.
Description: A one-function package containing prediction(), a type-safe alternative to predict() that always returns a data frame. The summary() method provides a data frame with average predictions, possibly over counterfactual versions of the data (à la the margins command in 'Stata'). Marginal effect estimation is provided by the related package, 'margins' <https://cran.r-project.org/package=margins>. The package currently supports common model types (e.g., lm, glm) from the 'stats' package, as well as numerous other model classes from other add-on packages. See the README file or main package documentation page for a complete listing.
License: MIT + file LICENSE
Version: 0.3.15
Date: 2019-12-24
Version: 0.3.18
Authors@R: c(person("Thomas J.", "Leeper",
role = c("aut", "cre"),
email = "thosjleeper@gmail.com",
role = c("aut"),
comment = c(ORCID = "0000-0003-4097-6326")),
person("Carl", "Ganz", role = "ctb",
email = "carlganz@ucla.edu"),
person("Carl", "Ganz", role = "ctb"),
person("Vincent", "Arel-Bundock", role = "ctb",
email = "vincent.arel-bundock@umontreal.ca",
comment = c(ORCID = "0000-0003-2042-7063"))
comment = c(ORCID = "0000-0003-2042-7063")),
person("Ben","Bolker",email="bolker@mcmaster.ca",
role=c("ctb","cre"),
comment=c(ORCID="0000-0002-2127-0443"))
)
URL: https://github.com/leeper/prediction
BugReports: https://github.com/leeper/prediction/issues
URL: https://github.com/bbolker/prediction
BugReports: https://github.com/bbolker/prediction/issues
Depends: R (>= 3.5.0)
Imports:
utils,
Expand All @@ -37,7 +36,6 @@ Enhances:
e1071,
earth,
ff,
ffbase,
gam (>= 1.15),
gee,
glmnet,
Expand All @@ -64,4 +62,4 @@ Enhances:
VGAM
ByteCompile: true
Encoding: UTF-8
RoxygenNote: 7.0.2
RoxygenNote: 7.3.2
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ S3method(find_data,crch)
S3method(find_data,data.frame)
S3method(find_data,default)
S3method(find_data,glimML)
S3method(find_data,glimQL)
S3method(find_data,glm)
S3method(find_data,hxlr)
S3method(find_data,lm)
Expand All @@ -25,6 +26,8 @@ S3method(prediction,Gam)
S3method(prediction,ar)
S3method(prediction,arima0)
S3method(prediction,betareg)
S3method(prediction,bigLm)
S3method(prediction,bigglm)
S3method(prediction,biglm)
S3method(prediction,bruto)
S3method(prediction,clm)
Expand All @@ -48,6 +51,7 @@ S3method(prediction,ivreg)
S3method(prediction,knnreg)
S3method(prediction,kqr)
S3method(prediction,ksvm)
S3method(prediction,lda)
S3method(prediction,lm)
S3method(prediction,lme)
S3method(prediction,loess)
Expand All @@ -56,15 +60,19 @@ S3method(prediction,mars)
S3method(prediction,mca)
S3method(prediction,mclogit)
S3method(prediction,merMod)
S3method(prediction,mlogit)
S3method(prediction,mnlogit)
S3method(prediction,mnp)
S3method(prediction,multinom)
S3method(prediction,naiveBayes)
S3method(prediction,nls)
S3method(prediction,nnet)
S3method(prediction,plm)
S3method(prediction,polr)
S3method(prediction,polyreg)
S3method(prediction,ppr)
S3method(prediction,princomp)
S3method(prediction,qda)
S3method(prediction,rlm)
S3method(prediction,rpart)
S3method(prediction,rq)
Expand All @@ -75,7 +83,10 @@ S3method(prediction,survreg)
S3method(prediction,svm)
S3method(prediction,svyglm)
S3method(prediction,train)
S3method(prediction,tree)
S3method(prediction,truncreg)
S3method(prediction,vgam)
S3method(prediction,vglm)
S3method(prediction,zeroinfl)
S3method(print,prediction)
S3method(print,summary.prediction)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## prediction 0.3.18

* under new maintainership
* various cosmetic/CRAN check updates

## prediction 0.3.15

* `build_datalist()` now works correctly with data.table datasets. (#34, #35, h/t Dan Schrage)
Expand Down
2 changes: 2 additions & 0 deletions R/find_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ find_data.glimML <- function(model, ...) {
methods::slot(model, "data")
}

#' @rdname find_data
#' @export
find_data.glimQL <- function(model, env = parent.frame(), ...) {
requireNamespace("methods", quietly = TRUE)
methods::slot(model, "fm")$data
Expand Down
3 changes: 2 additions & 1 deletion R/margex.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#' \item{\samp{agegroup}}{A factor with three levels}
#' \item{\samp{arm}}{A factor with three levels}
#' }
#' @source \url{http://www.stata-press.com/data/r14/margex.dta}
#' @source \url{https://www.stata-press.com/data/r14/margex.dta}
#' @usage data("margex")
#' @examples
#' \donttest{
#'
Expand Down
25 changes: 16 additions & 9 deletions R/prediction.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' \item \dQuote{ar}, see \code{\link[stats]{ar}}
#' \item \dQuote{Arima}, see \code{\link[stats]{arima}}
#' \item \dQuote{arima0}, see \code{\link[stats]{arima0}}
#' \item \dQuote{bigglm}, see \code{\link[biglm]{bigglm}} (including \dQuote{ffdf}-backed models provided by \code{\link[ffbase]{bigglm.ffdf}})
#' \item \dQuote{bigglm}, see \code{\link[biglm]{bigglm}}
#' \item \dQuote{betareg}, see \code{\link[betareg]{betareg}}
#' \item \dQuote{bruto}, see \code{\link[mda]{bruto}}
#' \item \dQuote{clm}, see \code{\link[ordinal]{clm}}
Expand Down Expand Up @@ -75,7 +75,7 @@
#' \item \dQuote{zeroinfl}, see \code{\link[pscl]{zeroinfl}}
#' }
#'
#' Where implemented, \code{prediction} also returns average predictions (and the variances thereof). Variances are implemented using the delta method, as described in \url{http://indiana.edu/~jslsoc/stata/ci_computations/spost_deltaci.pdf}.
#' Where implemented, \code{prediction} also returns average predictions (and the variances thereof). Variances are implemented using the delta method, as described by Xu and Long 2005 \doi{10.1177/1536867X0500500405}.
#'
#' @return A data frame with class \dQuote{prediction} that has a number of rows equal to number of rows in \code{data}, or a multiple thereof, if \code{!is.null(at)}. The return value contains \code{data} (possibly modified by \code{at} using \code{\link{build_datalist}}), plus a column containing fitted/predicted values (\code{"fitted"}) and a column containing the standard errors thereof (\code{"calculate_se"}). Additional columns may be reported depending on the object class. The data frame also carries attributes used by \code{print} and \code{summary}, which will be lost during subsetting.
#' @examples
Expand All @@ -97,14 +97,21 @@
#' prediction(x, at = lapply(iris, mean_or_mode))
#'
#' # prediction with multi-category outcome
#' \dontrun{
#' library("mlogit")
#' data("Fishing", package = "mlogit")
#' Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
#' mod <- mlogit(mode ~ price + catch, data = Fish)
#' prediction(mod)
#' prediction(mod, category = 3)
#' if (requireNamespace("mlogit")) {
#' data("Fishing", package = "mlogit")
#' Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
#' mod <- mlogit(mode ~ price + catch, data = Fish)
#' prediction(mod)
#' prediction(mod, category = 3)
#' }
#'
#' # standard errors of predictions for GLMs
#' m1 <- glm(breaks ~ wool * tension, data = warpbreaks, family = poisson)
#' p1 <- prediction(m1,
#' at = with(warpbreaks,
#' list(wool = levels(wool), tension= levels(tension))))
#' ss <- summary(p1)
#' print(ss)
#'
#' @keywords models
#' @seealso \code{\link{find_data}}, \code{\link{build_datalist}}, \code{\link{mean_or_mode}}, \code{\link{seq_range}}
Expand Down
6 changes: 3 additions & 3 deletions R/prediction_bigFastLm.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.bigLm <-
function(model,
data = NULL,
Expand Down Expand Up @@ -35,4 +35,4 @@ function(model,
vcov = vc,
jacobian = NULL,
weighted = FALSE)
}
}
4 changes: 2 additions & 2 deletions R/prediction_bigglm.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.bigglm <-
function(model,
data = find_data(model, parent.frame()),
Expand Down
4 changes: 2 additions & 2 deletions R/prediction_lda.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.lda <-
function(model,
data = find_data(model, parent.frame()),
Expand Down
4 changes: 2 additions & 2 deletions R/prediction_mlogit.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.mlogit <-
function(model,
data = find_data(model, parent.frame()),
Expand Down
6 changes: 3 additions & 3 deletions R/prediction_mnlogit.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.mnlogit <-
function(model,
data = find_data(model, parent.frame()),
Expand Down Expand Up @@ -61,4 +61,4 @@ function(model,
jacobian = NULL,
category = category,
weighted = FALSE)
}
}
4 changes: 2 additions & 2 deletions R/prediction_naiveBayes.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.naiveBayes <-
function(model,
data = find_data(model, parent.frame()),
Expand Down
4 changes: 2 additions & 2 deletions R/prediction_qda.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.qda <-
function(model,
data = find_data(model, parent.frame()),
Expand Down
4 changes: 2 additions & 2 deletions R/prediction_tree.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.tree <-
function(model,
data = find_data(model, parent.frame()),
Expand Down
4 changes: 2 additions & 2 deletions R/prediction_vgam.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.vgam <-
function(model,
data = find_data(model, parent.frame()),
Expand Down
4 changes: 2 additions & 2 deletions R/prediction_vglm.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @rdname prediction
# @export
#' @rdname prediction
#' @export
prediction.vglm <-
function(model,
data = find_data(model, parent.frame()),
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ output: github_document

<img src="man/figures/logo.png" align="right" />

The **prediction** and **margins** packages are a combined effort to port the functionality of Stata's (closed source) [`margins`](http://www.stata.com/help.cgi?margins) command to (open source) R. **prediction** is focused on one function - `prediction()` - that provides type-safe methods for generating predictions from fitted regression models. `prediction()` is an S3 generic, which always return a `"data.frame"` class object rather than the mix of vectors, lists, etc. that are returned by the `predict()` methods for various model types. It provides a key piece of underlying infrastructure for the **margins** package. Users interested in generating marginal (partial) effects, like those generated by Stata's `margins, dydx(*)` command, should consider using `margins()` from the sibling project, [**margins**](https://cran.r-project.org/package=margins).
The **prediction** and **margins** packages are a combined effort to port the functionality of Stata's (closed source) [`margins`](https://www.stata.com/help.cgi?margins) command to (open source) R. **prediction** is focused on one function - `prediction()` - that provides type-safe methods for generating predictions from fitted regression models. `prediction()` is an S3 generic, which always return a `"data.frame"` class object rather than the mix of vectors, lists, etc. that are returned by the `predict()` methods for various model types. It provides a key piece of underlying infrastructure for the **margins** package. Users interested in generating marginal (partial) effects, like those generated by Stata's `margins, dydx(*)` command, should consider using `margins()` from the sibling project, [**margins**](https://cran.r-project.org/package=margins).

In addition to `prediction()`, this package provides a number of utility functions for generating useful predictions:

Expand Down Expand Up @@ -170,10 +170,9 @@ The currently supported model classes are:

[![CRAN](https://www.r-pkg.org/badges/version/prediction)](https://cran.r-project.org/package=prediction)
![Downloads](https://cranlogs.r-pkg.org/badges/prediction)
[![Build Status](https://travis-ci.org/leeper/prediction.svg?branch=master)](https://travis-ci.org/leeper/prediction)
[![Build status](https://ci.appveyor.com/api/projects/status/a4tebeoa98cq07gy/branch/master?svg=true)](https://ci.appveyor.com/project/leeper/prediction/branch/master)
[![codecov.io](https://codecov.io/github/leeper/prediction/coverage.svg?branch=master)](https://codecov.io/github/leeper/prediction?branch=master)
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![codecov.io](https://app.codecov.io/github/leeper/prediction?branch=master)](https://app.codecov.io/github/leeper/prediction?branch=master)
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)

The development version of this package can be installed directly from GitHub using `remotes`:

Expand Down
15 changes: 0 additions & 15 deletions inst/CITATION

This file was deleted.

3 changes: 3 additions & 0 deletions man/find_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions man/margex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading