Learn R Programming

spatstat.random (version 3.4-5)

rpoint3: Generate N Random Points in 3 Dimensions

Description

Generate a random point pattern in three-dimensional space containing \(n\) independent, identically distributed random points with a specified distribution.

Usage

rpoint3(n, f, fmax = NULL, domain = box3(), ...,
  nsim = 1, drop = TRUE, ex = NULL, giveup = 1000)

Value

A three-dimensional point pattern (an object of class "pp3") if nsim=1 and drop=TRUE, otherwise a list of three-dimensional point patterns.

Arguments

n

Number of points to generate.

f

The probability density of the points, possibly un-normalised. Either a constant, or a function f(x,y,z, ...).

fmax

An upper bound on the values of f.

domain

Three-dimensional box (object of class "box3") in which to generate the point pattern.

...

Additional arguments passed to the function f.

nsim

Number of simulated realisations to be generated.

drop

Logical. If nsim=1 and drop=TRUE (the default), the result will be a point pattern, rather than a list containing a point pattern.

ex

Optional. Example point pattern in three dimensions (object of class "pp3"). The number of points n and the spatial region domain will be taken from ex.

giveup

Integer. Maximum number of attempts permitted in the rejection method.

Author

Adrian Baddeley Adrian.Baddeley@curtin.edu.au.

Details

This function generates n independent, identically distributed random points with common probability density proportional to f inside the specified three-dimensional region domain.

The argument f may be

a numerical constant:

uniformly distributed random points will be generated.

a function:

random points will be generated in the domain with probability density proportional to f(x, y, z, ...) where x, y, z are the cartesian coordinates. The function f must accept vectors of coordinates x,y,z and return the corresponding vector of function values. Additional arguments ... of any kind may be passed to the function.

The algorithm is as follows:

  • If f is a constant, we invoke runifpoint3.

  • If f is a function, then we use the rejection method. Proposal points are generated from the uniform distribution. A proposal point \((x,y,z)\) is accepted with probability f(x,y,z,...)/fmax and otherwise rejected. The algorithm continues until n points have been accepted. It gives up after giveup * n proposals if there are still fewer than n points.

See Also

runifpoint3

Examples

Run this code
  rpoint3(10, 1)
  rpoint3(10, f=function(x,y,z) {sqrt(x)}, fmax=1)

Run the code above in your browser using DataLab