diff --git a/.aspell/defaults.R b/.aspell/defaults.R new file mode 100644 index 0000000..dd66851 --- /dev/null +++ b/.aspell/defaults.R @@ -0,0 +1,4 @@ +Rd_files <- vignettes <- R_files <- description <- + list(encoding = "UTF-8", + language = "en", + dictionaries = c("en_stats", "mydict")) diff --git a/.aspell/mydict.rds b/.aspell/mydict.rds new file mode 100644 index 0000000..071acbb Binary files /dev/null and b/.aspell/mydict.rds differ diff --git a/.gitignore b/.gitignore index 7232f73..0d3ce05 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ README.html /vignettes/figure/ /vignettes/*.bib.bak /revdep/ +\#* +.#* diff --git a/DESCRIPTION b/DESCRIPTION index cde7b57..6eb575b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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' . 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' . 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, @@ -37,7 +36,6 @@ Enhances: e1071, earth, ff, - ffbase, gam (>= 1.15), gee, glmnet, @@ -64,4 +62,4 @@ Enhances: VGAM ByteCompile: true Encoding: UTF-8 -RoxygenNote: 7.0.2 +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index 3daf9dc..ed65eb4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) @@ -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) @@ -56,8 +60,11 @@ 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) @@ -65,6 +72,7 @@ S3method(prediction,polr) S3method(prediction,polyreg) S3method(prediction,ppr) S3method(prediction,princomp) +S3method(prediction,qda) S3method(prediction,rlm) S3method(prediction,rpart) S3method(prediction,rq) @@ -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) diff --git a/NEWS.md b/NEWS.md index 5c186bc..695184e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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) diff --git a/R/find_data.R b/R/find_data.R index a9d1e6a..1858d65 100644 --- a/R/find_data.R +++ b/R/find_data.R @@ -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 diff --git a/R/margex.R b/R/margex.R index 7169129..c6fc358 100644 --- a/R/margex.R +++ b/R/margex.R @@ -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{ #' diff --git a/R/prediction.R b/R/prediction.R index 3ca09d3..81e8292 100644 --- a/R/prediction.R +++ b/R/prediction.R @@ -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}} @@ -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 @@ -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}} diff --git a/R/prediction_bigFastLm.R b/R/prediction_bigFastLm.R index 11e7a5a..7494c5b 100644 --- a/R/prediction_bigFastLm.R +++ b/R/prediction_bigFastLm.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.bigLm <- function(model, data = NULL, @@ -35,4 +35,4 @@ function(model, vcov = vc, jacobian = NULL, weighted = FALSE) -} \ No newline at end of file +} diff --git a/R/prediction_bigglm.R b/R/prediction_bigglm.R index 88b7522..fc0cffc 100644 --- a/R/prediction_bigglm.R +++ b/R/prediction_bigglm.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.bigglm <- function(model, data = find_data(model, parent.frame()), diff --git a/R/prediction_lda.R b/R/prediction_lda.R index 1d1f00d..6758e00 100644 --- a/R/prediction_lda.R +++ b/R/prediction_lda.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.lda <- function(model, data = find_data(model, parent.frame()), diff --git a/R/prediction_mlogit.R b/R/prediction_mlogit.R index 88903c5..d6fb5dd 100644 --- a/R/prediction_mlogit.R +++ b/R/prediction_mlogit.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.mlogit <- function(model, data = find_data(model, parent.frame()), diff --git a/R/prediction_mnlogit.R b/R/prediction_mnlogit.R index c23c7cd..fbbc281 100644 --- a/R/prediction_mnlogit.R +++ b/R/prediction_mnlogit.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.mnlogit <- function(model, data = find_data(model, parent.frame()), @@ -61,4 +61,4 @@ function(model, jacobian = NULL, category = category, weighted = FALSE) -} \ No newline at end of file +} diff --git a/R/prediction_naiveBayes.R b/R/prediction_naiveBayes.R index 42f5153..1d19d38 100644 --- a/R/prediction_naiveBayes.R +++ b/R/prediction_naiveBayes.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.naiveBayes <- function(model, data = find_data(model, parent.frame()), diff --git a/R/prediction_qda.R b/R/prediction_qda.R index db99fd9..ea67aae 100644 --- a/R/prediction_qda.R +++ b/R/prediction_qda.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.qda <- function(model, data = find_data(model, parent.frame()), diff --git a/R/prediction_tree.R b/R/prediction_tree.R index 33b2ed8..3a3f756 100644 --- a/R/prediction_tree.R +++ b/R/prediction_tree.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.tree <- function(model, data = find_data(model, parent.frame()), diff --git a/R/prediction_vgam.R b/R/prediction_vgam.R index 3c885b2..e6ecfee 100644 --- a/R/prediction_vgam.R +++ b/R/prediction_vgam.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.vgam <- function(model, data = find_data(model, parent.frame()), diff --git a/R/prediction_vglm.R b/R/prediction_vglm.R index af8f4ce..eeffd05 100644 --- a/R/prediction_vglm.R +++ b/R/prediction_vglm.R @@ -1,5 +1,5 @@ -# @rdname prediction -# @export +#' @rdname prediction +#' @export prediction.vglm <- function(model, data = find_data(model, parent.frame()), diff --git a/README.md b/README.md index 20612b4..d019770 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ output: github_document -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: @@ -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`: diff --git a/inst/CITATION b/inst/CITATION deleted file mode 100644 index a2dfe3d..0000000 --- a/inst/CITATION +++ /dev/null @@ -1,15 +0,0 @@ -citHeader("To cite package 'prediction' in publications use:") - - year <- sub(".*(2[[:digit:]]{3})-.*", "\\1", meta$Date, perl = TRUE) - vers <- paste("R package version", meta$Version) - - citEntry(entry="Manual", - title = "prediction: Tidy, Type-Safe 'prediction()' Methods", - author = personList(as.person("Thomas J. Leeper")), - year = year, - note = vers, - textVersion = - paste("Thomas J. Leeper (", - year, - "). prediction: Tidy, Type-Safe 'prediction()' Methods. ", - vers, ".", sep="")) \ No newline at end of file diff --git a/man/find_data.Rd b/man/find_data.Rd index c8315c0..8ccc504 100644 --- a/man/find_data.Rd +++ b/man/find_data.Rd @@ -6,6 +6,7 @@ \alias{find_data.data.frame} \alias{find_data.crch} \alias{find_data.glimML} +\alias{find_data.glimQL} \alias{find_data.glm} \alias{find_data.hxlr} \alias{find_data.lm} @@ -27,6 +28,8 @@ find_data(model, ...) \method{find_data}{glimML}(model, ...) +\method{find_data}{glimQL}(model, env = parent.frame(), ...) + \method{find_data}{glm}(model, env = parent.frame(), ...) \method{find_data}{hxlr}(model, env = parent.frame(), ...) diff --git a/man/margex.Rd b/man/margex.Rd index 45ed257..a3ee228 100644 --- a/man/margex.Rd +++ b/man/margex.Rd @@ -4,7 +4,8 @@ \name{margex} \alias{margex} \title{Artificial data for margins, copied from Stata} -\format{A data frame with 3000 observations on the following 11 variables. +\format{ +A data frame with 3000 observations on the following 11 variables. \describe{ \item{\samp{y}}{A numeric vector} \item{\samp{outcome}}{A binary numeric vector with values (0,1)} @@ -17,12 +18,13 @@ \item{\samp{treatment}}{A factor with two levels} \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} +\url{https://www.stata-press.com/data/r14/margex.dta} } \usage{ -margex +data("margex") } \description{ The dataset is identical to the one provided by Stata and available from \code{webuse::webuse("margex")} with categorical variables explicitly encoded as factors. diff --git a/man/prediction.Rd b/man/prediction.Rd index 801b7e7..2f7ca83 100644 --- a/man/prediction.Rd +++ b/man/prediction.Rd @@ -1,24 +1,27 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/prediction.R, R/prediction_Arima.R, % R/prediction_ar.R, R/prediction_arima0.R, R/prediction_betareg.R, -% R/prediction_biglm.R, R/prediction_bruto.R, R/prediction_clm.R, -% R/prediction_coxph.R, R/prediction_crch.R, R/prediction_earth.R, -% R/prediction_fda.R, R/prediction_gam.R, R/prediction_gausspr.R, -% R/prediction_gee.R, R/prediction_glimML.R, R/prediction_glimQL.R, -% R/prediction_glm.R, R/prediction_glmnet.R, R/prediction_glmx.R, -% R/prediction_gls.R, R/prediction_hetglm.R, R/prediction_hurdle.R, -% R/prediction_hxlr.R, R/prediction_ivreg.R, R/prediction_knnreg.R, -% R/prediction_kqr.R, R/prediction_ksvm.R, R/prediction_lm.R, +% R/prediction_bigFastLm.R, R/prediction_bigglm.R, R/prediction_biglm.R, +% R/prediction_bruto.R, R/prediction_clm.R, R/prediction_coxph.R, +% R/prediction_crch.R, R/prediction_earth.R, R/prediction_fda.R, +% R/prediction_gam.R, R/prediction_gausspr.R, R/prediction_gee.R, +% R/prediction_glimML.R, R/prediction_glimQL.R, R/prediction_glm.R, +% R/prediction_glmnet.R, R/prediction_glmx.R, R/prediction_gls.R, +% R/prediction_hetglm.R, R/prediction_hurdle.R, R/prediction_hxlr.R, +% R/prediction_ivreg.R, R/prediction_knnreg.R, R/prediction_kqr.R, +% R/prediction_ksvm.R, R/prediction_lda.R, R/prediction_lm.R, % R/prediction_lme.R, R/prediction_loess.R, R/prediction_lqs.R, % R/prediction_mars.R, R/prediction_mca.R, R/prediction_mclogit.R, -% R/prediction_merMod.R, R/prediction_mnp.R, R/prediction_multinom.R, +% R/prediction_merMod.R, R/prediction_mlogit.R, R/prediction_mnlogit.R, +% R/prediction_mnp.R, R/prediction_multinom.R, R/prediction_naiveBayes.R, % R/prediction_nls.R, R/prediction_nnet.R, R/prediction_plm.R, % R/prediction_polr.R, R/prediction_polyreg.R, R/prediction_ppr.R, -% R/prediction_princomp.R, R/prediction_rlm.R, R/prediction_rpart.R, -% R/prediction_rq.R, R/prediction_selection.R, R/prediction_speedglm.R, -% R/prediction_speedlm.R, R/prediction_survreg.R, R/prediction_svm.R, -% R/prediction_svyglm.R, R/prediction_train.R, R/prediction_truncreg.R, -% R/prediction_zeroinfl.R, R/summary.R +% R/prediction_princomp.R, R/prediction_qda.R, R/prediction_rlm.R, +% R/prediction_rpart.R, R/prediction_rq.R, R/prediction_selection.R, +% R/prediction_speedglm.R, R/prediction_speedlm.R, R/prediction_survreg.R, +% R/prediction_svm.R, R/prediction_svyglm.R, R/prediction_train.R, +% R/prediction_tree.R, R/prediction_truncreg.R, R/prediction_vgam.R, +% R/prediction_vglm.R, R/prediction_zeroinfl.R, R/summary.R \name{prediction-package} \alias{prediction-package} \alias{prediction} @@ -27,6 +30,8 @@ \alias{prediction.ar} \alias{prediction.arima0} \alias{prediction.betareg} +\alias{prediction.bigLm} +\alias{prediction.bigglm} \alias{prediction.biglm} \alias{prediction.bruto} \alias{prediction.clm} @@ -50,6 +55,7 @@ \alias{prediction.knnreg} \alias{prediction.kqr} \alias{prediction.ksvm} +\alias{prediction.lda} \alias{prediction.lm} \alias{prediction.lme} \alias{prediction.loess} @@ -58,8 +64,11 @@ \alias{prediction.mca} \alias{prediction.mclogit} \alias{prediction.merMod} +\alias{prediction.mlogit} +\alias{prediction.mnlogit} \alias{prediction.mnp} \alias{prediction.multinom} +\alias{prediction.naiveBayes} \alias{prediction.nls} \alias{prediction.nnet} \alias{prediction.plm} @@ -67,6 +76,7 @@ \alias{prediction.polyreg} \alias{prediction.ppr} \alias{prediction.princomp} +\alias{prediction.qda} \alias{prediction.rlm} \alias{prediction.rpart} \alias{prediction.rq} @@ -77,7 +87,10 @@ \alias{prediction.svm} \alias{prediction.svyglm} \alias{prediction.train} +\alias{prediction.tree} \alias{prediction.truncreg} +\alias{prediction.vgam} +\alias{prediction.vglm} \alias{prediction.zeroinfl} \alias{prediction_summary} \title{Extract Predictions from a Model Object} @@ -109,6 +122,17 @@ prediction(model, ...) ... ) +\method{prediction}{bigLm}(model, data = NULL, calculate_se = FALSE, ...) + +\method{prediction}{bigglm}( + model, + data = find_data(model, parent.frame()), + at = NULL, + type = "response", + calculate_se = TRUE, + ... +) + \method{prediction}{biglm}( model, data = find_data(model, parent.frame()), @@ -300,6 +324,15 @@ prediction(model, ...) ... ) +\method{prediction}{lda}( + model, + data = find_data(model, parent.frame()), + at = NULL, + calculate_se = FALSE, + category, + ... +) + \method{prediction}{lm}( model, data = find_data(model, parent.frame()), @@ -372,6 +405,24 @@ prediction(model, ...) ... ) +\method{prediction}{mlogit}( + model, + data = find_data(model, parent.frame()), + at = NULL, + calculate_se = FALSE, + category, + ... +) + +\method{prediction}{mnlogit}( + model, + data = find_data(model, parent.frame()), + at = NULL, + calculate_se = FALSE, + category, + ... +) + \method{prediction}{mnp}( model, data = find_data(model, parent.frame()), @@ -392,6 +443,16 @@ prediction(model, ...) ... ) +\method{prediction}{naiveBayes}( + model, + data = find_data(model, parent.frame()), + at = NULL, + type = NULL, + calculate_se = FALSE, + category, + ... +) + \method{prediction}{nls}( model, data = find_data(model, parent.frame()), @@ -453,6 +514,15 @@ prediction(model, ...) ... ) +\method{prediction}{qda}( + model, + data = find_data(model, parent.frame()), + at = NULL, + calculate_se = FALSE, + category, + ... +) + \method{prediction}{rlm}( model, data = find_data(model, parent.frame()), @@ -535,8 +605,38 @@ prediction(model, ...) ... ) +\method{prediction}{tree}( + model, + data = find_data(model, parent.frame()), + at = NULL, + type = NULL, + calculate_se = FALSE, + category, + ... +) + \method{prediction}{truncreg}(model, data, at = NULL, calculate_se = FALSE, ...) +\method{prediction}{vgam}( + model, + data = find_data(model, parent.frame()), + at = NULL, + type = c("response", "link"), + calculate_se = FALSE, + category, + ... +) + +\method{prediction}{vglm}( + model, + data = find_data(model, parent.frame()), + at = NULL, + type = c("response", "link"), + calculate_se = TRUE, + category, + ... +) + \method{prediction}{zeroinfl}( model, data = find_data(model, parent.frame()), @@ -587,7 +687,7 @@ Methods are currently implemented for the following object classes: \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}} @@ -643,7 +743,7 @@ Methods are currently implemented for the following object classes: \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}. } \examples{ require("datasets") @@ -664,15 +764,22 @@ prediction(x, at = list(Sepal.Length = seq_range(iris$Sepal.Length, 5))) 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) + } \seealso{ \code{\link{find_data}}, \code{\link{build_datalist}}, \code{\link{mean_or_mode}}, \code{\link{seq_range}}