Non-square matrices

This document describe an example of reconstructing a non-square matrix.

library(systemicrisk)

Set up vectors of row and column sums of length 10 and 4, respectively, ensuring that their sums matches up.

set.seed(1230)
l <- rexp(10,rate=5/4)
l
##  [1] 0.11213094 0.24672257 0.42200570 0.59310598 0.96265285 0.90072506
##  [7] 0.45717999 0.04956001 0.59984659 0.37724666
a <- rexp(4);
a <- a/sum(a)*sum(l)
a
## [1] 0.7983658 1.7702032 0.9808514 1.1717560

Construct a model with fixed matrix p and lambda.

mod <- Model.Indep.p.lambda(model.p=Model.p.constant(p=matrix(0.5,nrow=10,ncol=4)),
                            model.lambda=Model.lambda.constant(lambda=matrix(5,nrow=10,ncol=4)))

Run the sampler to generate 10 samples.

res <- sample_HierarchicalModel(l=l,a=a,model=mod,nsamples=10,silent=TRUE)

Here are the first two of these samples.

res$L[[1]]
##             [,1]       [,2]         [,3]       [,4]
##  [1,] 0.04628372 0.06584722 0.0000000000 0.00000000
##  [2,] 0.00000000 0.08698660 0.1114270429 0.04830893
##  [3,] 0.00000000 0.19711167 0.1273630299 0.09753100
##  [4,] 0.00000000 0.20578887 0.3873171134 0.00000000
##  [5,] 0.00000000 0.00000000 0.1105124291 0.85214042
##  [6,] 0.48659262 0.29600064 0.0769706087 0.04116119
##  [7,] 0.00000000 0.27734863 0.1671147934 0.01271657
##  [8,] 0.04956001 0.00000000 0.0000000000 0.00000000
##  [9,] 0.00000000 0.54509270 0.0000000000 0.05475389
## [10,] 0.21592943 0.09602689 0.0001463929 0.06514395
res$L[[2]]
##              [,1]       [,2]       [,3]       [,4]
##  [1,] 0.000000000 0.09039052 0.02174042 0.00000000
##  [2,] 0.000000000 0.24672257 0.00000000 0.00000000
##  [3,] 0.000000000 0.00000000 0.00000000 0.42200570
##  [4,] 0.009408544 0.26814688 0.24746087 0.06808969
##  [5,] 0.000000000 0.74371433 0.21893852 0.00000000
##  [6,] 0.159743939 0.00000000 0.49271159 0.24826953
##  [7,] 0.223717673 0.23346232 0.00000000 0.00000000
##  [8,] 0.000000000 0.00000000 0.00000000 0.04956001
##  [9,] 0.057056342 0.18776660 0.00000000 0.35502364
## [10,] 0.348439280 0.00000000 0.00000000 0.02880738