scale.model.RdThis function scales an intrinsic GMRF model so the geometric mean of the marginal variances is one
A SPD matrix, either as a (dense) matrix or sparseMatrix
Linear constraints spanning the null-space of Q; see
?INLA::f and argument extraconstr
A small constant added to the diagonal of Q if
constr
inla.scale.model returns a sparseMatrix of type
dgTMatrix scaled so the geometric mean of the marginal variances (of
the possible non-singular part of Q) is one, for each connected
component of the matrix.
## Q is singular
data(Germany)
g = system.file("demodata/germany.graph", package="INLA")
Q = -inla.graph2matrix(g)
diag(Q) = 0
diag(Q) = -rowSums(Q)
n = dim(Q)[1]
Q.scaled = inla.scale.model(Q, constr = list(A = matrix(1, 1, n), e=0))
print(diag(MASS::ginv(as.matrix(Q.scaled))))
#> [1] 4.1051254 2.2958691 1.2041273 1.8375575 1.9951740 0.8300261 2.8406550
#> [8] 1.4079953 1.3162505 1.5876088 1.5346849 2.3295677 1.2067025 1.3716385
#> [15] 1.1653051 1.0092041 0.7393211 0.7297798 1.3321255 0.5430324 0.5776739
#> [22] 0.5099762 0.5721098 0.5689658 0.6653532 0.7167899 0.6351572 2.3114669
#> [29] 0.6880773 0.6860854 0.5359093 0.5207970 0.6515564 0.6677200 0.7162291
#> [36] 0.8150340 0.9792132 0.8032751 0.6539792 0.7218376 0.9333989 0.8034911
#> [43] 0.5914811 0.9465180 0.6643542 0.7624728 1.0571072 2.1726464 1.3187042
#> [50] 1.4373429 3.0478575 1.0023731 1.8708652 0.8838465 0.9025644 1.2722998
#> [57] 1.1732539 1.1181209 0.8724629 0.6050640 0.9880708 0.8314674 1.6989176
#> [64] 0.9334874 1.6346144 1.2631024 0.9112081 0.8377976 1.1311883 1.3812903
#> [71] 1.1137079 1.0418807 1.1058375 1.1228275 0.9644103 1.2579880 0.7450501
#> [78] 0.8181725 1.0075867 0.8455357 3.1326824 1.5001287 0.8852628 1.2531093
#> [85] 1.3571247 1.0564988 0.9501750 0.8599024 1.1192940 0.6865471 0.8445417
#> [92] 0.6808125 1.1030357 1.1742098 1.1575390 0.8327129 0.7566873 0.7483675
#> [99] 0.7341174 0.7119539 1.0760203 0.6508734 0.7923708 0.5718769 0.5405377
#> [106] 0.6789234 0.6986693 0.9541101 0.9351042 0.9950817 0.9428015 1.3586441
#> [113] 0.7438890 0.5614279 0.6694066 0.7260356 0.5445919 0.6442976 0.7408111
#> [120] 1.4228331 0.6037497 0.9949701 0.8295831 0.6653329 0.7008455 0.5685291
#> [127] 0.6671481 0.4684695 0.7736886 0.7568828 0.6408058 0.7150024 0.6076916
#> [134] 0.7867606 0.5718256 0.7401830 0.5814428 0.5072559 1.3106649 0.4951193
#> [141] 0.5427051 0.5283866 0.5448223 0.5557168 0.5228071 1.0630013 0.8034720
#> [148] 0.6745900 0.7949787 0.8952814 0.9878638 0.6614252 0.7854810 0.7152412
#> [155] 0.6594777 0.5846399 2.8737269 0.9008465 1.2824857 0.8214778 1.0981692
#> [162] 1.3244705 1.7526482 1.2946108 1.3244705 1.0948596 1.6029926 2.7602867
#> [169] 1.1128440 0.9173852 1.7969592 0.7464658 0.7658741 0.9264287 0.9212733
#> [176] 1.0489627 0.9037810 0.9088119 0.6568687 0.6355869 0.9847290 1.1175586
#> [183] 0.9389221 0.9845266 0.9417351 0.9601217 0.7924613 2.4424259 0.6668682
#> [190] 0.8830962 0.7190725 0.5590435 0.8982501 0.7826234 2.7553238 1.5627605
#> [197] 0.7042316 0.9797661 1.5336649 0.9085688 0.6942375 0.6543553 1.6470441
#> [204] 0.8902021 0.8983490 1.0429308 2.5847811 1.9655656 1.8125316 1.2653912
#> [211] 1.2582492 1.3582232 1.2694084 1.3868521 2.7889571 2.2527950 0.9712919
#> [218] 1.0421512 1.0777111 1.8003757 0.9554586 1.0080080 1.3844267 1.1074801
#> [225] 1.0576557 1.3317466 1.4852197 3.1470723 1.7645132 3.5467773 1.3002980
#> [232] 1.0709729 1.4208626 0.7845676 1.2361699 1.0466598 1.1139008 1.5602140
#> [239] 1.0720785 1.5709636 1.2601994 1.0240059 1.0119570 0.9889436 1.3715146
#> [246] 1.2298350 1.7712196 1.2713611 2.8215382 3.6747631 3.0354039 1.4779901
#> [253] 1.9541015 0.9415258 1.0459805 1.8992054 1.5962191 1.3533150 1.2598462
#> [260] 1.4823516 2.6384893 2.7880457 2.7833045 0.8629316 1.3254135 0.7725538
#> [267] 1.0077468 1.0124880 0.9811673 1.1919122 2.2782844 2.3601969 2.4045945
#> [274] 2.3300586 0.5027267 0.5846392 0.6290368 0.8471093 0.5545009 0.5589203
#> [281] 0.8109690 0.8128515 1.0899850 2.3864607 1.2794452 1.2976306 0.8261913
#> [288] 1.5193493 0.6109031 0.6963218 0.7738345 0.6894386 0.6030709 0.6979689
#> [295] 0.9378112 1.4206399 2.3311114 2.4789553 0.6695227 0.6315068 0.5775082
#> [302] 0.6603435 0.8136055 0.6882601 0.5479463 0.5555537 0.7033977 1.6749094
#> [309] 2.8480948 3.0770069 1.4469349 0.9393950 0.8876580 1.0938729 0.9841890
#> [316] 1.1536050 1.5852104 1.0725371 0.9639258 0.7167236 1.3014492 1.6203524
#> [323] 1.5369789 1.2571006 1.4544296 1.2029588 1.1050379 0.7881356 0.9216342
#> [330] 1.4626481 2.7668235 3.0646472 1.5229544 1.5157152 3.1330056 1.3574479
#> [337] 1.2857898 0.7298839 0.9976702 0.6499384 0.9531077 0.6349522 0.8676237
#> [344] 0.9912658 1.2770740 1.2890895 0.8806861 1.4068083 1.0047290 0.9946213
#> [351] 1.2659757 0.7814287 0.7629825 0.8866945 0.7136160 0.8707363 0.7501220
#> [358] 0.8319537 0.7034047 0.8320816 0.8576065 0.6940759 0.7248080 1.2262968
#> [365] 0.8904032 0.7729059 1.3327219 0.8272882 0.9850094 1.1376010 1.0578575
#> [372] 0.8712543 0.8081703 3.4392086 1.3988745 2.0595470 2.6140966 2.3740330
#> [379] 2.8664342 1.3107767 1.3672780 1.4485821 1.1965811 1.4475635 1.0606932
#> [386] 1.6636509 1.1177341 1.3927160 1.0503926 0.8007732 0.8544520 0.8698156
#> [393] 1.3260344 1.1068617 0.8518353 0.8398783 1.4254385 1.5475741 1.1162353
#> [400] 1.2488832 4.1495907 0.8385389 0.9569351 1.9976400 1.2492206 1.2046192
#> [407] 1.4113031 0.9477230 1.0908765 2.2285102 1.6007724 1.4644188 3.5863098
#> [414] 2.2872556 1.5274246 1.4934362 1.2424566 0.9377835 0.8336933 1.1936386
#> [421] 1.2864182 0.6763597 1.1871823 0.7729677 0.8199823 1.2261612 0.7657134
#> [428] 0.9459805 0.6813123 0.9105702 0.9545677 1.0494189 0.8959718 0.7010321
#> [435] 1.8107521 0.6444784 0.8598131 0.8237287 1.0030421 1.0841146 1.0029268
#> [442] 1.2293811 0.5116979 2.0836706 1.1964205 0.8151083 1.4655036 0.8968978
#> [449] 0.7345318 1.1929376 0.6696869 0.8453616 0.8683491 0.7421438 1.7840461
#> [456] 1.2940662 0.9423170 0.6797830 1.4963121 0.7198470 0.7478258 2.6252545
#> [463] 1.0302571 0.7411174 0.9321482 0.6394888 0.7817460 0.8105916 0.9417505
#> [470] 0.6217023 0.7154378 0.6716578 0.6639645 1.3364092 0.6540630 0.7974092
#> [477] 0.6337536 0.6993426 0.6524098 0.5212850 0.6064085 0.6221227 0.4977418
#> [484] 0.5175417 0.6922616 0.6061266 0.8961892 0.6489273 0.6957998 0.7960118
#> [491] 0.5691125 0.6813897 0.7275949 0.7351859 0.6584707 0.6940805 0.7029038
#> [498] 0.6673471 0.6303150 0.7500053 0.7111808 0.7103548 0.6751434 0.7161166
#> [505] 1.3657647 2.3626800 1.3368955 1.3805278 2.3603798 0.7833475 0.7779479
#> [512] 0.5897282 0.6513392 0.5869818 0.5658906 0.7144668 0.6312053 0.5871223
#> [519] 0.5516540 0.8041708 0.7938472 0.5205906 0.6531608 0.5586046 0.5652191
#> [526] 0.7123615 0.5956882 0.5899389 0.6303873 0.5853399 0.5520841 0.5550222
#> [533] 0.6982708 0.7377527 0.8015791 0.7700303 0.4877332 0.5122183 0.8108939
#> [540] 0.8264810 0.5999470 0.5848221 0.6100972 0.7616472
## Q is singular with 3 connected components
g = inla.read.graph("6 1 2 2 3 2 2 1 3 3 2 1 2 4 1 5 5 1 4 6 0")
print(paste("Number of connected components", g$cc$n))
#> [1] "Number of connected components 3"
Q = -inla.graph2matrix(g)
diag(Q) = 0
diag(Q) = -rowSums(Q)
n = dim(Q)[1]
Q.scaled = inla.scale.model(Q, constr = list(A = matrix(1, 1, n), e=0))
print(diag(MASS::ginv(as.matrix(Q.scaled))))
#> [1] 1.0000000 1.0000000 1.0000000 0.9999999 0.9999999 1.0000000
## Q is non-singular with 3 connected components. no constraints needed
diag(Q) = diag(Q) + 1
Q.scaled = inla.scale.model(Q)
print(diag(MASS::ginv(as.matrix(Q.scaled))))
#> [1] 1 1 1 1 1 1