| create_indicator {spatialwarnings} | R Documentation | 
Custom Spatial Early-Warning signals
Description
Computation, significance assessment and display of trends of a custom, user-defined indicator.
Usage
create_indicator(fun, taskname = as.character(substitute(fun)))
compute_indicator(mat, fun, taskname = as.character(substitute(fun)), ...)
Arguments
fun | 
 A function that takes a matrix as input and returns a vector of numerical values. If the function returns a named vector, then the names will be used in plots and summaries. The function may also accept extra arguments.  | 
taskname | 
 The task name. A character string used used for plots and
textual summaries that describes the indicator (or set of indicators) 
being computed. If a task name cannot be derived from   | 
mat | 
 A matrix or a list of matrices.  | 
... | 
 Additional arguments being passed to the function   | 
Details
spatialwarnings provides "workflow functions", named *_sews, 
that assist the user in computing, displaying and assessing the 
significance of indicator values. The functions create_indicator and 
compute_indicator provides such workflow for any arbitrary function. 
create_indicator takes a function 'fun' and returns another function 
that can be used as an indicator similar to the *_sews functions. The 
results of this function can be assessed for significance using 
indictest and trends can be displayed using 
plot, summary, etc. (see Examples). compute_indicator 
does the same but without needing an intermediate indicator function.
Value
create_indicator returns a function that can be used in the same way 
than the other *_sews functions (e.g. generic_sews). This 
function as well as compute_indicator will return
simple_sews_* objects.
See Also
Examples
# Use the maximum patch size as indicator of degradation
maxpatchsize <- function(mat) { 
  max(patchsizes(mat))
}
# Create the indicator function
maxpatch_sews <- create_indicator(maxpatchsize)
# Then work with this function as if it were a function from the *_sews 
# family. 
mp_indic <- maxpatch_sews(forestgap)
summary(mp_indic)
## Not run:  
# Assess significance and display trends
mp_test <- indictest(mp_indic, nulln = 49)
plot(mp_test)
## End(Not run)
# Try spatial coefficient of variation as a spatial EWS. This function can 
# have arguments. 
spatial_cv <- function(mat, subsize) { 
  matc <- coarse_grain(mat, subsize)
  return( sd(matc) / mean(matc) )
}
# Create indicator function
cv_sews <- create_indicator(spatial_cv)
# Compute and display trends
cv_indic <- cv_sews(serengeti, subsize = 3)
plot(cv_indic, along = serengeti.rain)
# We can do the same work in one run using compute_indicator
cv_indic2 <- compute_indicator(serengeti, spatial_cv, subsize = 3)
plot(cv_indic2, along = serengeti.rain)
## Not run:  
indictest(cv_indic, nulln = 99)
## End(Not run)