Learn R Programming

sparseMatEst (version 1.0.0)

genSparseMatrix: Sparse matrix generator

Description

A way to generate sparse matrices for simulation and testing.

Usage

genSparseMatrix(k, rho, type)

Arguments

k

dimension parameter

rho

additional parameter

type

type of matrix to generate

Value

a matrix corresponding to the arguments chosen.

Details

genSparseMatrix constructs a sparse matrix to be used for testing and simulation. The type argument determines what type of matrix is produced while k effects the dimension and rho is an additional parameter to effect the output.

For type = 'tri', a (k x k) tridiagonal matrix is returned with off-diagonal entries equal to rho.

For type = 'arm', a (k x k) autoregressive matrix is returned with off-diagonal entries equal to rho^|i-j|.

For type = 'band', a (k x k) banded matrix is returned with rho bands.

For type = 'rand', a (k x k) matrix is returned with rho in (0,1) randomly selected off-diagonal entries set to be non-zero.

For type = 'tree', the adjacency matrix for a k-deep binary tree is returned with off-diagonal entries set to rho. The dimension of this matrix is k(k+1)/2.

For type = 'multi', a (k x k) matrix is returned with rho off-diagonals set to ones.

For type = 'block', a block diagonal matrix is returned with k blocks of size rho.

Examples

Run this code
# NOT RUN {
  out = list();
  out[[1]]= genSparseMatrix( 20,0.5,"tri" );
  out[[2]]= genSparseMatrix( 20,0.5,"arm" );
  out[[3]]= genSparseMatrix( 20,5,"band" );
  out[[4]]= genSparseMatrix( 20,0.5,"rand" );
  out[[5]]= genSparseMatrix( 7,0.5,"tree" );
  out[[6]]= genSparseMatrix( 20,5,"multi" );
  out[[7]]= genSparseMatrix( 5,4,"block" );

    par(mfrow=c(2,3));
    lab = c("tri","arm","band","rand","tree","multi","block");
    for( i in 2:7  )
      image(out[[i]],main=lab[i]);

# }

Run the code above in your browser using DataLab