LKrigMiscellaneous: Miscellaneous internal functions for LatticeKrig package.

Description Usage Arguments Details Value Author(s) Examples

Description

Some utility functions used internally by higher level LKrig functions. Currently these are simple functions that perform shifts of a matrix and operations on indices for multidimensional arrays.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
LKrig.shift.matrix( A, shift.row=0, shift.col=0, periodic=c(FALSE, FALSE))
LKrig.rowshift.periodic( A, shift.row)
LKrig.rowshift( A, shift.row, shift.col)
LKArrayShift(A, shift, periodic = FALSE)


expandMatrix0( A, B)
expandMatrix( ...)
expandMList( Mlist, byrow=TRUE)


convertIndexPeriodic(I, nGrid, nPad = NULL)
convertIndexArray(I, nGrid)
grid2Index(I, grid)

Arguments

A

A matrix.

byrow

If TRUE matrices will be repeated row by row. If FALSE this will be done column by column.

B

Another matrix.

grid

A vector giving the size of each dimension of array.

I

A matrix of multidimensional indices where each row identifies an element of the array. e.g. If I[1,] == c( 3,4,2) this refers to A[3,4,2]

Mlist

A list where each component is a matrix.

nGrid

A array giving number of elements in each dimension.

nPad

An array with the number of padding indices in each dimension.

periodic

A vector of logicals columns.TRUE indicates an index where the shift will be periodic – entries shifted beyond the dimensions will be wrapped to the other side. e.g. for the matrix version c(FALSE, TRUE) indicates the columns of the matrix will be shifted in a periodic way but not the rows.

shift

A integer vector that gives the shifts for each dimension of the array.

shift.row

An integer that specifies the number of positions that the rows of the matrix are shifted.

shift.col

An integer that specifies the number of positions that the columns of the matrix are shifted.

...

Matrices to be expanded.

Details

Shift related: These functions are used to create the nearest neighbor indices for the precision matrices.

Expand related: These functions are useful for creating a sets of covariance parameters that follow a factorial pattern. For example repeating the rows of the "alpha" parameters as the "a.wght" parameters are varied. expandMList is particularly useful for creating a factorial design of parameters to pass to LKrig.MLE for searching the likelihood.

Index related: The function convertIndexPeriodic converts a single index for a multidimensional array, into an index that reflects wrapping into a smaller grid to reflect the padding. This is used in the LKDistGrid function to handle distances when the grid has periodic dimensions. The other two functions are used for checking and debugging of going back and forth between the multidimensional and single indexes.

Value

Shift: A matrix of shifted values. Entries that are not defined due to the shift are set to NA. A column shift is done by a combination of transpose operations and a row shift.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
A<- matrix( 1:12,3,4)
A
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12

#shift of 2 for rows:
 LKrig.rowshift( A, 2)
    [,1] [,2] [,3] [,4]
[1,]   NA   NA   NA   NA
[2,]   NA   NA   NA   NA
[3,]    1    4    7   10

#periodic case
LKrig.rowshift.periodic( A, 2)
     [,1] [,2] [,3] [,4]
[1,]    2    5    8   11
[2,]    3    6    9   12
[3,]    1    4    7   10

Expand: ExpandMList Returns a list of matrices where the original matrices are repeated so that combinations of rows are represented. The example below illustrates. byrow=FALSE does the repetition by columns instead of rows.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
> A
     [,1] [,2]
[1,]    1    3
[2,]    2    4
> B
     [,1]
[1,]   11
[2,]   12
[3,]   13
> C
[1,] 100
> expandMList( list( A=A, B=B, C=C))
$A
     [,1] [,2]
[1,]    1    3
[2,]    2    4
[3,]    1    3
[4,]    2    4
[5,]    1    3
[6,]    2    4

$B
     [,1]
[1,]   11
[2,]   11
[3,]   12
[4,]   12
[5,]   13
[6,]   13

$C
     [,1]
[1,]  100
[2,]  100
[3,]  100
[4,]  100
[5,]  100
[6,]  100

Author(s)

Doug Nychka

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
	A<- array( 1:90, c( 4,5,3))
	LKArrayShift( A, c( -1,-1,0))	
	
# welcome to the world of unrolling multiarray indices
A<- array( 1:60, c( 4,3,5))	
I<- rbind( c(1,2,1), c( 3,2,5))
look<- grid2Index( I, c( 4,3,5) )
# A has been filled with the right unrolled index
print( look)
print(A[look])

LatticeKrig documentation built on Nov. 9, 2019, 5:07 p.m.