Datos de partida
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.3 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.3 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
health <-
read_excel("C:/Users/mbono/Downloads/health.xls") |>
select(-1) |>
as.matrix()
New names:
• `` -> `...1`
Datos de partida
[,1] [,2] [,3] [,4] [,5]
[1,] 243 789 167 18 6
[2,] 220 809 164 35 6
[3,] 147 658 181 41 8
[4,] 90 469 236 50 16
[5,] 53 414 306 106 30
[6,] 44 267 284 98 20
[7,] 20 136 157 66 17
health.P = matriz de proporciones por celda
health.P <- health/sum(health)
health.r <- apply(health.P, 1, sum)
health.c <- apply(health.P, 2, sum)
health.Dr <- diag(health.r)
health.Dc <- diag(health.c)
health.Drmh <- diag(1/sqrt(health.r))
health.Dcmh <- diag(1/sqrt(health.c))
[,1] [,2] [,3] [,4] [,5]
[1,] 0.038141579 0.12384241 0.02621253 0.002825302 0.0009417674
[2,] 0.034531471 0.12698164 0.02574164 0.005493643 0.0009417674
[3,] 0.023073301 0.10328049 0.02840998 0.006435410 0.0012556898
[4,] 0.014126511 0.07361482 0.03704285 0.007848062 0.0025113797
[5,] 0.008318945 0.06498195 0.04803014 0.016637890 0.0047088369
[6,] 0.006906294 0.04190865 0.04457699 0.015382201 0.0031392246
[7,] 0.003139225 0.02134673 0.02464291 0.010359441 0.0026683409
[1] 0.19196358 0.19369016 0.16245487 0.13514362 0.14267776 0.11191336 0.06215665
[1] 0.12823733 0.55595668 0.23465704 0.06498195 0.01616701
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 0.1919636 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.00000000
[2,] 0.0000000 0.1936902 0.0000000 0.0000000 0.0000000 0.0000000 0.00000000
[3,] 0.0000000 0.0000000 0.1624549 0.0000000 0.0000000 0.0000000 0.00000000
[4,] 0.0000000 0.0000000 0.0000000 0.1351436 0.0000000 0.0000000 0.00000000
[5,] 0.0000000 0.0000000 0.0000000 0.0000000 0.1426778 0.0000000 0.00000000
[6,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.1119134 0.00000000
[7,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.06215665
[,1] [,2] [,3] [,4] [,5]
[1,] 0.1282373 0.0000000 0.000000 0.00000000 0.00000000
[2,] 0.0000000 0.5559567 0.000000 0.00000000 0.00000000
[3,] 0.0000000 0.0000000 0.234657 0.00000000 0.00000000
[4,] 0.0000000 0.0000000 0.000000 0.06498195 0.00000000
[5,] 0.0000000 0.0000000 0.000000 0.00000000 0.01616701
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 2.282394 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
[2,] 0.000000 2.272198 0.000000 0.000000 0.000000 0.000000 0.000000
[3,] 0.000000 0.000000 2.481039 0.000000 0.000000 0.000000 0.000000
[4,] 0.000000 0.000000 0.000000 2.720209 0.000000 0.000000 0.000000
[5,] 0.000000 0.000000 0.000000 0.000000 2.647414 0.000000 0.000000
[6,] 0.000000 0.000000 0.000000 0.000000 0.000000 2.989228 0.000000
[7,] 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 4.011033
[,1] [,2] [,3] [,4] [,5]
[1,] 2.792497 0.000000 0.000000 0.000000 0.000000
[2,] 0.000000 1.341157 0.000000 0.000000 0.000000
[3,] 0.000000 0.000000 2.064349 0.000000 0.000000
[4,] 0.000000 0.000000 0.000000 3.922867 0.000000
[5,] 0.000000 0.000000 0.000000 0.000000 7.864755
health.S <- health.Drmh %*% (health.P - health.r %o% health.c) %*% health.Dcmh
[,1] [,2] [,3] [,4] [,5]
[1,] 0.08620063 0.052401995 -0.08873504 -0.086391392 -0.038803691
[2,] 0.06150416 0.058809131 -0.09244781 -0.063221200 -0.039129176
[3,] 0.01552300 0.043132623 -0.04973815 -0.040110998 -0.026746522
[4,] -0.02433773 -0.005542315 0.02993293 -0.009964963 0.006985322
[5,] -0.07376388 -0.050918059 0.07951736 0.076503529 0.050016099
[6,] -0.06214794 -0.081424582 0.11302292 0.095098928 0.031265829
[7,] -0.05411753 -0.071060440 0.08327716 0.099449615 0.052474969
health.svd <- svd(health.S)
$d
[1] 3.695985e-01 4.571116e-02 3.594393e-02 2.176889e-02 4.907848e-17
$u
[,1] [,2] [,3] [,4] [,5]
[1,] -0.43988571 0.4055135 0.3580394 0.4051477 -0.17502756
[2,] -0.39281241 0.1878872 -0.3264349 -0.2359385 0.15007504
[3,] -0.21696458 -0.3593238 -0.2881977 -0.4407184 -0.60289704
[4,] 0.07053349 -0.5698555 0.4570550 0.2872186 -0.32748658
[5,] 0.40421675 -0.2747270 -0.3757860 0.3289609 0.32688500
[6,] 0.48934481 0.2513851 0.4740176 -0.5715127 0.02415671
[7,] 0.44418561 0.4557838 -0.3276935 0.2619526 -0.60718464
$v
[,1] [,2] [,3] [,4] [,5]
[1,] -0.4097126 0.76083252 0.3111209 0.16803540 0.3581024
[2,] -0.4001414 -0.41367632 -0.3220458 -0.09533413 0.7456250
[3,] 0.5754638 -0.17534580 0.6350704 -0.01112854 0.4844141
[4,] 0.5207555 0.46808034 -0.5438450 -0.38595996 0.2549156
[5,] 0.2639651 0.01266605 -0.3168729 0.90199034 0.1271495
health.rsc <- health.Drmh %*% health.svd$u
health.rsc
[,1] [,2] [,3] [,4] [,5]
[1,] -1.0039924 0.9255414 0.8171870 0.9247065 -0.3994818
[2,] -0.8925477 0.4269170 -0.7417249 -0.5360990 0.3410002
[3,] -0.5382976 -0.8914965 -0.7150298 -1.0934395 -1.4958112
[4,] 0.1918658 -1.5501259 1.2432850 0.7812946 -0.8908318
[5,] 1.0701291 -0.7273162 -0.9948610 0.8708957 0.8653999
[6,] 1.4627632 0.7514475 1.4169467 -1.7083818 0.0722099
[7,] 1.7816430 1.8281639 -1.3143892 1.0507004 -2.4354375