Skip to content

Commit

Permalink
add prediction.gls() (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeper committed Sep 1, 2016
1 parent f72c16e commit 86b8a88
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 4,8 @@ Title: Marginal Effects for Model Objects
Description: An R port of Stata's 'margins' command, which can be used to
calculate marginal (or partial) effects from model objects.
License: MIT file LICENSE
Version: 0.2.10
Date: 2016-08-31
Version: 0.2.11
Date: 2016-09-01
Authors@R: c(person("Thomas J.", "Leeper",
role = c("aut", "cre"),
email = "[email protected]"))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 18,7 @@ S3method(plot,margins)
S3method(plot,marginslist)
S3method(prediction,coxph)
S3method(prediction,glm)
S3method(prediction,gls)
S3method(prediction,ivreg)
S3method(prediction,lm)
S3method(prediction,loess)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 1,9 @@
# CHANGES TO margins 0.3.0 #

## margins 0.2.11

* Added a `prediction()` method for "gls" objects (from `MASS::gls()`). (#3)

## margins 0.2.10

* Replaced `numDeriv::jacobian()` with an internal alternative. (#41)
Expand Down
1 change: 1 addition & 0 deletions R/prediction.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,7 @@
#' \itemize{
#' \item \dQuote{lm}, see \code{\link[stats]{lm}}
#' \item \dQuote{glm}, see \code{\link[stats]{glm}}, \code{\link[MASS]{glm.nb}}
#' \item \dQuote{gls}, see \code{\link[MASS]{gls}}
#' \item \dQuote{polr}, see \code{\link[MASS]{polr}}
#' \item \dQuote{loess}, see \code{\link[stats]{loess}}
#' \item \dQuote{ivreg}, see \code{\link[AER]{ivreg}}
Expand Down
19 changes: 19 additions & 0 deletions R/prediction_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 191,25 @@ prediction.coxph <- function(model, data, type = c("risk", "expected", "lp"), ..
type = type)
}

#' @rdname prediction
#' @export
prediction.gls <- function(model, data, ...) {

# extract predicted value at input value (value can only be 1 number)
pred <- data.frame(fit = predict(model, newdata = data, type = "class", ...))
pred[["se.fit"]] <- NA_real_
class(pred[["fit"]]) <- c("fit", class(pred[["fit"]]))
class(pred[["se.fit"]]) <- c("se.fit", "numeric")

# obs-x-2 data.frame of predictions
structure(list(fitted = pred[["fit"]],
se.fitted = pred[["se.fit"]]),
class = c("prediction", "data.frame"),
row.names = seq_len(length(pred[["fit"]])),
model.class = class(model),
type = NULL)
}

#' @rdname prediction
#' @export
prediction.polr <- function(model, data, ...) {
Expand Down
4 changes: 4 additions & 0 deletions man/prediction.Rd

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

0 comments on commit 86b8a88

Please sign in to comment.