GDP & Unemployment

Let’s consider a scenario where we want to analyze the relationship between a country’s GDP (Gross Domestic Product) and its unemployment rate. The hypothesis is that higher GDP leads to lower unemployment rates due to increased economic activity and job creation. First, we’ll generate a simulated dataset with two variables: GDP and unemployment rate. We’ll assume a linear relationship between the two variables with some random noise.

Import .

set.seed(123)

n = 10000
gdp = rnorm(n, 1000, 200)
unemployment = 10-0.05*gdp + rnorm(n, 0, 2)

data = data.frame(GDP = gdp, Unemployment = unemployment)
head (data)
##         GDP Unemployment
## 1  887.9049    -29.65379
## 2  953.9645    -38.03185
## 3 1311.7417    -53.73316
## 4 1014.1017    -41.84139
## 5 1025.8575    -40.84270
## 6 1343.0130    -54.88668

Correlation Matrix

library(corrplot)
## corrplot 0.92 loaded
corrplot(cor(data), method = 'number')

Dari Correlation Matrix diatas, ditemukan bahwa nilai korelasi kedua variabel tersebut adalah -0.98 yang merupakan korelasi negatif yang sangat kuat. Dimana jika GDP Naik maka Angka Unemployment juga Turun signifikan. Begitu juga sebaliknya.

Plot

library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
fig <- plot_ly(
  data, x = ~GDP, y = ~Unemployment,
  text = ~paste("GDP: ", GDP, '$<br>Unemployment Rate:', Unemployment),
  color = ~GDP, size = ~Unemployment
)

fig
## No trace type specified:
##   Based on info supplied, a 'scatter' trace seems appropriate.
##   Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: `line.width` does not currently support multiple values.

Dari Scatter Plot diatas, sesuai dengan nilai Korelasi yang signifikan didapatkan bahwa jelas nilai GDP dan Rate Unemployment sangat bertolak belakang secara signifikan. Serta, data yang ada membentuk sebuah persebaran Linear sehingga akan sangat cocok untuk dibuat Simple Linear.

Linear Model

modela = lm(Unemployment ~ GDP, data)
summary(modela)
## 
## Call:
## lm(formula = Unemployment ~ GDP, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.9652 -1.3378 -0.0148  1.3617  7.5393 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  9.9214218  0.1022358   97.04   <2e-16 ***
## GDP         -0.0499396  0.0001003 -497.89   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.003 on 9998 degrees of freedom
## Multiple R-squared:  0.9612, Adjusted R-squared:  0.9612 
## F-statistic: 2.479e+05 on 1 and 9998 DF,  p-value: < 2.2e-16

Menggunakan Simple Linear Model, didapatkan bahwa Model
\[ 9.921 - 0.049*GDP \]
Dimana jika ada kenaikan GDP Sebesar 1 USD akan meurunkan Index Pengangguran sebesar 0.049. Menggunakan model tersebut kita bisa melakukan beberapa prediksi.

Conclusion

GDP dan Uenmployment Rate memiliki hubungan linear negatif dengan nilai korelasi yang snagat signifikan yaitu -0.98. Menggunakan Model Linear, kita mendapatkan model yaitu
\[ 9.921 - 0.049*GDP \]
Dimana setiap kenaikan $1 GDP maka menurunkan angka pengangguran sebesar 0.049 Atau setiap USD 20 Menurunkan 1 Index Pengangguran.

GDP Growth & Investment Rate

The objective of this study case is to demonstrate how simple linear regression can be used to analyze economic data and make predictions based on the relationship between two variables. Lets generate data for GDP growth rate (gdp_growth) and investment rate (investment_rate) for a fictional country over a period of 10 years.

set.seed(123)

years = (1:10)
investment_rate= rnorm(10, 20, 5)
gdp_growth = 3+0.8*investment_rate + rnorm(10, 0, 1)

data1 = data.frame(years, investment_rate, gdp_growth)
data1
##    years investment_rate gdp_growth
## 1      1        17.19762   17.98218
## 2      2        18.84911   18.43910
## 3      3        27.79354   25.63560
## 4      4        20.35254   19.39272
## 5      5        20.64644   18.96131
## 6      6        28.57532   27.64717
## 7      7        22.30458   21.34152
## 8      8        13.67469   11.97314
## 9      9        16.56574   16.95394
## 10    10        17.77169   16.74456

Correlation

data1a = data1[, -1]
corrplot(cor(data1a), "number")

Nilai GDP Growth dan Investment Rate memiliki pengaruh positif yang signifikan sebesar 0.98 dimana Ketika Investment Rate Naik, Maka GDP Growth juga naik.

Plot

library(plotly)

figg <- plot_ly(
  data1a, x = ~gdp_growth, y = ~investment_rate,
  text = ~paste("GDP Growth: ", gdp_growth, '$<br> Investment rate:', investment_rate),
  color = ~gdp_growth, size = ~investment_rate
)

figg
## No trace type specified:
##   Based on info supplied, a 'scatter' trace seems appropriate.
##   Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: `line.width` does not currently support multiple values.

Linear Model

modelb = lm(gdp_growth ~ investment_rate, data1a)
summary(modelb)
## 
## Call:
## lm(formula = gdp_growth ~ investment_rate, data = data1a)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.33303 -0.64421 -0.02448  0.49596  1.41472 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      0.64706    1.31108   0.494    0.635    
## investment_rate  0.92573    0.06282  14.736 4.42e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8988 on 8 degrees of freedom
## Multiple R-squared:  0.9645, Adjusted R-squared:   0.96 
## F-statistic: 217.1 on 1 and 8 DF,  p-value: 4.423e-07

Menggunakan Simple Linear Model, didapatkan bahwa Model
\[ 0.647 + 0.925*Invest rate \]
Dimana jika ada kenaikan Investment Rate sebesar 1 , Maka ada pertumbuhan GDP Sebesar 0.925.

Predicting

Diasumsikan di 5 tahun berikutnya kita mendapatkan Investment rate, maka kita bisa memprediksi Nilai Petumbuhan GDP Dengan Nilai Akurasi 96.45% menggunakan Model yang barusan dibuat.

test = data.frame(investment_rate=(c(20,21,22,19,18)))
prediksi = predict(modelb, test)

test$gdp_growth = prediksi

test
##   investment_rate gdp_growth
## 1              20   19.16171
## 2              21   20.08744
## 3              22   21.01317
## 4              19   18.23598
## 5              18   17.31024
ggplot(test, aes(x=gdp_growth, y=investment_rate)) + 
  geom_point()

Conclusions and Insights

Kesimpulannya, Investment Rate dan Growth GDP Berhubungan signifikan secara positif. Dimana jika Investment rate naik, maka GDP Bertumbuh berlaku juga sebaliknya.

Serta, Menggunakan Simple Linear Model, didapatkan bahwa Model
\[ 0.647 + 0.925*Invest rate \]
Dimana jika ada kenaikan Investment Rate sebesar 1 , Maka ada pertumbuhan GDP Sebesar 0.925.

Dengan nilai koralsi dan model yang dibuat, dipastikan Perubahan Nilai Investasi, sangat berpengaruh pada pertumbuhan GDP