-
Notifications
You must be signed in to change notification settings - Fork 0
Add more statistics to the output table #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -67,3 +67,19 @@ mape <- function (obs, pred) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| mpe <- function (obs, pred) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sum((obs - pred)/obs)/length(obs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #' Weighted sum-of-squares of residuals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #' @inheritParams rmse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #' @param w weights | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
mccarthy-m-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ss <- function(obs, pred, w = NULL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(is.null(w)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| w <- rep(1, length(obs)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (length(obs) != length(pred) || length(obs) != length(w)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cli::cli_abort("`obs`, `pred`, and `w` must have the same length") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(sum(w) == 0) return(NA) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sum(w * (obs - pred)^2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+71
to
+85
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion for something more concise (you can take or leave). ss(obs = 1:5, pred = 5:1, w = 1:3)
#> Error in `ss()`:
#> ! Can't recycle `obs` (size 5) to match `w` (size 3).
Suggested change
Here are some tests you could add for this too: test_that("recycling + incompatible size error works", {
expect_equal(ss(obs = 1:3, pred = 3:1, w = 1), 8)
expect_equal(ss(obs = 1:3, pred = 3:1, w = c(1, 1, 0.5)), 6)
expect_error(
ss(obs = 1:5, pred = 5:1, w = 1:3), class = "vctrs_error_incompatible_size"
)
}) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.