Skip to contents

Use the Singular Value Decomposition (SVD) to construct a parsimonious representation of a set of rates, probabilities, means, or other values. The construction proceeds as follows:

  • shift any values outside the permitted range;

  • transform values in matrix x (eg take logs);

  • carry out a SVD on the transformed version of x; and

  • centre and scale the results from the SVD to produce matrix matrix and vector offset.

Usage

make_matrix_and_offset(x, transform, n_comp = 10, eps = 1e-05)

Arguments

x

A matrix with value such as rates, probabilities, or means.

transform

"log", "logit", or "none".

n_comp

Number of components.

eps

Quantity used in setting floor and ceiling on value. See below for details. Default is 0.00001.

Value

A named list with two elements:

  • matrix, a numeric matrix

  • offset, a numeric vector

Details

If

  • \(X\) is a the matrix of transformed values of x

  • \(F\) is the matrix called matrix,

  • \(g\) is the vector called offset, and

  • \(\alpha\) is a vector of standard normal variates,

and

$$\beta = F \alpha + g$$

then \(\beta\) should look like a randomly-selected column from \(X\).

Matrix x typically has age along the rows, and some combination of classification variables, such as country and time, along the columns. One exception is when the SVD is used to capture the relationship between female and male rates, in which case rows are formed by interacting sex and age. See below for an example.

When transform is "log" or "logit", make_matrix_and_offset() converts any values in x that are less than eps to values greater than or equal to eps before transforming. The converted value is based on on a main effects model.

When transform is "logit", make_matrix_and_offset() converts any values greater than 1-epsto1-eps` before transforming. The converted value is based on main effects model.

Examples

x <- matrix(rgamma(n = 150, shape = 1),
            nrow = 10,
            ncol = 15)
x
#>             [,1]        [,2]      [,3]      [,4]      [,5]       [,6]
#>  [1,] 3.56720380 0.003006878 0.5823610 0.9919389 0.6262240 3.99729207
#>  [2,] 1.16790186 3.549754306 0.4097386 0.5870689 1.9758239 0.09760170
#>  [3,] 0.05745463 0.320788501 0.4414623 0.9002344 0.1350997 1.59358869
#>  [4,] 0.34040705 0.057208557 0.3029223 0.1013501 2.4746057 2.70982721
#>  [5,] 3.47156091 1.192544692 0.3143513 0.5136526 0.1306852 0.34895709
#>  [6,] 1.04366207 0.977676517 0.1501912 0.5211211 0.1503169 0.84492969
#>  [7,] 3.02627506 0.270517553 1.9871448 0.9643644 0.2410900 1.53427309
#>  [8,] 0.36756952 0.632583351 0.0957137 1.7860282 0.4381687 1.51650134
#>  [9,] 0.09970044 0.687157296 4.3464560 1.1765075 1.3526707 0.47342014
#> [10,] 0.78957870 2.307000169 0.5334439 0.7714259 0.6557784 0.04720586
#>              [,7]      [,8]      [,9]     [,10]     [,11]      [,12]      [,13]
#>  [1,] 0.280821777 0.1244746 1.3906908 0.9330427 1.5329073 0.24247424 1.95369160
#>  [2,] 0.004650806 1.0179040 0.1499705 0.4298801 1.6344452 0.08642313 0.04321846
#>  [3,] 0.312242653 0.3315243 1.5212165 0.6262551 1.6104275 0.32607519 0.66979397
#>  [4,] 2.300686987 2.9197751 1.0940085 0.6833322 0.2586801 0.28390766 0.14797684
#>  [5,] 2.139300961 0.5594540 0.5275938 0.6810664 2.2716396 3.27000473 1.12674682
#>  [6,] 0.236397300 2.4718336 0.2797523 0.3335608 1.6820578 0.55451812 2.75331147
#>  [7,] 1.629613976 2.2863807 0.3491605 0.2210535 2.3039239 0.97291392 0.33989775
#>  [8,] 0.101492580 2.6819784 0.7033173 1.2725915 1.6293517 0.83687730 0.55150446
#>  [9,] 2.422577440 0.8104164 2.4537597 5.3369482 1.7628890 1.11902902 0.15003181
#> [10,] 1.110745169 5.1982640 0.2337429 0.4004319 1.0264775 0.54241287 0.79764261
#>            [,14]     [,15]
#>  [1,] 0.16174685 0.4013503
#>  [2,] 3.06172416 0.1637757
#>  [3,] 0.69982934 2.6790740
#>  [4,] 1.71830506 0.4943887
#>  [5,] 0.32760009 0.4201330
#>  [6,] 0.08526380 0.2787144
#>  [7,] 3.75891187 2.7092459
#>  [8,] 0.98357963 3.1915289
#>  [9,] 0.02302998 1.1277676
#> [10,] 0.08573478 1.1894050
make_matrix_and_offset(x, transform = "log")
#> $matrix
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>                                                                              
#>  [1,]  0.17528628 -1.65720991 -0.05668403  0.24742426 -0.12856010  0.52205430
#>  [2,]  1.43624933  0.42553298 -0.40433772 -0.30518841 -0.14150740  0.36394391
#>  [3,]  0.29016560 -0.52792213  0.22617414 -0.28818973  0.71633520 -0.33941385
#>  [4,]  0.15679453 -0.69318740 -0.32138916 -0.54972906 -0.62028404 -0.69374772
#>  [5,]  0.06933407 -0.02582008  0.46096010  0.67440904 -0.16545291 -0.03744454
#>  [6,]  0.53490707 -0.24764186  0.62259009  0.62520632  0.02268646 -0.16637543
#>  [7,]  0.04260670 -0.16177638 -0.32886505  0.33069408 -0.13451366 -0.43215747
#>  [8,]  0.47571592 -0.17158849  0.02188372 -0.01149469  0.57688061 -0.36545908
#>  [9,] -0.12429760 -0.19540437  1.04416407 -0.90435328 -0.07229123  0.21240954
#> [10,]  0.40319892  0.34641700  0.85275585  0.15515048 -0.40469680 -0.23983199
#>                                                      
#>  [1,] -0.05382438 -0.13367565  0.02172424  0.06702029
#>  [2,] -0.12094761  0.09756409 -0.01488215 -0.01058140
#>  [3,] -0.16549639  0.23497041  0.27346909  0.07214679
#>  [4,]  0.24687043  0.12224166 -0.04302583  0.01352010
#>  [5,] -0.14698977  0.40276031 -0.23792116  0.15605022
#>  [6,]  0.31797514  0.03301484  0.05181985 -0.28726456
#>  [7,] -0.73239081 -0.11274978 -0.02852707 -0.13774428
#>  [8,]  0.12704230 -0.27239286 -0.34514803  0.08108567
#>  [9,] -0.24182609  0.01868138 -0.16416879 -0.11023359
#> [10,] -0.06628593 -0.28005857  0.19528999  0.19054851
#> 
#> $offset
#>  [1] -0.68760454 -1.03547562 -0.61234173 -0.57269519 -0.27952568 -0.68642930
#>  [7]  0.01722542 -0.27913968 -0.20772451 -0.49823436
#> 
make_matrix_and_offset(x, transform = "none")
#> $matrix
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>                                                                              
#>  [1,] 0.2996417  0.06610274  1.043700877  0.325531605 -0.15409584  0.34910127
#>  [2,] 0.2477155  0.40937448 -0.341548025 -0.594214842  0.58028551  0.26914652
#>  [3,] 0.2171811 -0.10270269  0.136537464  0.416083501  0.16264076 -0.38330764
#>  [4,] 0.2942018  0.12660764 -0.263218156  0.462253467  0.15766163  0.70775843
#>  [5,] 0.3053926  0.10509102  0.590533254 -0.745079437 -0.34370231 -0.11831054
#>  [6,] 0.2309295  0.37256342  0.008434699  0.002783175 -0.55758549  0.01954166
#>  [7,] 0.4344857  0.36076511  0.191031783 -0.044450273  0.58801153 -0.31420802
#>  [8,] 0.3188680  0.16322295 -0.246014493  0.463883139 -0.02095599 -0.46556252
#>  [9,] 0.3952457 -1.56677822 -0.275352649 -0.158521040 -0.05061767  0.04557032
#> [10,] 0.3147881  0.49614317 -0.820737626 -0.050060946 -0.55385156  0.00738620
#>                                                        
#>  [1,]  0.28423527 -0.12824557 -0.161901830 -0.015611731
#>  [2,]  0.52505756  0.07142443 -0.007002622  0.008505383
#>  [3,]  0.22118533  0.22146418  0.122825588 -0.186258688
#>  [4,] -0.35725556  0.20954880  0.086740716  0.015019654
#>  [5,] -0.28371889  0.30637423  0.001420205  0.004203135
#>  [6,]  0.23649237 -0.17764519  0.300593755  0.061105012
#>  [7,] -0.39740858 -0.31064927  0.030515615 -0.002633322
#>  [8,]  0.14543319  0.19517270 -0.105300459  0.172047404
#>  [9,]  0.04781382 -0.09047462  0.004394599  0.011753857
#> [10,] -0.05952236 -0.10500891 -0.169052642 -0.111670126
#> 
#> $offset
#>  [1] 1.1192818 0.9586588 0.8150044 1.0591588 1.1530194 0.8242205 1.5063178
#>  [8] 1.1192524 1.5561574 1.0459526
#> 
make_matrix_and_offset(x, transform = "logit", n_comp = 2)
#> Error in make_matrix_and_offset(x, transform = "logit", n_comp = 2): `transform` is "logit" but `x` has 59 values greater than 1.