## Loading required package: MASS
## Loading required package: matrixcalc

Create a matrix \(A\) with \(p_1 = 10\) rows and \(p_2 = 9\) columns.

p1 <- 10
p2 <- 9
m1 <- 6 # number of rows in A11
m2 <- 3 # number of columns in A11
A <- matrix(rnorm(10, mean = 0, sd = 0.1), p1, p2)

Find the approximation low-rank of \(A\) under singular value decomposition (SVD)

j1 <- svd(A)$d
j2 <- svd(A)$u
j3 <- svd(A)$v
num <-length(which(j1 != 0))
D <- diag(j1)
D[num, num] <- 0
app_low_rank_A <- j2
A11 <- app_low_rank_A[1:m1, 1:m2]
A12 <- app_low_rank_A[1:m1, (1+m2):p2]
A21 <- app_low_rank_A[(1+m1):p1, 1:m2]
A22 <- matrix(NA, nrow = p1 - m1, ncol = p2-m2)
Arecovery <- rbind(cbind(A11, A12), cbind(A21, A22))
Arecovery
##              [,1]        [,2]        [,3]         [,4]         [,5]
##  [1,] -0.66011468 -0.74563894  0.02467862 -0.010085324 -0.026429084
##  [2,]  0.09530799 -0.06679183  0.14749935 -0.982178325  0.001517307
##  [3,]  0.46312641 -0.44958316 -0.49086217  0.002813528  0.584723258
##  [4,] -0.16104826  0.14686398 -0.29543824 -0.070554121 -0.002563894
##  [5,] -0.16095558  0.14690560 -0.29543961 -0.070553558 -0.002562418
##  [6,]  0.24219851 -0.11041542  0.29423189  0.071047115  0.003855809
##  [7,]  0.25905351 -0.21244434 -0.24583975           NA           NA
##  [8,]  0.24984942 -0.21657834 -0.24570292           NA           NA
##  [9,] -0.06617942  0.02507524 -0.07347428           NA           NA
## [10,]  0.31026181 -0.29904350  0.59105240           NA           NA
##                [,6]          [,7]         [,8]          [,9]
##  [1,] -0.0097605613  0.0116298862  0.076485432  0.0065082700
##  [2,]  0.0005603586 -0.0006676774 -0.004391066 -0.0003736430
##  [3,]  0.0027229286 -0.0032444189 -0.021337335 -0.0018156286
##  [4,] -0.9274494816  0.0011282190  0.007419876  0.0006313694
##  [5,]  0.1518788419  0.9149391184  0.007415606  0.0006310060
##  [6,] -0.1514011782  0.1788092701  0.884647755 -0.0009495087
##  [7,]            NA            NA           NA            NA
##  [8,]            NA            NA           NA            NA
##  [9,]            NA            NA           NA            NA
## [10,]            NA            NA           NA            NA

Apply smc.FUN to recover the block \(A_{22}\)

A22 <- smc.FUN(Arecovery, 2, "True", m1, m2)
A22
##              [,1]        [,2]        [,3]        [,4]        [,5]          [,6]
## [1,] -0.016783565  0.12708065  0.20959377  0.18223474 -0.29146769  2.846038e-16
## [2,] -0.016774224  0.12700992  0.20947712  0.18213331 -0.29130547  2.844454e-16
## [3,] -0.005016115  0.03798068  0.06264142  0.05446461 -0.08711113  8.505972e-17
## [4,]  0.040351353 -0.30552962 -0.50390917 -0.43813208  0.70075194 -6.842496e-16