Advertisement
jmbm

Fig_07

Jul 13th, 2023
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.32 KB | None | 0 0
  1. # AGRUPAMIENTO DE PARÁSITOS
  2.  
  3. #---- VARIABLES
  4. xmax <- 50                  # ancho pradera
  5. ymax <- 50                  # largo pradera
  6. S <- matrix(0, xmax, ymax)  # posiciones hospedadores
  7. Si <- S                     # p. hosp. inf. por nº picaduras
  8. Sp <- S                     # posiciones hospedador infestado
  9. nH <- 1000                  # número de hospedadores
  10. m <- 8                      # número de grupos
  11. mx <- integer()             # posición x de los grupos
  12. my <- integer()             # posición y de los grupos
  13. n <- 50                     # número de individuos/grupo
  14. nx <- integer()             # posición x de los parásitos
  15. ny <- integer()             # posición y de los parásitos
  16. radio <- 40                 # radio del grupo
  17. nP <- m*n                   # número de parásitos
  18.  
  19. #---- REPARTO HOSPEDADORES
  20. for (i in 1:nH) {
  21.   x <- sample(1:xmax, 1)
  22.   y <- sample(1:ymax, 1)
  23.   S[x, y] <- 1
  24. }
  25. nHreal <- sum(S)            # número real de hospedadores
  26.  
  27. #---- REPARTO DE PARÁSITOS
  28. mx <- sample(1:xmax, m)     # centro x gravedad de cada grupo
  29. my <- sample(1:ymax, m)     # centro y gravedad de cada grupo
  30. for (i in 1:m) {            # poblar los m grupos
  31.   for (j in 1:n) {
  32.     fuera <- TRUE
  33.     while (fuera) {
  34.       nx[j] <- sample((mx[i] - radio):(mx[i] + radio), 1)
  35.       ny[j] <- sample((my[i] - radio):(my[i] + radio), 1)
  36.       radij <- (nx[j] - mx[i])^2 + (ny[j] - my[i])^2
  37.       if (radij < radio) {
  38.         fuera <- FALSE
  39.         }
  40.       nx[j] <- nx[j] %% xmax
  41.       if (nx[j] == 0) {
  42.         nx[j] <- 1
  43.       }
  44.       ny[j] <- ny[j] %% ymax
  45.       if (ny[j] == 0) {
  46.         ny[j] <- 1
  47.       }
  48.     }
  49.     if (S[nx[j], ny[j]] == 1) {# ha pillado a un hospedador
  50.       Si[nx[j], ny[j]] <- Si[nx[j], ny[j]] + 1 # suma picadura
  51.       Sp[nx[j], ny[j]] <- 1 # marca picadura
  52.       }
  53.   }
  54. }
  55.  
  56. #---- RECUENTO DISTRIBUCIÓN PICADURAS
  57. picax <- 0:8
  58. pica <- as.numeric(table(factor(Si, levels = picax)))
  59. pica[1] <- nHreal - sum(pica[2:9])  # calcular H pica = 0
  60. f <- pica[1]/nHreal
  61.  
  62. #---- RESULTADO GRÁFICO
  63. pdf("fig_07.pdf", width = 6, height = 6)
  64. par(pty = "s", mar = c(1, 1, 1, 1), xaxt = "n", yaxt = "n", xaxs = "i", yaxs="i", ann = FALSE)
  65. S <- S + Sp
  66. image(x = 1:xmax, y = 1:ymax, S, xlim = c(0.5, xmax + 0.5), ylim = c(0.5, ymax + 0.5), col = c("azure", "forestgreen", "firebrick1"))
  67. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement