compute_effective_range: Compute effective range

View source: R/functions_range.R

compute_effective_rangeR Documentation

Compute effective range

Description

Calculates the effective range for a spline basis matrix.

Usage

compute_effective_range(
  X,
  coords = X[, c("x", "y")],
  df = 3,
  nsamp = min(1000, nrow(X)),
  smoothedCurve = FALSE,
  newd = seq(0, 1, 100),
  scale_factor = 1,
  returnFull = FALSE,
  cl = NULL,
  namestem = "",
  inds = NULL,
  verbose = TRUE,
  span = 0.1
)

compute_effective_range_nochecks(
  X,
  inds,
  newd,
  D,
  smoothedCurve = FALSE,
  scale_factor = 1,
  returnFull = FALSE,
  cl = NULL,
  span = 0.1
)

Arguments

X

Matrix of spline values. See namestem for expected column names.

coords

Matrix of point coordinates. Defaults to the x and y columns of X, but can have a different number of columns for settings with different dimensions.

df

Degrees of freedom for which effective range should be computed.

nsamp

Number of observations from X from which to sample. Defaults to minimum of 1,000 and nrow(X).

smoothedCurve

Should a smoothed curve be fit to the relationship between the distances and the smoothed weights (TRUE), or just find the smallest distance that has a negative weight (FALSE)

newd

Distance values at which to make loess predictions. Should correspond to distances in the same units as coords.

scale_factor

Factor by which range should be scaled. Often physical distance corresponding to resolution of grid.

returnFull

Should the mean and median curves be returned (TRUE), or just the range value of where they first cross zero (FALSE).

cl

Cluster object, or number of cluster instances to create. Defaults to no parallelization.

namestem

Stem of names of columns of X corresponding to evaluated splines. Defaults to "", meaning names of the form 1, 2, ...

inds

Indices of observations to use for computation. Passed to computeS.

verbose

Control message printing.

span

Passed to fitLoess. If too small, then can lead to unstable loess estimates.

D

Distance matrix.

Details

Using the given TPRS basis and the inputted coordinates, the effective bandwidth is computed for the given degrees of freedom. This is accomplished by computing a distance matrix from the coordinates and a smoothing matrix from the basis. For each column of smoothing weights, the smallest distance that corresponds with the first negative smoothing weight is obtained and the median of the obtained distances is reported as the effective bandwidth. The names of columns of X are assumed to be numeric, with an optional name stem (e.g. "s1", "s2", etc.).

See Also

compute_lowCurve

Examples

xloc <- runif(n=100, min=0, max=10)
X <- splines::ns(x=xloc, df=4, intercept=TRUE)
colnames(X) <- paste0("s", 1:ncol(X))
xplot <- 0:10
compute_effective_range(X=X, coords=as.matrix(xloc), df=2:4, newd=xplot, namestem="s")

M <- 16
tprs_df <- 10
si <- seq(0, 1, length=M+1)[-(M+1)]
gridcoords <- expand.grid(x=si, y=si)
tprsX <- computeTPRS(coords = gridcoords, maxdf = tprs_df+1)
compute_effective_range(X=tprsX$tprsX, coords=gridcoords, df=3:10)

jpkeller/spconf documentation built on March 11, 2024, 9:32 a.m.