beta_builder {sim2Dpredictr} | R Documentation |
Create a Parameter Vector from Lattice Locations
Description
Specify the locations in the lattice/image that have non-zero parameters as well as the values for those parameters, and the function creates the parameter vector that matches the correct locations in the design matrix.
Usage
beta_builder(
row.index,
col.index,
im.res,
B0 = 0,
B.values,
index.type = "manual",
decay.fn = "gaussian",
phi = 0.5,
max.d = Inf,
h,
w,
bayesian = FALSE,
bayesian.dist = NULL,
bayesian.scale = NULL,
output.indices = TRUE
)
Arguments
row.index , col.index |
Vectors of row/columns indices for non-zero
parameters.
If |
im.res |
A vector specifying the dimension/resolution of the image. The first entry is the number of 'rows' in the lattice/image, and the second entry is the number of 'columns' in the lattice/image. |
B0 |
is the "true" intercept value; default is 0. |
B.values |
is a vector "true" parameter values for non-zero parameters.
The order of assignment is by row. If B.values argument is a single value,
then all non-zero parameters are assigned to that value, unless
|
index.type |
is one of index.type = c("manual", "rectangle", "ellipse", "decay")
|
decay.fn |
An argument to specify the decay function of non-zero
parameters decay from the peak when |
phi |
A scalar value greater than 0 that determines the decay rate of
non-zero parameters when |
max.d |
When |
w , h |
If index.type = "ellipse" then the width and height of the ellipse, respectively. |
bayesian |
If |
bayesian.dist |
When |
bayesian.scale |
A list. When |
output.indices |
If |
Value
A 2-element list containing (1) indices for the locations of "true" non-zero parameters, and (2) a parameter vector.
Note
The order of the parameters is by row. That is, if the lattice/image is 4x4, then parameters 1-4 make up the first row, 5-8 then second, and so forth.
Examples
## example
Bex1 <- beta_builder(row.index = c(5, 5, 6, 6),
col.index = c(5, 6, 5, 6),
im.res = c(10, 10),
B0 = 0, B.values = rep(1, 4))
## True non-zero parameters are locations 45, 46, 55, 56 in B
## i.e. locations (5, 5), (5, 6), (6, 5), (6, 6)
## Suppose that we index rows by i = 1, ... , I
## cols by j = 1, ... , J
## The index for a parameter is given by J * (i - 1) + j
## In this example, I = 10, J = 10; Thus:
## (5, 5) -> 10 * (5 - 1) + 5 = 45
## (5, 6) -> 10 * (5 - 1) + 6 = 46
## (6, 5) -> 10 * (6 - 1) + 5 = 55
## (6, 6) -> 10 * (6 - 1) + 6 = 45
Bex1
## length 101 (includes B0 w/ 100 variable parameter values)
length(Bex1$B)
## example: index.type = "rectangle"
Bex2 <- beta_builder(row.index = 12:15, col.index = 6:19,
im.res = c(20, 20), B0 = 16,
B.values = 1:(length(12:15) * length(6:19)),
index.type = "rectangle")
Bex2
matrix(Bex2$B[-1], nrow = 20, byrow = TRUE)
## example: index.type = "ellipse"
Bex3 <- beta_builder(row.index = 4, col.index = 5,
im.res = c(10, 10),
B0 = 16, B.values = 3,
index.type = "ellipse",
h = 5, w = 4)
Bex3
matrix(Bex3$B[-1], nrow = 10, byrow = TRUE)
## decaying parameter values
Bex4 <- beta_builder(row.index = 10, col.index = 20,
im.res = c(30, 30), B0 = 0, B.values = 10,
index.type = "decay", max.d = 7,
output.indices = FALSE)
inf_2D_image(B = Bex4, im.res = c(30, 30), binarize.B = FALSE)
Bex5 <- beta_builder(row.index = 4, col.index = 5,
im.res = c(10, 10),
B0 = 16, B.values = 5,
index.type = "ellipse",
h = 5, w = 4,
bayesian = TRUE,
bayesian.dist = "gaussian",
bayesian.scale = list("binary", c(0, 1, 0.25)))
inf_2D_image(B = Bex5$B, im.res = c(10, 10), binarize.B = FALSE)