Skip to content

Commit

Permalink
version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jobstdavid committed Sep 30, 2023
1 parent e6a95e2 commit 5626d38
Show file tree
Hide file tree
Showing 86 changed files with 1,795 additions and 1,111 deletions.
Binary file modified .DS_Store
Binary file not shown.
646 changes: 486 additions & 160 deletions .Rhistory

Large diffs are not rendered by default.

Binary file added .github/.DS_Store
Binary file not shown.
29 changes: 10 additions & 19 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
Expand All @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -29,30 +29,21 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v1

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
inst/doc
.Rproj.user

*.o
*.so
18 changes: 13 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
Package: eppverification
Type: Package
Title: Verification Tools for the Statistical Postprocessing of Ensemble Forecasts
Version: 0.2.0
Version: 0.3.0
Authors@R: c(
person(given = "David",
family = "Jobst",
role = c("aut", "cre"),
email = "jobst@imai.uni-hildesheim.de",
email = "jobstd@uni-hildesheim.de",
comment = c(DOI = "10.5281/zenodo.5574572")))
Maintainer: David Jobst <jobst@imai.uni-hildesheim.de>
Maintainer: David Jobst <jobstd@uni-hildesheim.de>
Description: This package provides user-friendly univariate and multivariate verification tools for the statistical ensemble post-processing. It allows to score and assess the calibration (reliability) and sharpness of ensemble forecasts and predictive distributions. In addition this package can be used to create useful contemporary visualizations for verification.
URL: https://github.com/jobstdavid/eppverification
BugReports: https://github.com/jobstdavid/eppverification/issues
Imports: ggplot2, ggmap, fields, vegan, pcaPP
Imports:
ggplot2,
fields,
vegan,
pcaPP,
Rfast,
Rcpp
License: GPL (>= 3) + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0)
LinkingTo:
Rcpp, RcppArmadillo
26 changes: 14 additions & 12 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(ae)
export(box.plot)
export(bh.test)
export(bs)
export(cov.plot)
export(cpi)
Expand All @@ -16,7 +16,6 @@ export(es)
export(line.plot)
export(logs)
export(m.pit)
export(map.plot)
export(ment)
export(mri)
export(mrnk)
Expand All @@ -28,18 +27,22 @@ export(rmv)
export(rnk)
export(score.plot)
export(se)
export(ss)
export(var.pit)
export(vr.hist)
export(vs)
importFrom(Rcpp,sourceCpp)
importFrom(Rfast,colmeans)
importFrom(Rfast,cova)
importFrom(Rfast,rowMedians)
importFrom(Rfast,rowVars)
importFrom(Rfast,rowmeans)
importFrom(Rfast,rowsums)
importFrom(fields,rdist)
importFrom(ggmap,calc_zoom)
importFrom(ggmap,get_stamenmap)
importFrom(ggmap,ggmap)
importFrom(ggmap,make_bbox)
importFrom(ggplot2,aes)
importFrom(ggplot2,after_stat)
importFrom(ggplot2,element_text)
importFrom(ggplot2,geom_abline)
importFrom(ggplot2,geom_boxplot)
importFrom(ggplot2,geom_histogram)
importFrom(ggplot2,geom_hline)
importFrom(ggplot2,geom_line)
Expand All @@ -52,23 +55,22 @@ importFrom(ggplot2,ggtitle)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_color_manual)
importFrom(ggplot2,scale_fill_gradient)
importFrom(ggplot2,scale_fill_manual)
importFrom(ggplot2,scale_linetype_manual)
importFrom(ggplot2,scale_shape_manual)
importFrom(ggplot2,scale_size_manual)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_x_discrete)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,scale_y_discrete)
importFrom(ggplot2,stat)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_bw)
importFrom(ggplot2,xlab)
importFrom(ggplot2,ylab)
importFrom(pcaPP,l1median_VaZh)
importFrom(stats,acf)
importFrom(stats,complete.cases)
importFrom(stats,median)
importFrom(stats,pnorm)
importFrom(stats,na.omit)
importFrom(stats,pt)
importFrom(stats,setNames)
importFrom(stats,var)
importFrom(vegan,spantree)
useDynLib(eppverification, .registration = TRUE)
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# eppverification 0.3.0 (September 30, 2023)

- univariate and multivariate score calculation is speeded-up using C++ code by the R-packages `Rfast`, `Rcpp`, `RcppArmadillo`.
- new function `bh.test` to perform a Benjamini-Hochberg-Correction for different p-values.
- new function `ss` to calculate the skill score.
- fast calculation of the sample covariance matrix for the determinate sharpness `ds`.
- change test statistic in `dm.test`.
- better handling of NA values in the verification functions.
- changed `stat` to `after_stat` in `ggplot2` based functions.
- removed the functions `map.plot` and `box.plot`.


# eppverification 0.2.0 (Januar 9, 2022)

- new function `dm.test` to perform a Diebold-Mariano-Test for two forecasts.
Expand Down
Empty file added R/.Rhistory
Empty file.
35 changes: 35 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

crps_cpp <- function(y, x) {
.Call(`_eppverification_crps_cpp`, y, x)
}

crps_sml_cpp <- function(y, x) {
.Call(`_eppverification_crps_sml_cpp`, y, x)
}

crps_mc_cpp <- function(y, x) {
.Call(`_eppverification_crps_mc_cpp`, y, x)
}

euclnorm_cpp <- function(x) {
.Call(`_eppverification_euclnorm_cpp`, x)
}

es_cpp <- function(y, x) {
.Call(`_eppverification_es_cpp`, y, x)
}

es_mc_cpp <- function(y, x) {
.Call(`_eppverification_es_mc_cpp`, y, x)
}

vs_cpp <- function(y, x, w, p) {
.Call(`_eppverification_vs_cpp`, y, x, w, p)
}

ds_cpp <- function(x) {
.Call(`_eppverification_ds_cpp`, x)
}

31 changes: 11 additions & 20 deletions R/ae.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param y vector of observations
#' @param x matrix of ensemble forecasts/samples of a predictive distribution or vector of medians of ensemble forecasts/a predictive distribution (depending on \code{y}; see details)
#' @param mean logical; if \code{TRUE} the mean of the AE values is calculated for output; if \code{FALSE} the single AE values are used as output; default: \code{FALSE}
#' @param na.rm logical; if \code{TRUE} NA are removed after the computation; if \code{FALSE} NA are used in the computation; default: \code{FALSE}
#'
#' @details
#' For a vector \code{y} of length n, \code{x} can be given as matrix of ensemble forecasts/samples of a predictive distribution
Expand All @@ -15,7 +16,6 @@
#' If the medians of ensemble forecasts or of a predictive distribution are directly
#' available, \code{x} can be given as vector of medians, where
#' the i-th entry of \code{y} belongs to the i-th entry of \code{x}.
#' Only finite values of \code{y} and \code{x} are used.
#'
#' In addition, with this function, the Mean Absolute Error (MAE) can be calculated.
#'
Expand Down Expand Up @@ -46,50 +46,41 @@
#'
#' @rdname ae
#'
#' @importFrom stats median
#' @importFrom stats median na.omit
#' @importFrom Rfast rowMedians
#'
#' @export
ae <- function(y, x, mean = FALSE) {
ae <- function(y, x, mean = FALSE, na.rm = FALSE) {
if (!is.vector(y)) {
stop("'y' should be a vector!")
}
if (is.matrix(x)) {
if (length(y) != nrow(x)) {
stop("Length of 'y' is not equal to the number of rows of 'x'!")
}
index <- which(is.finite(y))
y <- y[index]
x <- x[index, ]

med <- apply(x, 1, median.i)
med <- rowMedians(x = x, parallel = TRUE, na.rm = FALSE)
ae.value <- abs(y-med)
} else if (is.vector(x)) {
if (length(y) != length(x)) {
stop("Length of 'y' is not equal to the length of 'x'!")
}
#prepare data
data <- cbind(y, x)
data <- matrix(data[apply(is.finite(data), 1, all), ], ncol = 2)
y <- data[, 1]
x <- data[, 2]

ae.value <- abs(y-x)
} else {
stop("'x' should be a vector or matrix!")
}

if (na.rm == TRUE) {
ae.value <- as.vector(na.omit(ae.value))
}

if (mean == TRUE) {
ae.value <- mean(ae.value)
}
return(as.numeric(ae.value))

}
#'
#' internal function
#' @noRd
median.i <- function(z) {
z <- z[is.finite(z)]
out <- median(z)
return(out)
}



Loading

0 comments on commit 5626d38

Please sign in to comment.