library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(purrr)
energy1 <- read_csv("Electricity - installed generating capacity.csv")
## Rows: 211 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): kW
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
energy2 <- read_csv("Carbon dioxide emissions.csv")
## Rows: 216 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): metric tonnes of CO2
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
energy3 <- read_csv("Energy consumption per capita.csv")
## Rows: 195 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): Btu/person
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
comm1 <- read_csv("Telephones - fixed lines.csv")
## Rows: 226 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): value
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
comm2 <- read_csv("Telephones - mobile cellular.csv")
## Rows: 225 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): value
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
comm3 <- read_csv("Broadband - fixed subscriptions.csv")
## Rows: 217 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): value
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
econ1 <- read_csv("Inflation rate (consumer prices).csv")
## Rows: 216 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): name, slug, date_of_information, region
## dbl (1): ranking
## num (1): %
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
econ2 <- read_csv("Youth unemployment rate (ages 15-24).csv")
## Rows: 197 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (3): %, date_of_information, ranking
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
econ3 <- read_csv("Public debt.csv")
## Rows: 207 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): name, slug, date_of_information, region
## dbl (2): % of GDP, ranking
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
econ4 <- read_csv("Debt - external.csv")
## Rows: 122 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): name, slug, value, region
## dbl (2): date_of_information, ranking
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
energy1 <- energy1 %>% select(name, energy_capacity = `kW`)
energy2 <- energy2 %>% select(name, co2 = `metric tonnes of CO2`)
energy3 <- energy3 %>% select(name, energy_pc = `Btu/person`)
comm1 <- comm1 %>% select(name, fixlines = `value`)
comm2 <- comm2 %>% select(name, mobile = `value`)
comm3 <- comm3 %>% select(name, broadband = `value`)
econ1 <- econ1 %>% select(name, inflation = `%`)
econ2 <- econ2 %>% select(name, youth_unemp = `%`)
econ3 <- econ3 %>% select(name, public_debt = `% of GDP`)
econ4 <- econ4 %>% select(name, external_debt = `value`)
df <- reduce(list(
energy1, energy2, energy3,
comm1, comm2, comm3,
econ1, econ2, econ3, econ4
), full_join, by = "name")
indep_vars <- df %>%
select(fixlines, mobile, broadband, energy_capacity, co2, energy_pc) %>%
scale()
data_reg <- cbind(
as.data.frame(indep_vars),
inflation = df$inflation,
youth_unemp = df$youth_unemp,
public_debt = df$public_debt
)
# Inflación como dependiente
model1 <- lm(inflation ~ ., data = data_reg)
summary(model1)
##
## Call:
## lm(formula = inflation ~ ., data = data_reg)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3833 -1349 -919 -355 144435
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2127.77 1931.66 1.102 0.272
## fixlines -812.45 2769.79 -0.293 0.770
## mobile 104.66 2108.94 0.050 0.960
## broadband -1403.54 3544.82 -0.396 0.693
## energy_capacity 6643.31 9983.49 0.665 0.507
## co2 -4553.27 8475.73 -0.537 0.592
## energy_pc -155.69 872.43 -0.178 0.859
## youth_unemp -28.31 70.67 -0.401 0.689
## public_debt -14.44 25.82 -0.559 0.577
##
## Residual standard error: 11040 on 173 degrees of freedom
## (50 observations deleted due to missingness)
## Multiple R-squared: 0.005861, Adjusted R-squared: -0.04011
## F-statistic: 0.1275 on 8 and 173 DF, p-value: 0.998
# Desempleo juvenil como dependiente
model2 <- lm(youth_unemp ~ ., data = data_reg)
summary(model2)
##
## Call:
## lm(formula = youth_unemp ~ ., data = data_reg)
##
## Residuals:
## Min 1Q Median 3Q Max
## -16.631 -7.531 -2.496 5.583 59.826
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.366e+01 1.807e+00 7.560 2.26e-12 ***
## fixlines -2.225e+00 2.974e+00 -0.748 0.4554
## mobile -2.497e+00 2.260e+00 -1.105 0.2707
## broadband 3.834e-01 3.814e+00 0.101 0.9200
## energy_capacity -4.750e+00 1.074e+01 -0.442 0.6590
## co2 8.483e+00 9.099e+00 0.932 0.3525
## energy_pc -1.734e+00 9.290e-01 -1.867 0.0636 .
## inflation -3.274e-05 8.172e-05 -0.401 0.6892
## public_debt 3.947e-02 2.763e-02 1.429 0.1549
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.88 on 173 degrees of freedom
## (50 observations deleted due to missingness)
## Multiple R-squared: 0.0382, Adjusted R-squared: -0.006275
## F-statistic: 0.8589 on 8 and 173 DF, p-value: 0.5524
# Deuda pública como dependiente
model3 <- lm(public_debt ~ ., data = data_reg)
summary(model3)
##
## Call:
## lm(formula = public_debt ~ ., data = data_reg)
##
## Residuals:
## Min 1Q Median 3Q Max
## -61.500 -20.029 -2.535 13.730 125.430
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.223e+01 4.092e+00 12.766 < 2e-16 ***
## fixlines 2.595e+01 7.907e+00 3.282 0.00125 **
## mobile 3.116e+00 6.199e+00 0.503 0.61581
## broadband -9.309e+00 1.041e+01 -0.894 0.37235
## energy_capacity 3.667e+01 2.927e+01 1.253 0.21205
## co2 -5.333e+01 2.462e+01 -2.166 0.03167 *
## energy_pc 2.191e+00 2.561e+00 0.855 0.39355
## inflation -1.250e-04 2.234e-04 -0.559 0.57663
## youth_unemp 2.954e-01 2.068e-01 1.429 0.15493
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 32.49 on 173 degrees of freedom
## (50 observations deleted due to missingness)
## Multiple R-squared: 0.1688, Adjusted R-squared: 0.1304
## F-statistic: 4.391 on 8 and 173 DF, p-value: 7.492e-05