forked from leeper/prediction
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prediction.ridgeLinear without se.fit
- Loading branch information
Showing
5 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ 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. | ||
License: MIT + file LICENSE | ||
Version: 0.3.15 | ||
Date: 2019-12-24 | ||
Version: 0.3.16 | ||
Date: 2020-03-18 | ||
Authors@R: c(person("Thomas J.", "Leeper", | ||
role = c("aut", "cre"), | ||
email = "[email protected]", | ||
|
@@ -13,7 +13,8 @@ Authors@R: c(person("Thomas J.", "Leeper", | |
email = "[email protected]"), | ||
person("Vincent", "Arel-Bundock", role = "ctb", | ||
email = "[email protected]", | ||
comment = c(ORCID = "0000-0003-2042-7063")) | ||
comment = c(ORCID = "0000-0003-2042-7063")), | ||
person("Dan", "Frankowski", role = "ctb") | ||
) | ||
URL: https://github.com/leeper/prediction | ||
BugReports: https://github.com/leeper/prediction/issues | ||
|
@@ -55,6 +56,7 @@ Enhances: | |
plm, | ||
pscl, | ||
quantreg, | ||
ridge (>= 2.5), | ||
rpart, | ||
sampleSelection, | ||
speedglm, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Like prediction.default, but without calculate_se | ||
|
||
#' @rdname prediction | ||
#' @export | ||
prediction.ridgeLinear <- | ||
function(model, | ||
data = find_data(model, parent.frame()), | ||
at = NULL, | ||
type = "response", | ||
vcov = stats::vcov(model), | ||
calculate_se = FALSE, | ||
...) { | ||
if (calculate_se) { | ||
stop(paste0("calculate_se not implemented")) | ||
} | ||
# extract predicted values | ||
data <- data | ||
if (missing(data) || is.null(data)) { | ||
pred <- predict(model, type = type, ...) | ||
pred <- make_data_frame(fitted = pred, se.fitted = rep(NA_real_, length(pred))) | ||
} else { | ||
# setup data | ||
if (!is.null(at)) { | ||
data <- build_datalist(data, at = at, as.data.frame = TRUE) | ||
at_specification <- attr(data, "at_specification") | ||
} | ||
# calculate predictions | ||
tmp <- predict(model, newdata = data, type = type, ...) | ||
# cbind back together | ||
pred <- make_data_frame(data, fitted = tmp, se.fitted = rep(NA_real_, nrow(data))) | ||
} | ||
|
||
# variance(s) of average predictions | ||
J <- NULL | ||
vc <- NA_real_ | ||
|
||
# output | ||
structure(pred, | ||
class = c("prediction", "data.frame"), | ||
at = if (is.null(at)) at else at_specification, | ||
type = type, | ||
call = if ("call" %in% names(model)) model[["call"]] else NULL, | ||
model_class = class(model), | ||
row.names = seq_len(nrow(pred)), | ||
vcov = vc, | ||
jacobian = J, | ||
weighted = FALSE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters