Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pdf("fig_08.pdf", width = 5, height = 5)
- par(bty = "n", las = 1, mar = c(8, 4, 1, 1) + 0.2)
- # función suma armónicos
- sum_arm <- function(n) {
- a <- numeric(n)
- for (i in 1:n) {
- for (j in 1:i) {
- a[j] <- a[j] + 1/i
- }
- }
- a/n
- }
- # datos
- 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)
- 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")
- n <- length(obs)
- teor <- 100*sum_arm(n)
- R2 <- 1 - sum((obs - teor)^2) / var(obs) / (n - 1)
- # gráfico
- plot(1:n - 0.1, obs, ylab = "Población (%)", type = "h", las = 2, ylim = c(0, 20), lwd = 2, xlab = "", xaxt = "n")
- axis(1, at = 1:n, labels = nomb, las = 2, cex.axis = 0.8)
- lines(1:n + 0.1, teor, type = "h", col = "red", lwd = 2)
- legend("topright", bty = "n", cex = 0.8, c("observado", "teórico"), lty = 1, lwd = 2, col = c("black", "red"))
- text(10, 10, bquote(R^2 ~ ":" ~ .(round(R2, 2))))
- dev.off()
Advertisement
Add Comment
Please, Sign In to add comment