diff --git a/DESCRIPTION b/DESCRIPTION index 5f60e19..c4c7141 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,10 @@ Authors@R: c(person("Thomas J.", "Leeper", email = "thosjleeper@gmail.com", comment = c(ORCID = "0000-0003-4097-6326")), person("Carl", "Ganz", role = "ctb", - email = "carlganz@ucla.edu") + email = "carlganz@ucla.edu"), + person("Vincent", "Arel-Bundock", role = "ctb", + email = "vincent.arel-bundock@umontreal.ca", + comment = c(ORCID = "0000-0003-2042-7063")) ) URL: https://github.com/leeper/prediction BugReports: https://github.com/leeper/prediction/issues diff --git a/NEWS.md b/NEWS.md index da851b5..2bc7259 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# prediction 0.3.13 + +* Fixed a bug in `prediction_glm` with the `data` argument (Issue #32). + # prediction 0.3.12 * Remove mnlogit dependency, as it has been removed from CRAN. diff --git a/R/prediction_glm.R b/R/prediction_glm.R index d268169..5e00ffa 100644 --- a/R/prediction_glm.R +++ b/R/prediction_glm.R @@ -51,7 +51,7 @@ function(model, if (type == "link") { means_for_prediction <- colMeans(model_mat) } else if (type == "response") { - predictions_link <- predict(model, data = data, type = "link", se.fit = FALSE, ...) + predictions_link <- predict(model, newdata = data, type = "link", se.fit = FALSE, ...) means_for_prediction <- colMeans(model$family$mu.eta(predictions_link) * model_mat) } J <- matrix(means_for_prediction, nrow = 1L) @@ -64,7 +64,7 @@ function(model, if (type == "link") { means_for_prediction <- colMeans(model_mat) } else if (type == "response") { - predictions_link <- predict(model, data = one, type = "link", se.fit = FALSE, ...) + predictions_link <- predict(model, newdata = one, type = "link", se.fit = FALSE, ...) means_for_prediction <- colMeans(model$family$mu.eta(predictions_link) * model_mat) } means_for_prediction diff --git a/tests/testthat/tests-core.R b/tests/testthat/tests-core.R index d86e75b..3615308 100644 --- a/tests/testthat/tests-core.R +++ b/tests/testthat/tests-core.R @@ -19,6 +19,16 @@ test_that("Test prediction()", { label = "prediction() matches predict() (GLM)") }) +test_that("Test prediction(data = )", { + m <- lm(mpg ~ cyl + wt, data = mtcars) + p1 <- prediction(m, data = data.frame(cyl = 4, wt = 3.9)) + expect_true(inherits(p1, "data.frame"), label = "prediction(lm(~), data = data.frame()) works") + + m <- glm(mpg ~ cyl + wt, data = mtcars) + p1 <- prediction(m, data = data.frame(cyl = 4, wt = 3.9)) + expect_true(inherits(p1, "data.frame"), label = "prediction(glm(~), data = data.frame()) works") +}) + test_that("Test prediction(at = )", { m <- lm(mpg ~ cyl, data = mtcars) p1 <- prediction(m, at = list(cyl = 4))