View source: R/expansionTerms.R
| expansionTerms | R Documentation |
Compute "expansion" terms that modify the shape of a base distance function.
expansionTerms(a, d, series, nexp, w)
a |
A vector or matrix of (estimated) coefficients.
|
d |
A vector or 1-column matrix of
distances at which to evaluate
the expansion terms. |
series |
If |
nexp |
Number of expansion terms. Integer from 0 to 5. |
w |
A vector specifying strip width for every 'case'
in |
Expansion terms modify the base likelihood function
and are used to incorporate "wiggle". The modified distance function is,
key * expTerms where key is a vector of values in
the base likelihood function (e.g., halfnorm.like()$L.unscaled)
and expTerms is the
matrix returned by this routine. In equation form,
f(x_i|\beta,a_1,a_2,\dots,a_m) =
f(x_i|\beta)(1 + \sum_{k=1}^{m} a_k h_{k}(x_i/w)).
,
where m = the the number of expansions (nexp), h_{j}(x)
are expansion terms for distance x, and
a_1, a_2, \dots, a_m are the (estimated)
expansion term coefficients.
If nexp equals 0, 1 is returned.
If nexp is greater than 0, a matrix of
size nXk containing expansion terms,
where n = length(d) and k = nrow(a). The
expansion series associated with row j of a
are in column j of the return. i.e.,
element (i,j) of the return is
1 + \sum_{k=1}^{m} a_{jk} h_{k}(x_{i}/w).
a1 <- c(log(40), 0.5, -.5)
a2 <- c(log(40), 0.25, -.5)
dists <- seq(0, 100, length = 100) %m%.
w = 100 %m%.
expTerms1 <- expansionTerms(a1, dists, "cosine", 2, w)
expTerms2 <- expansionTerms(a2, dists, "cosine", 2, w)
plot(dists, expTerms2, ylim = c(0,2.5))
points(dists, expTerms1, pch = 16)
# Same as above
a <- rbind(a1, a2)
w <- rep(w, nrow(a))
expTerms <- expansionTerms(a, dists, "cosine", 2, w)
matlines(dists, expTerms, lwd=2, col=c("red", "blue"), lty=1)
# Showing key and expansions
key <- halfnorm.like(log(40), dists, matrix(1,length(dists),1))$L.unscaled
plot(dists, key, type = "l", col = "blue", ylim=c(0,1.5))
lines(dists, key * expTerms1, col = "red")
lines(dists, key * expTerms2, col = "purple")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.