Title: | Litter Analysis |
---|---|
Description: | Data sets on various litter types like beach litter, riverain litter, floating litter, and seafloor litter are rapidly growing. This package offers a simple user interface to analyse these litter data in a consistent and reproducible way. It also provides functions to facilitate several kinds of litter analysis, e.g., trend analysis, power analysis, and baseline analysis. Under the hood, these functions are also used by the user interface. See Schulz et al. (2019) <doi:10.1016/j.envpol.2019.02.030> for details. MS-Windows users are advised to run 'litteR' in 'RStudio'. See our vignette: Installation manual for 'RStudio' and 'litteR'. |
Authors: | Dennis Walvoort [aut, cre, cph], Willem van Loon [aut, cph], Rijkswaterstaat - The Netherlands [cph, fnd, dtc] |
Maintainer: | Dennis Walvoort <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.0 |
Built: | 2024-12-12 07:07:45 UTC |
Source: | CRAN |
A tool for the analysis of various litter types, e.g., beach litter, riverain litter, floating litter, and seafloor litter.
The easiest way to get convenient with litteR is to create an empty
project directory and fill it with example files by calling the function
create_litter_project
. The workhorse function in litteR
is called litter
. This function will start a simple user
interface and lets you select an input file (*.csv) and a settings file
(*.yaml). It will produce an HTML-report with litter analysis results
according to the selected options in the settings file.
See the package vignette for more details.
Maintainer: Dennis Walvoort [email protected] [copyright holder]
Authors:
Willem van Loon [email protected] [copyright holder]
Other contributors:
Rijkswaterstaat - The Netherlands [copyright holder, funder, data contributor]
Schulz, Marcus, Dennis J.J. Walvoort, Jon Barry, David M. Fleet & Willem M.G.M. van Loon, 2019. Baseline and power analyses for the assessment of beach litter reductions in the European OSPAR region. Environmental Pollution 248:555-564 <doi:10.1016/j.envpol.2019.02.030>
Adjusted boxplot statistics according to Hubert & Vandervieren (2008). The upper whisker extends from the hinge to the largest value no further than the upper fence. Similarly, the lower whisker extends from the hinge to the smallest value no further than the lower fence. See Hubert & Vandervieren (2008, p.5191, Eq.5).
adj_boxplot_stats(x, ...) ## Default S3 method: adj_boxplot_stats(x, ...)
adj_boxplot_stats(x, ...) ## Default S3 method: adj_boxplot_stats(x, ...)
x |
numeric vector |
... |
further arguments passed to or from other methods. |
Numeric vector consisting of respectively the lower whisker/fence, the first quartile/hinge, the median, the third quartile/hinge, and the upper whisker/fence.
adj_boxplot_stats(default)
: Adjusted Boxplot Statistics
Hubert, M., and E. Vandervieren, 2008. An adjusted boxplot for skewed distributions. Computational Statistics and Data Analysis 52:5186-5201 doi:10.1016/j.csda.2007.11.008
adj_boxplot_stats(rlnorm(100))
adj_boxplot_stats(rlnorm(100))
Fills an empty directory (path
) with example files. If the
path
' argument is missing or NULL
,
a Tcl/Tk dialogue will be started.
create_litter_project(path = NULL)
create_litter_project(path = NULL)
path |
(Existing) directory name |
Logger, in the spirit of loggers like log4j. Implemented logging levels are DEBUG, INFO, WARN, ERROR (in increasing order of specificity. Logging events can be filtered to show only events with a minimum specificity.
create_logger(con = stdout(), level = c("DEBUG", "INFO", "WARN", "ERROR"))
create_logger(con = stdout(), level = c("DEBUG", "INFO", "WARN", "ERROR"))
con |
connection to write logging data to |
level |
log only events of this level and those that are more specific (see details) |
Anonymous logging functions
logger <- create_logger(level = "INFO") logger$info("starting specific computation") logger$info("Today is {Sys.Date()}")
logger <- create_logger(level = "INFO") logger$info("starting specific computation") logger$info("Today is {Sys.Date()}")
Coefficient of Variation
cv(x, na.rm = FALSE)
cv(x, na.rm = FALSE)
x |
a numeric vector |
na.rm |
logical. Should missing values be removed? |
coefficient of variation (numeric vector of length 1).
https://en.wikipedia.org/wiki/Coefficient_of_variation
Generic function for enumerating objects
enumerate(x, ...) ## S3 method for class 'numeric' enumerate(x, ...)
enumerate(x, ...) ## S3 method for class 'numeric' enumerate(x, ...)
x |
object to enumerate |
... |
further arguments passed to or from other methods. |
enumerate(numeric)
: enumerate numeric
vector.
Collapsing a character
vector of length n, to a
character
vector of length 1.
## S3 method for class 'character' enumerate(x, ...)
## S3 method for class 'character' enumerate(x, ...)
x |
character vector |
... |
further arguments passed to or from other methods. |
character
vector of length 1, with elements
separated by a comma except for the last element which
is prepended by "and".
enumerate("apples") enumerate(c("apples", "oranges")) enumerate(c("apples", "oranges", "pears"))
enumerate("apples") enumerate(c("apples", "oranges")) enumerate(c("apples", "oranges", "pears"))
Convert Sequenized Output to Character String
## S3 method for class 'sequenized' enumerate(x, ...)
## S3 method for class 'sequenized' enumerate(x, ...)
x |
object of class |
... |
further arguments passed to or from other methods. |
string representation (character vector of length 1) of a sequenized object
Simple wrapper for file.access
with mode=2
has_write_access(path)
has_write_access(path)
path |
filename |
TRUE
if write access, FALSE
if not
Extract the intercept from object x
.
intercept(x, ...)
intercept(x, ...)
x |
object |
... |
further arguments passed to or from other methods. |
estimate of the intercept (numeric vector of length 1).
A normalized measure of the dispersion of a probability distribution.
iod(x, na.rm = FALSE)
iod(x, na.rm = FALSE)
x |
a numeric vector |
na.rm |
logical. Should missing values be removed? |
index of dispersion (numeric vector of length 1).
https://en.wikipedia.org/wiki/Index_of_dispersion
Checks if the data format x
complies with format
.
is_date_format(x, format = "%Y-%m-%d")
is_date_format(x, format = "%Y-%m-%d")
x |
object of class |
format |
required date format (see |
TRUE
if x
complies with format
,
and FALSE
otherwise.
is_date_format("2019-05-14", "%Y-%m-%d")
is_date_format("2019-05-14", "%Y-%m-%d")
Test for natural numbers according to ISO 80000-2, that is the set 0, 1, 2, ...
is_natural_number(x)
is_natural_number(x)
x |
|
TRUE
in case x
is a natural number,
FALSE
otherwise.
stopifnot(!is_natural_number(3.1)) stopifnot(!is_natural_number(2.99)) stopifnot(is_natural_number(3)) stopifnot(all(is_natural_number(0:9))) stopifnot(sum(is_natural_number(c(1, 2.5, 3))) == 2)
stopifnot(!is_natural_number(3.1)) stopifnot(!is_natural_number(2.99)) stopifnot(is_natural_number(3)) stopifnot(all(is_natural_number(0:9))) stopifnot(sum(is_natural_number(c(1, 2.5, 3))) == 2)
Mann-Kendall S Statistic
kendall_s(x, t = seq_along(x))
kendall_s(x, t = seq_along(x))
x |
observations |
t |
time index |
Gilbert, R.O., 1987. Statistical methods for environmental pollution monitoring.
Mann-Kendall Variance of S Statistic
kendall_var_s(x, t = seq_along(x))
kendall_var_s(x, t = seq_along(x))
x |
observations |
t |
time index |
Gilbert, R.O., 1987. Statistical Methods for Environmental Pollution Monitoring.
Van Belle and Hughes, 1984, Nonparametric Tests for Trend in Water Quality. Water Resources Research 20:127-136
Lists all duplicates as a list of tuples.
list_duplicates(x, ...) ## S3 method for class 'character' list_duplicates(x, ...) ## S3 method for class 'tbl' list_duplicates(x, ...) ## S3 method for class 'data.frame' list_duplicates(x, ...)
list_duplicates(x, ...) ## S3 method for class 'character' list_duplicates(x, ...) ## S3 method for class 'tbl' list_duplicates(x, ...) ## S3 method for class 'data.frame' list_duplicates(x, ...)
x |
object of class |
... |
further arguments passed to or from other methods. |
list
of row numbers with duplicates
list_duplicates(character)
: list duplicates for a character
vector.
list_duplicates(tbl)
: lists duplicates for a tibble
.
list_duplicates(data.frame)
: lists duplicates for a data.frame
.
list_duplicates(c("a", "b", "c")) # list() list_duplicates(c("a", "b", "a", "c")) # list(c(1, 3))
list_duplicates(c("a", "b", "c")) # list() list_duplicates(c("a", "b", "a", "c")) # list(c(1, 3))
Starts a graphical user interface for analysing litter data. A Tcl/Tk-dialogue will be started if one or more arguments are missing.
litter(filename = NULL)
litter(filename = NULL)
filename |
name of file containing settings (see vignette for details) |
For details, see our vignette by typing: vignette("litter-manual")
directory name (invisibly) where all results are stored.
Performs Mann-Kendall non-parametric test for trend.
mann_kendall(x, t = seq_along(x), type = c("both", "increasing", "decreasing")) ## S3 method for class 'mann_kendall' test_statistic(x, ...) ## S3 method for class 'mann_kendall' p_value(x, ...)
mann_kendall(x, t = seq_along(x), type = c("both", "increasing", "decreasing")) ## S3 method for class 'mann_kendall' test_statistic(x, ...) ## S3 method for class 'mann_kendall' p_value(x, ...)
x |
numeric vector representing a time-series. |
t |
time index (a numeric vector, or a vector
of class |
type |
direction to test (both, increasing, or decreasing). |
... |
further arguments passed to or from other methods. |
object of class Mann-Kendall
.
test_statistic(mann_kendall)
: Extracts Mann Kendall tau
p_value(mann_kendall)
: Extract p-value
test_statistic
, p_value
,
cor.test
, regional_kendall
# create mann_kendall object mk <- mann_kendall(c(9, 4, 7, 5, 3), type = "decreasing") mk <- mann_kendall( x = c(9, 4, 7, 5, 3), t = c(1, 3, 2, 5, 9), type = "decreasing") # get test statistic tau test_statistic(mk) # get p-value p_value(mk)
# create mann_kendall object mk <- mann_kendall(c(9, 4, 7, 5, 3), type = "decreasing") mk <- mann_kendall( x = c(9, 4, 7, 5, 3), t = c(1, 3, 2, 5, 9), type = "decreasing") # get test statistic tau test_statistic(mk) # get p-value p_value(mk)
Robust statistic that quantifies the skewness of univariate distributions.
medcouple(x, ...) ## Default S3 method: medcouple(x, ...)
medcouple(x, ...) ## Default S3 method: medcouple(x, ...)
x |
numeric vector |
... |
further arguments passed to or from other methods. |
medcouple (numeric vector of length 1).
medcouple(default)
: default method
This is a naive, but robust en simple implementation. For a more efficient implementation see package robustbase and the references section below.
Brys, G., M. Hubert, A. Struyf, 2004. A Robust Measure of Skewness. Journal of Computational and Graphical Statistics 13: 996-1017. doi:10.1198/106186004X12632.
Extract p-value.
p_value(x, ...)
p_value(x, ...)
x |
object |
... |
further arguments passed to or from other methods. |
p-value of a test (numeric vector of length 1).
Reads litter data from various formats. Currently only the OSPAR data snapshot format, and a wide format are supported. See the package vignette for more details.
read_litter(filename, logger = create_logger(level = "INFO"), type_names)
read_litter(filename, logger = create_logger(level = "INFO"), type_names)
filename |
name of litter file |
logger |
optional logger object (see |
type_names |
character vector of allowed type_names |
tibble
with litter data in long format
Read the file that links type names to group codes See the package vignette for more details.
read_litter_types(filename, logger = create_logger(level = "INFO"))
read_litter_types(filename, logger = create_logger(level = "INFO"))
filename |
name of type file |
logger |
optional logger object (see |
tibble
with look-up-table of type names and group codes
Reads settings file. See tutorial for its format.
read_settings(filename, logger = create_logger(level = "INFO"))
read_settings(filename, logger = create_logger(level = "INFO"))
filename |
name of litter file |
logger |
optional logger object (see |
validated settings file
Type stable implementation of an Empirical Cumulative Distribution Function (ECDF) sampler.
recdf(x, n)
recdf(x, n)
x |
numeric vector |
n |
number of draws |
vector of n
elements of the same type as x
recdf(1:5, 10)
recdf(1:5, 10)
Performs Regional Kendall non-parametric test for trend.
regional_kendall( x, t = seq_along(x), r = rep.int(1, length(x)), type = c("both", "increasing", "decreasing") ) ## S3 method for class 'regional_kendall' test_statistic(x, ...) ## S3 method for class 'regional_kendall' p_value(x, ...)
regional_kendall( x, t = seq_along(x), r = rep.int(1, length(x)), type = c("both", "increasing", "decreasing") ) ## S3 method for class 'regional_kendall' test_statistic(x, ...) ## S3 method for class 'regional_kendall' p_value(x, ...)
x |
observations |
t |
time index |
r |
region index |
type |
direction to test (both, increasing, or decreasing). |
... |
further arguments passed to or from other methods. |
test_statistic(regional_kendall)
: Extracts Regional Kendall Z
p_value(regional_kendall)
: Extract Regional Kendall p-value
Gilbert, R.O., 1987. Statistical methods for environmental pollution monitoring.
This is the Median Absolute Deviation divided by the median and is similar to the coefficient of variation.
rmad(x, na.rm = FALSE)
rmad(x, na.rm = FALSE)
x |
a numeric vector |
na.rm |
logical. Should missing values be removed? |
Relative median absolute deviation (numeric vector of length 1).
https://en.wikipedia.org/wiki/Median_absolute_deviation
Applies function fun
within a rolling (moving) window
of size w
to vector numeric vector x
.
roll(x, w = 3, fun = mean)
roll(x, w = 3, fun = mean)
x |
numeric vector (time-series) |
w |
width of moving window |
fun |
function to be applied |
vector of length length(x)-w
Generic function for sequenizing objects
sequenize(x, ...)
sequenize(x, ...)
x |
object to sequenize |
... |
further arguments passed to or from other methods. |
Compression of integer sequences to 'start-end' notation.
For instance c(1:5, 8:9)
becomes "1-5, 8-9"
.
## S3 method for class 'integer' sequenize(x, ...)
## S3 method for class 'integer' sequenize(x, ...)
x |
vector of integers. |
... |
further arguments passed to or from other methods. |
object of class sequenized
The elements of x
should be unique and in ascending order.
sequenize(c(1:4, 8:9))
sequenize(c(1:4, 8:9))
Extract slope.
slope(x, ...)
slope(x, ...)
x |
object |
... |
further arguments passed to or from other methods. |
estimate of the slope (numeric vector of length 1).
Computes adjusted boxplot statistics to be used by ggplot2
.
See Hubert & Vandervieren (2008, p.5191, Eq.5).
stat_adj_boxplot() stat_adj_boxplot_outlier()
stat_adj_boxplot() stat_adj_boxplot_outlier()
stat_adj_boxplot_outlier()
: add outliers to adjusted boxplot
Hubert, M., and E. Vandervieren, 2008. An adjusted boxplot for skewed distributions. Computational Statistics and Data Analysis 52:5186-5201 doi:10.1016/j.csda.2007.11.008
adj_boxplot_stats
, stat_adj_boxplot_outlier
library(ggplot2) d <- data.frame(x = gl(2, 50), y = rnorm(100)) ggplot(data = d, mapping = aes(x = x, y = y)) + stat_adj_boxplot()
library(ggplot2) d <- data.frame(x = gl(2, 50), y = rnorm(100)) ggplot(data = d, mapping = aes(x = x, y = y)) + stat_adj_boxplot()
Extract test_statistic.
test_statistic(x, ...)
test_statistic(x, ...)
x |
object |
... |
further arguments passed to or from other methods. |
test statistic of a test (numeric vector of length 1).
test_statistic.wilcoxon
,
test_statistic.mann_kendall
Theil Sen Slope Estimator
theil_sen(x, y, ...) ## S3 method for class 'theil_sen' slope(x, ...) ## S3 method for class 'theil_sen' intercept(x, ...)
theil_sen(x, y, ...) ## S3 method for class 'theil_sen' slope(x, ...) ## S3 method for class 'theil_sen' intercept(x, ...)
x |
time vector ( |
y |
numeric value. |
... |
further arguments passed to or from other methods. |
object of class Theil_Sen
.
slope(theil_sen)
: Extract slope.
intercept(theil_sen)
: Extract intercept.
https://en.wikipedia.org/wiki/Theil-Sen_estimator
# create theil_sen object ts <- theil_sen(1:5, c(1, 2, 3, 5, 9)) # get slope slope(ts) # get intercept intercept(ts)
# create theil_sen object ts <- theil_sen(1:5, c(1, 2, 3, 5, 9)) # get slope slope(ts) # get intercept intercept(ts)
Robust centrality measure estimated as the weighted average of
the three quartiles: , where
and
are the first, second and third
quartiles respectively.
trimean(x, ...) ## Default S3 method: trimean(x, ...)
trimean(x, ...) ## Default S3 method: trimean(x, ...)
x |
numeric vector |
... |
further arguments passed to or from other methods. |
trimean (numeric value of length 1).
trimean(default)
: Tukey's trimean
https://en.wikipedia.org/wiki/Trimean
stopifnot(trimean(0:100) == mean(0:100)) stopifnot(trimean(0:100) == median(0:100))
stopifnot(trimean(0:100) == mean(0:100)) stopifnot(trimean(0:100) == median(0:100))
Generic function for validation of file formats.
validate(x, ...) ## S3 method for class 'litter' validate(x, type_names, logger = create_logger(level = "INFO"), ...) ## S3 method for class 'litter_types' validate(x, logger = create_logger(level = "INFO"), ...) ## S3 method for class 'settings' validate(x, logger = create_logger(level = "INFO"), ...)
validate(x, ...) ## S3 method for class 'litter' validate(x, type_names, logger = create_logger(level = "INFO"), ...) ## S3 method for class 'litter_types' validate(x, logger = create_logger(level = "INFO"), ...) ## S3 method for class 'settings' validate(x, logger = create_logger(level = "INFO"), ...)
x |
object to validate |
... |
further arguments passed to or from other methods. |
type_names |
character vector of permissible types |
logger |
optional logger object (see |
validated object of class wide
validated object of class litter_types
validated settings (list
)
validate(litter)
: validate litter data.
validate(litter_types)
: validate litter_types file
validate(settings)
: validate settings file
Constructor for a Wilcoxon test (simple wrapper for wilcox.test
).
wilcoxon(x, type = c("both", "greater", "less"), mu = 0) ## S3 method for class 'wilcoxon' test_statistic(x, ...) ## S3 method for class 'wilcoxon' p_value(x, ...)
wilcoxon(x, type = c("both", "greater", "less"), mu = 0) ## S3 method for class 'wilcoxon' test_statistic(x, ...) ## S3 method for class 'wilcoxon' p_value(x, ...)
x |
numeric vector representing a time-series. |
type |
direction to test (both, increasing, or decreasing). |
mu |
baseline value (null hypothesis) |
... |
further arguments passed to or from other methods. |
object of class wilcoxon
.
test_statistic(wilcoxon)
: Extract test statistic V
p_value(wilcoxon)
: Extract p-value
wilcox.test
, p_value
,
test_statistic
# create wilcoxon object w <- wilcoxon(c(9, 4, 7, 5, 3), type = "less") # get test statistic V test_statistic(w) # get p-value p_value(w)
# create wilcoxon object w <- wilcoxon(c(9, 4, 7, 5, 3), type = "less") # get test statistic V test_statistic(w) # get p-value p_value(w)