spatstat.sparse-package: The spatstat.sparse Package

spatstat.sparse-packageR Documentation

The spatstat.sparse Package


The spatstat.sparse package defines three-dimensional sparse arrays, and supports standard operations on them. It also provides some utility functions for matrix calculations such as quadratic forms.


The spatstat.sparse package

  • defines a class of sparse three-dimensional arrays and supports standard operations on them (see Section Sparse 3D Arrays).

  • provides utility functions for matrix computations that are common in statistics, such as quadratic forms (see Section Matrix Utilities).

The code in spatstat.sparse was originally written for internal use within the spatstat package, but has now been removed and organised into a separate, stand-alone package which can be used for other purposes.

Sparse 3D Arrays

The main purpose of spatstat.sparse is to define a class of sparse three-dimensional arrays.

An array A is three-dimensional if it is indexed by three integer indices, so that A[i,j,k] specifies an element of the array. The array is called sparse if only a small fraction of the entries are non-zero. A sparse array can be represented economically by listing only the entries which are non-zero.

The spatstat.sparse package defines the class sparse3Darray of sparse three-dimensional arrays. These arrays can have numeric, integer, logical, or complex entries.

The package supports:

  • creation of sparse arrays from raw data

  • conversion to/from other data types

  • array indexing, extraction of entries, assignment of new values

  • arithmetic and logical operations

  • tensor operations (generalising matrix multiplication)

  • permutation of array dimensions

  • binding of several arrays into a single array

  • printing of sparse arrays.

The spatstat.sparse package uses the Matrix package to handle slices of three-dimensional arrays which are two-dimensional (sparse matrices) or one-dimensional (sparse vectors).

The main functions are:

sparse3Darray Create a sparse 3D array
as.sparse3Darray Convert other data to a sparse 3D array
[.sparse3Darray Subset operator
aperm.sparse3Darray Permute a sparse array
Ops.sparse3Darray arithmetic and logical operators
Complex.sparse3Darray complex operators
Math.sparse3Darray standard mathematical functions
Summary.sparse3Darray mean, maximum etc
tensorSparse Tensor product
as.array.sparse3Darray Convert sparse array to full array

The class "sparse3Darray" has methods for anyNA, dim, dim<-, dimnames, dimnames<- and print, documented in methods.sparse3Darray.

For other undocumented functions, see spatstat.sparse-internal.

Matrix Utilities

The package also includes some utilities for matrix calculations:

sumouter sum of outer products of rows of a matrix
quadform quadratic form involving rows of a matrix
bilinearform bilinear form involving rows of a matrix
matrixsqrt square root of a matrix
matrixpower powers of a matrix


This library and its documentation are usable under the terms of the “GNU General Public License”, a copy of which is distributed with R.




spatstat.sparse documentation built on April 18, 2022, 9:05 a.m.