jmbm

Fig_08

Oct 10th, 2022
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.19 KB | None | 0 0
  1. pdf("fig_08.pdf", width = 5, height = 5)
  2. par(bty = "n", las = 1, mar = c(8, 4, 1, 1) + 0.2)
  3.  
  4. # función suma armónicos
  5. sum_arm <- function(n) {
  6.   a <- numeric(n)
  7.   for (i in 1:n) {
  8.     for (j in 1:i) {
  9.       a[j] <- a[j] + 1/i
  10.     }
  11.   }
  12.   a/n
  13. }
  14.  
  15. # datos
  16. obs <- c(16.7, 14.1, 11, 7.6, 7.2, 6.4, 5.7, 5.1, 4.5, 4.3, 4.3, 4, 2.2, 2.1, 1.4, 1.2, 0.7, 0.6, 0.6, 0.3)
  17. nomb <- c("industria", "comercio", "construcción", "transporte", "adm. pública", "hostelería", "agric/ganadería/pesca", "técnica/ciencia", "administración", "comunicación", "educación", "sanidad", "finaciera", "artes/recreativas", "otros servicios", "saneamiento", "inmobiliaria", "energía", "hogar", "minería")
  18. n <- length(obs)
  19. teor <- 100*sum_arm(n)
  20.  
  21. R2 <- 1 - sum((obs - teor)^2) / var(obs) / (n - 1)
  22.  
  23. # gráfico
  24. plot(1:n - 0.1, obs, ylab = "Población (%)", type = "h", las = 2, ylim = c(0, 20), lwd = 2, xlab = "", xaxt = "n")
  25. axis(1, at = 1:n, labels = nomb, las = 2, cex.axis = 0.8)
  26. lines(1:n + 0.1, teor, type = "h", col = "red", lwd = 2)
  27. legend("topright", bty = "n", cex = 0.8, c("observado", "teórico"), lty = 1, lwd = 2, col = c("black", "red"))
  28. text(10, 10, bquote(R^2 ~ ":" ~ .(round(R2, 2))))
  29.  
  30. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment