Learn R Programming

spatstat.explore (version 3.1-0)

eval.fv: Evaluate Expression Involving Functions

Description

Evaluates any expression involving one or more function value (fv) objects, and returns another object of the same kind.

Usage

eval.fv(expr, envir, dotonly=TRUE, equiv=NULL, relabel=TRUE)

Value

Another object of class "fv".

Arguments

expr

An expression.

envir

Optional. The environment in which to evaluate the expression, or a named list containing "fv" objects to be used in the expression.

dotonly

Logical. See Details.

equiv

Mapping between column names of different objects that are deemed to be equivalent. See Details.

relabel

Logical value indicating whether to compute appropriate labels for the resulting function. This should normally be TRUE (the default). See Details.

Author

Adrian Baddeley Adrian.Baddeley@curtin.edu.au and Rolf Turner r.turner@auckland.ac.nz

Details

This is a wrapper to make it easier to perform pointwise calculations with the summary functions used in spatial statistics.

An object of class "fv" is essentially a data frame containing several different statistical estimates of the same function. Such objects are returned by Kest and its relatives.

For example, suppose X is an object of class "fv" containing several different estimates of the Ripley's K function \(K(r)\), evaluated at a sequence of values of \(r\). Then eval.fv(X+3) effectively adds 3 to each function estimate in X, and returns the resulting object.

Suppose X and Y are two objects of class "fv" which are compatible (in particular they have the same vector of \(r\) values). Then eval.im(X + Y) will add the corresponding function values in X and Y, and return the resulting function.

In general, expr can be any expression involving (a) the names of objects of class "fv", (b) scalar constants, and (c) functions which are vectorised. See the Examples.

First eval.fv determines which of the variable names in the expression expr refer to objects of class "fv". Each such name is replaced by a vector containing the function values. The expression is then evaluated. The result should be a vector; it is taken as the new vector of function values.

The expression expr must be vectorised. There must be at least one object of class "fv" in the expression. If the objects are not compatible, they will be made compatible by harmonise.fv.

If dotonly=TRUE (the default), the expression will be evaluated only for those columns of an "fv" object that contain values of the function itself (rather than values of the derivative of the function, the hazard rate, etc). If dotonly=FALSE, the expression will be evaluated for all columns.

For example the result of Fest includes several columns containing estimates of the empty space function \(F(r)\), but also includes an estimate of the hazard \(h(r)\) of \(F(r)\). Transformations that are valid for \(F\) may not be valid for \(h\). Accordingly, \(h\) would normally be omitted from the calculation.

The columns of an object x that represent the function itself are identified by its “dot” names, fvnames(x, "."). They are the columns normally plotted by plot.fv and identified by the symbol "." in plot formulas in plot.fv.

The argument equiv can be used to specify that two different column names in different function objects are mathematically equivalent or cognate. It should be a list of name=value pairs, or a named vector of character strings, indicating the pairing of equivalent names. (Without this argument, these columns would be discarded.) See the Examples.

The argument relabel should normally be TRUE (the default). It determines whether to compute appropriate mathematical labels and descriptions for the resulting function object (used when the object is printed or plotted). If relabel=FALSE then this does not occur, and the mathematical labels and descriptions in the result are taken from the function object that appears first in the expression. This reduces computation time slightly (for advanced use only).

See Also

fv.object, Kest

Examples

Run this code
  # manipulating the K function
  X <- runifrect(42)
  Ks <- Kest(X)

  eval.fv(Ks + 3)
  Ls <- eval.fv(sqrt(Ks/pi))

  # manipulating two K functions
  Y <- runifrect(20)
  Kr <- Kest(Y)

  Kdif <- eval.fv(Ks - Kr)
  Z <- eval.fv(sqrt(Ks/pi) - sqrt(Kr/pi))

  ## Use of 'envir'
  U <- eval.fv(sqrt(K), list(K=Ks))

  ## Use of 'equiv'
  Fc <- Fest(cells)
  Gc <- Gest(cells)
  # Hanisch and Chiu-Stoyan estimators are cognate
  Dc <- eval.fv(Fc - Gc, equiv=list(cs="han"))

Run the code above in your browser using DataLab