Description Usage Arguments Details Value Author(s) Examples
This routine translates a scalar value into a vector of length N containing N-1 zeros and one 1.0. The index position of the 1.0 within the returning vector depends on the position of val with respect to the bounds x_lower and x_upper.
1 | valToVec(val, N = 10, x_lower = 0, x_upper = 1)
|
val |
Value to be translated |
N |
Dimension of resulting vector |
x_lower |
Lower bound |
x_upper |
Upper bound |
Always provide N>1. If you convert the resulting vector back with <<vecToVal>> (see Package "myBayes"). The resulting value deviates from the original by a maximum difference of +- 1/N.
A probability vector containing N-1 zeros and one 1.0.
Philipp van Wickevoort Crommelin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (val, N = 10, x_lower = 0, x_upper = 1)
{
if (val > x_upper | val < x_lower)
print("warning: val is not within bounds of x_lower and x_upper")
if (N > 1) {
dx = (x_upper - x_lower)/(N - 1)
ref = seq(from = x_lower, to = x_upper, by = dx)
diff = abs(ref - rep(val, N))
minInd = which(diff == min(diff))
result = rep(0, N)
result[minInd] = 1
return(result)
}
else {
print(paste0("N needs to be greater than 1. N is currently set to ",
N))
return(NA)
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.