vecr2matr {bayesSurv}R Documentation

Transform single component indeces to double component indeces

Description

Components of a bivariate G-spline can be indexed in several ways. Suppose that the knots in the first dimension are μ1,K1,,μ1,K1\mu_{1,-K_1},\dots,\mu_{1,K_1} and the knots in the second dimension μ2,K2,,μ2,K2.\mu_{2,-K_2},\dots,\mu_{2,K_2}. I.e. we have 2K1+12K_1+1 knots in the first dimension and 2K2+12K_2+1 knots in the second dimension. Each G-spline component can have a double index (k1,k2)(k_1,k_2) assigned which means that it corresponds to the knot (μ1,k1,μ2,k2)(\mu_{1,k_1},\mu_{2,k_2}) or alternatively the same G-spline component can have a~single index

r=(k2+K2)×(2K1+1)+k1+K1+1r=(k_2 + K_2)\times(2K_1+1) + k_1 + K_1 + 1

assigned where rr takes values from 1,,K1×K21,\dots,K_1\times K_2. Single indexing is used for example by files r.sim and r_2.sim generated by functions bayesHistogram, bayesBisurvreg, bayessurvreg2 to save some space.

This function serves to translate single indeces to double indeces using the relationship

k1=(r1)\mboxmod(2K1+1)K1k_1 = (r - 1) \mbox{ mod } (2K_1+1) - K_1

k2=(r1)\mboxdiv(2K1+1)K2k_2 = (r - 1) \mbox{ div } (2K_1+1) - K_2

The function can be used also in one dimensional case when a~simple relationship holds

r=k+K+1r = k + K + 1

k=r1Kk = r - 1 - K

Usage

vecr2matr(vec.r, KK)

Arguments

vec.r

a~vector of single indeces

KK

a~vector with numbers of knots on each side of the central knot for each dimension of the G-spline. The length of KK determines dimension of the G-spline

Value

In bivariate case: a~matrix with two columns and as many rows as the length of vec.r.

In univariate case: a~vector with as ,amy components as the length of vec.r.

Author(s)

Arnošt Komárek arnost.komarek@mff.cuni.cz

Examples

### Bivariate G-spline
### with 31 knots in each dimension
KK <- c(15, 15)

### First observation in component (-15, -15),
### second observation in component (15, 15),
### third observation in component (0, 0)
vec.r <- c(1, 961, 481)
vecr2matr(vec.r, KK)

[Package bayesSurv version 3.7 Index]