knitr::opts_chunk$set(echo =TRUE)
# Growth and Trade Share scatterplot and regression analysis

library(ggplot2)
#library(dplyr)
setwd("C:/Users/Manjot/Downloads")
Growth <- read.csv("Growth.csv")
#tibble(Growth)
Average_Growth <- Growth$growth
Average_Trade_Share <- Growth$tradeshare
x <- data.frame(Average_Growth,Average_Trade_Share)
ggplot(x, aes(x = Average_Growth, y = Average_Trade_Share)) + geom_point(color = "red", size = 1.5) + labs(title = "Average Growth Rates vs Average Trade share",x = "Average Growth",y = "Average Trade Share")

#There is a weak positive linear relationship between the Average Growth rates in a country and it's Average Trade share. This relationship is summed up as follows most countries that have negative or near zero average growth rates have average trade shares ranging from 0 to 0.80.

model <-lm(Average_Growth ~ Average_Trade_Share)
summary(model)
## 
## Call:
## lm(formula = Average_Growth ~ Average_Trade_Share)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.2869 -0.8032  0.3969  0.9856  3.2188 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)  
## (Intercept)           1.0918     0.5074   2.151   0.0355 *
## Average_Trade_Share   1.0419     0.8784   1.186   0.2403  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.532 on 59 degrees of freedom
## Multiple R-squared:  0.02329,    Adjusted R-squared:  0.006737 
## F-statistic: 1.407 on 1 and 59 DF,  p-value: 0.2403
# Histrogram for Growth 
y <- x$Average_Growth
print(y)
##  [1]  1.91516793  0.61764508  4.30475903  2.93009663  1.71226490  0.70826310
##  [7]  2.88032675  2.22701430  0.06020596 -0.65793407  1.97514737  2.93298149
## [13]  3.22405005  2.43128085 -2.81194448  1.02530861  1.97394180  2.69816303
## [19] -2.75147796  0.35505781  2.45368814  2.38598847  1.96221948  1.12413180
## [25]  1.15874064  2.79849434 -0.88355076  0.92923063  0.59778476 -0.60755610
## [31]  1.44699538  4.87669516  1.88813424 -0.43782407  1.12078643  2.38809299
## [37]  2.17937016  1.42186534  2.88918519  0.83815551  2.38193154  1.61369658
## [43]  3.64730978  0.46277532  3.01238894  2.81096935  0.39202112  3.18249369
## [49] -0.33983421  2.49876904 -0.96316224  2.70459843  2.02718854  1.12037110
## [55]  1.96250916  3.25449395  0.41779017  2.20057726  4.11454391  2.65133452
## [61]  3.02417779
y <- data.frame(x$Average_Growth)
print(y)
##    x.Average_Growth
## 1        1.91516793
## 2        0.61764508
## 3        4.30475903
## 4        2.93009663
## 5        1.71226490
## 6        0.70826310
## 7        2.88032675
## 8        2.22701430
## 9        0.06020596
## 10      -0.65793407
## 11       1.97514737
## 12       2.93298149
## 13       3.22405005
## 14       2.43128085
## 15      -2.81194448
## 16       1.02530861
## 17       1.97394180
## 18       2.69816303
## 19      -2.75147796
## 20       0.35505781
## 21       2.45368814
## 22       2.38598847
## 23       1.96221948
## 24       1.12413180
## 25       1.15874064
## 26       2.79849434
## 27      -0.88355076
## 28       0.92923063
## 29       0.59778476
## 30      -0.60755610
## 31       1.44699538
## 32       4.87669516
## 33       1.88813424
## 34      -0.43782407
## 35       1.12078643
## 36       2.38809299
## 37       2.17937016
## 38       1.42186534
## 39       2.88918519
## 40       0.83815551
## 41       2.38193154
## 42       1.61369658
## 43       3.64730978
## 44       0.46277532
## 45       3.01238894
## 46       2.81096935
## 47       0.39202112
## 48       3.18249369
## 49      -0.33983421
## 50       2.49876904
## 51      -0.96316224
## 52       2.70459843
## 53       2.02718854
## 54       1.12037110
## 55       1.96250916
## 56       3.25449395
## 57       0.41779017
## 58       2.20057726
## 59       4.11454391
## 60       2.65133452
## 61       3.02417779
ggplot(y, aes(x = Average_Growth)) + geom_histogram(binwidth = 1.0, color = "black", fill = "red") + labs(title = "Average Growth histogram", x = "Average Growth", y = "Frequency")

# Growth and Years-school Regression and histogram
z <- data.frame(Growth$growth,Growth$yearsschool)
print(z)
##    Growth.growth Growth.yearsschool
## 1     1.91516793               1.45
## 2     0.61764508               4.99
## 3     4.30475903               6.71
## 4     2.93009663               2.89
## 5     1.71226490               8.66
## 6     0.70826310               0.79
## 7     2.88032675               3.80
## 8     2.22701430               2.97
## 9     0.06020596               3.02
## 10   -0.65793407               0.70
## 11    1.97514737               9.03
## 12    2.93298149               4.56
## 13    3.22405005               4.37
## 14    2.43128085               4.65
## 15   -2.81194448               0.54
## 16    1.02530861               5.07
## 17    1.97394180               2.41
## 18    2.69816303               0.63
## 19   -2.75147796               0.20
## 20    0.35505781               4.68
## 21    2.45368814               7.64
## 22    2.38598847               8.07
## 23    1.96221948               7.67
## 24    1.12413180               9.55
## 25    1.15874064               3.77
## 26    2.79849434               7.51
## 27   -0.88355076               2.53
## 28    0.92923063               1.42
## 29    0.59778476               1.69
## 30   -0.60755610               1.70
## 31    1.44699538               4.99
## 32    4.87669516               3.45
## 33    1.88813424               7.67
## 34   -0.43782407               1.62
## 35    1.12078643               4.31
## 36    2.38809299               2.95
## 37    2.17937016              10.07
## 38    1.42186534               6.87
## 39    2.88918519               3.65
## 40    0.83815551               1.54
## 41    2.38193154               3.35
## 42    1.61369658               3.92
## 43    3.64730978               1.94
## 44    0.46277532               0.27
## 45    3.01238894               5.63
## 46    2.81096935               6.99
## 47    0.39202112               4.06
## 48    3.18249369               5.56
## 49   -0.33983421               0.53
## 50    2.49876904               2.38
## 51   -0.96316224               0.69
## 52    2.70459843               3.43
## 53    2.02718854               4.26
## 54    1.12037110               1.13
## 55    1.96250916               1.20
## 56    3.25449395               6.45
## 57    0.41779017               2.46
## 58    2.20057726               5.27
## 59    4.11454391               2.34
## 60    2.65133452               7.46
## 61    3.02417779               2.44
Average_Year_School <-  Growth$yearsschool
ggplot(z, aes(x = Average_Growth, y = Average_Year_School )) + geom_point(color = "red", size = 1.5) + labs( title = "Average Growth vs Average Year School", x = "Average Growth", y = "Average Year school") 

#There is a moderately strong relationship between average growth rates and average schooling rates in a country. The relationship is summed as follows most countries that have higher growth from 0% to 5% have on average higher educational attainment rates. Even though the this relationship is only moderately strong. It shows the importance of countries investing in their physical stock, but importantly their human capital stock as well.

model_1 <- lm(Average_Growth ~ Average_Year_School, data = z)
summary(model_1)
## 
## Call:
## lm(formula = Average_Growth ~ Average_Year_School, data = z)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.6184 -0.9327 -0.0893  0.9947  3.3586 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          0.67434    0.33070   2.039 0.045927 *  
## Average_Year_School  0.24458    0.06968   3.510 0.000865 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.41 on 59 degrees of freedom
## Multiple R-squared:  0.1728, Adjusted R-squared:  0.1587 
## F-statistic: 12.32 on 1 and 59 DF,  p-value: 0.0008646