Numerical integration of continuously differentiable
functions f(x,y) over simple closed polygonal domains.
The following cubature methods are implemented:
product Gauss cubature (Sommariva and Vianello, 2007,
The R package polyCub implements cubature (numerical integration) over polygonal domains. It solves the problem of integrating a continuously differentiable function f(x,y) over simple closed polygons.
You can install polyCub from CRAN via:
To install the development version from the GitHub repository, use:
The basic usage is:
polyregion represents the integration domain as an object of class
"owin" (from spatstat), "
gpc.poly" (from gpclib or rgeos),
"SpatialPolygons" (from sp),
or even as a plain list of lists of vertex coordinates (
f is the integrand and needs to take a two-column coordinate matrix
as its first argument.
polyCub() function by default calls
a C-implementation of product Gauss cubature.
The various implemented cubature methods can also be called directly.
General-purpose product Gauss cubature
(Sommariva and Vianello, 2007, BIT Numerical Mathematics,
Simple two-dimensional midpoint rule based on
Adaptive cubature for radially symmetric functions
integrate() along the polygon boundary
(Meyer and Held, 2014, The Annals of Applied Statistics,
https://doi.org/10.1214/14-AOAS743, Supplement B, Section 2.4)
Accurate (but slow) integration of the bivariate Gaussian density
based on polygon triangulation and
For details and illustrations see the
in the installed package or
The polyCub package evolved from the need to integrate so-called spatial interaction functions (Gaussian or power-law kernels) over the observation region (an administrative shapefile) of a spatio-temporal point process. Such epidemic models are implemented in surveillance.
polyCub also powers phylogeographic analyses in rase.
Contributions are welcome!
Please submit suggestions or report bugs at
or via e-mail to
Note that pull requests should only be submitted
after discussion of the underlying issue.
The polyCub package is free and open source software, licensed under the GPLv2.
Added a getting started
(suggested by @wrathematics in
fix minor compiler warning about missing
types field in
Package polyCub no longer attaches package sp (moved from "Depends" to "Imports").
The R code of the examples is no longer installed by default.
--example flag of R CMD INSTALL to achieve that.
The README now exemplifies the four different cubature rules.
The exported C-function
did not handle its
stop_on_error argument correctly
(it would always stop on error).
now detects non-finite
intrfr function values and gives an
informative error message (rather than just reporting "abnormal
termination of integration routine").
Package polyCub no longer strictly depends on package
It is only required for
polyCub.midpoint() and for polygon input of
Added full C-implementation of
polyCub.iso(), which is exposed as
"polyCub_iso" for use by other R packages (notably future versions of
LinkingTo: polyCub and
Accommodate CRAN checks: add missing import from graphics, register native routines and disable symbol search
polyCub.midpoint() works directly with input polygons of classes
"SpatialPolygons", since package polyCub now
polyCub.exact.Gauss() did not work if the
tristrip of the
transformed input polygon contained degenerate triangles (spotted by
Line integration in
polyCub.iso() could break due to division by zero
center point was part of the polygon boundary.
Nodes and weights for
polyCub.SV() were only cached up to
not 60 as announced in version 0.5-0. Fixed that which also makes
examples truly run without statmod.
polyCub.SV(), the new special setting
f=NULL means to only
compute nodes and weights.
Internal changes to the
"gpc.poly" converters to accommodate
polyCub.SV() gained an argument
engine to choose among available
implementations. The new and faster C-implementation is the default.
There should not be any numerical differences in the result of the
Package statmod is no
longer strictly required (imported). Nodes and weights for
Gauss-Legendre quadrature in
polyCub.SV() are now cached in the
polyCub package up to
::gauss.quad is only
queried for a higher number of nodes.
could not handle additional arguments for
integrate() given in the
now applies the
control arguments also to the numerical
checkintrfr() function is exported and documented.
Added a CITATION file.
gained an additional argument
print.args, an optional list of
arguments passed to
passed a data frame of coordinates to
f instead of a matrix as
rgeos (and therefore the GEOS library) is no longer strictly required (moved from "Imports" to "Suggests").
have been removed from the package (since we no longer import the formal
"gpc.poly" from gpclib or rgeos). However, there are two
owin2gpc similar to those dropped from
discpoly() back to
since it is only used there.
The latter two changes cause surveillance version 1.6-0 to be incompatible with this new version of polyCub. Appropriate modifications have been made in the new version 1.7-0 of surveillance.
thorough optimization of
polyCub.SV()-related code resulted in about
mapply() instead of a
less object copying
xylist() is now exported. It simply extracts polygon coordinates from
various spatial classes (with same unifying intention as
polyregion of class
"SpatialPolygons" of length more than 1 now
Use aspect ratio of 1 in
R CMD checkin the current R development version (also import packages into the NAMESPACE which are listed in the "Depends" field).
New cubature method
polyCub.iso() specific to isotropic functions
(thanks to Emil Hedevang for the basic idea).
plotpolyf() to plot a polygonal domain on top of an image
of a bivariate function.
The package now depends on R >= 2.15.0 (for
The package no longer registers
"owin" as an S4-class since we depend
on the sp package which does the job. This avoids a spurious warning
.simpleDuplicateClass()) upon package installation.
discpoly(), the argument
r has been renamed to
radius. This is
backward compatible by partial argument matching in old code.
This is the initial version of the polyCub package mainly built on functions previously maintained within the surveillance package. These methods for cubature of polygonal domains have been outsourced into this separate polyCub package since they are of general use for other packages as well.
The polyCub package has more documentation and tests, avoids the use
of gpclib as far as
possible (using rgeos
instead), and solves a compatibility issue with package
setClass("owin") instead of