mydata <- read.table("C:\\Users\\Ivan Kechev\\Downloads\\rawdatahw2.csv", header = TRUE, sep=",", dec=".")

sources: https://ec.europa.eu/eurostat/databrowser/view/isoc_sk_dskl_i$dv_317/default/table?lang=en https://ec.europa.eu/eurostat/databrowser/view/edat_aes_l21$dv_1602/default/table?lang=en https://ec.europa.eu/eurostat/databrowser/view/educ_ipart$dv_437/default/table?lang=en

The units of measure for share of people who speak at least one language (x1 - foreignlanguage), share of people that have any participation in eduction (x2 - education) and share of people who have average digital skills or above average (y - digitalskills) have the same unit of measure which is %.

The research question is - do countries with higher share of people that speak at least one foreign language and/or that have participated in education have higher share of people with average or above average digital skills.

mydata <- as.data.frame(mydata)
head(mydata)
##       Country digitalskills education foreignlanguage
## 1      Norway         82.55      97.2            12.0
## 2 Netherlands         79.37      99.6            22.2
## 3     Finland         76.47      59.3            19.5
## 4      Sweden         72.42      94.2            49.9
## 5     Germany         70.16      95.8            40.1
## 6     Denmark         69.98      97.8            29.8
library(psych)
summary(mydata[c(-1)])
##  digitalskills     education      foreignlanguage
##  Min.   :29.40   Min.   : 54.50   Min.   :12.00  
##  1st Qu.:50.06   1st Qu.: 78.38   1st Qu.:25.43  
##  Median :55.98   Median : 91.25   Median :36.05  
##  Mean   :56.90   Mean   : 86.28   Mean   :35.88  
##  3rd Qu.:64.82   3rd Qu.: 97.35   3rd Qu.:47.10  
##  Max.   :82.55   Max.   :100.00   Max.   :61.60

library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
scatterplotMatrix(mydata[ , c(-1, -5)], smooth=FALSE)

library(Hmisc)
## 
## Attaching package: 'Hmisc'
## The following object is masked from 'package:psych':
## 
##     describe
## The following objects are masked from 'package:base':
## 
##     format.pval, units
rcorr(as.matrix(mydata[ , c(-1, -5)]))
##                 digitalskills education foreignlanguage
## digitalskills            1.00      0.27           -0.34
## education                0.27      1.00           -0.33
## foreignlanguage         -0.34     -0.33            1.00
## 
## n= 28 
## 
## 
## P
##                 digitalskills education foreignlanguage
## digitalskills                 0.1661    0.0737         
## education       0.1661                  0.0874         
## foreignlanguage 0.0737        0.0874

As from the correlation matrix we have only semistrong correlation, none with a p-value of less than 0.05. The strongest correlation though is between foreign language and digital skills., although it shows a negative one, meaning that when the share of people that speak at least one foreign language increases, the share of people with average or above average digital skills decreases. Regarding this we could say that languages require more of a creative mind and digital skills more of a logical mind, thus people who are good with languages are not necessarily good with digital skills too. In fact they might be worse at it, because their creative side is more developed than their logical one.

fit <- lm(digitalskills ~ education + foreignlanguage, data=mydata)
summary(fit)
## 
## Call:
## lm(formula = digitalskills ~ education + foreignlanguage, data = mydata)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -26.291  -6.202  -0.255   8.978  19.418 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)  
## (Intercept)      52.7728    19.4033   2.720   0.0117 *
## education         0.1643     0.1838   0.894   0.3797  
## foreignlanguage  -0.2803     0.1921  -1.459   0.1570  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 12.62 on 25 degrees of freedom
## Multiple R-squared:  0.1452, Adjusted R-squared:  0.07683 
## F-statistic: 2.123 on 2 and 25 DF,  p-value: 0.1407
mydata$Fitted <- round(fit$fitted.values, 2)
head(mydata[c(-4, -5)])
##       Country digitalskills education
## 1      Norway         82.55      97.2
## 2 Netherlands         79.37      99.6
## 3     Finland         76.47      59.3
## 4      Sweden         72.42      94.2
## 5     Germany         70.16      95.8
## 6     Denmark         69.98      97.8
mydata$Std.Fitted <- scale(fit$fitted.values)
mydata$Std.Resid <- round(rstandard(fit), 3)
mydata$CooksD <- round(cooks.distance(fit), 3)
hist(mydata$Std.Resid, xlab="Standardized Residuals", ylab="frequency", main="Histogram of Standardized Residuals")

shapiro.test(mydata$Std.Resid)
## 
##  Shapiro-Wilk normality test
## 
## data:  mydata$Std.Resid
## W = 0.96835, p-value = 0.5372

From the histogram and the high p-value of the shapiro-wilk normality test we can conclude that the requirement for normal distribution of std. residuas is met.

hist(mydata$CooksD, xlab="Cooks D", ylab="frequency", main="Histogram of Cooks Distances")

From the histogram we can see that we have a unit with a Cooks distance much higher than the rest, thus this one should be removed.

head(mydata[order(-mydata$CooksD),], 8) #8 units with higest Cooks Distance
##        Country digitalskills education foreignlanguage Fitted  Std.Fitted
## 3      Finland         76.47      59.3            19.5  57.05  0.03134578
## 1       Norway         82.55      97.2            12.0  65.38  1.69521758
## 4       Sweden         72.42      94.2            49.9  54.27 -0.52505925
## 28    Bulgaria         29.40      79.5            36.2  55.69 -0.24057026
## 2  Netherlands         79.37      99.6            22.2  62.92  1.20295192
## 27     Romania         30.97      82.4            36.5  56.08 -0.16217908
## 26       Italy         41.51      98.8            37.9  58.39  0.29773879
## 7      Austria         65.55      90.9            52.2  53.08 -0.76213899
##    Std.Resid CooksD
## 3      1.860  0.534
## 1      1.479  0.134
## 4      1.525  0.097
## 28    -2.131  0.072
## 2      1.366  0.062
## 27    -2.029  0.055
## 26    -1.389  0.051
## 7      1.049  0.047

Finland has a CooksD of 0.534, which is higher by 0.4 compared to the subsequent one. We should remove Finland.

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
## 
##     src, summarize
## The following object is masked from 'package:car':
## 
##     recode
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
mydata <- mydata %>%
  filter(!Country == "Finland") #removing Finland due to its high Cooks Distance
fit <- lm(digitalskills ~ education + foreignlanguage, data=mydata)
summary(fit)
## 
## Call:
## lm(formula = digitalskills ~ education + foreignlanguage, data = mydata)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -23.9999  -4.1839  -0.5615   9.0576  19.9417 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)  
## (Intercept)      28.9587    22.0220   1.315   0.2009  
## education         0.3606     0.2008   1.796   0.0851 .
## foreignlanguage  -0.1168     0.2002  -0.583   0.5651  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.96 on 24 degrees of freedom
## Multiple R-squared:  0.1949, Adjusted R-squared:  0.1278 
## F-statistic: 2.905 on 2 and 24 DF,  p-value: 0.07416
mydata$Fitted <- round(fit$fitted.values, 2)
head(mydata[c(-4, -5)])
##       Country digitalskills education  Std.Fitted Std.Resid CooksD
## 1      Norway         82.55      97.2  1.69521758     1.479  0.134
## 2 Netherlands         79.37      99.6  1.20295192     1.366  0.062
## 3      Sweden         72.42      94.2 -0.52505925     1.525  0.097
## 4     Germany         70.16      95.8  0.07610437     1.055  0.026
## 5     Denmark         69.98      97.8  0.71838935     0.776  0.013
## 6     Austria         65.55      90.9 -0.76213899     1.049  0.047

Unfortunately, looking at the p-values of the partial regression coefficients, we can see that none is statistically significant enough (p-value < 0.05). Thus neither rate of educated people nor rate of people who speak at least one foreign language significantly affects the rate of people that have an average or above average level of digital skills.

mydata$Std.Fitted <- scale(mydata$Fitted)
library(car)
scatterplot(y = mydata$Std.Resid, x = mydata$Std.Fitted, ylab = "Standardized Residuals", xlab = "Standardized Fitted Values", boxplots=FALSE, regline=FALSE, smooth=FALSE)
## Warning in plot.window(...): "regline" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "regline" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "regline" is not a
## graphical parameter

## Warning in axis(side = side, at = at, labels = labels, ...): "regline" is not a
## graphical parameter
## Warning in box(...): "regline" is not a graphical parameter
## Warning in title(...): "regline" is not a graphical parameter

library(olsrr)
## 
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
## 
##     rivers
ols_test_breusch_pagan(fit)
## 
##  Breusch Pagan Test for Heteroskedasticity
##  -----------------------------------------
##  Ho: the variance is constant            
##  Ha: the variance is not constant        
## 
##                   Data                    
##  -----------------------------------------
##  Response : digitalskills 
##  Variables: fitted values of digitalskills 
## 
##         Test Summary         
##  ----------------------------
##  DF            =    1 
##  Chi2          =    0.2255259 
##  Prob > Chi2   =    0.6348613

From the scatterplot distribution of std. residuals and fitted values and the bresuch pagan test for heteroskedasticity, we may conclude that there is no heteroskedasticity (at p=0.64).

summary(fit)
## 
## Call:
## lm(formula = digitalskills ~ education + foreignlanguage, data = mydata)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -23.9999  -4.1839  -0.5615   9.0576  19.9417 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)  
## (Intercept)      28.9587    22.0220   1.315   0.2009  
## education         0.3606     0.2008   1.796   0.0851 .
## foreignlanguage  -0.1168     0.2002  -0.583   0.5651  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.96 on 24 degrees of freedom
## Multiple R-squared:  0.1949, Adjusted R-squared:  0.1278 
## F-statistic: 2.905 on 2 and 24 DF,  p-value: 0.07416

Once again, none of the coefficients is significant enough to be interpreted. The r^2 is also weak at 0.2, with the adjusted one being 0.13 - only a small share of variance in the share of people who have average or above digital skills in EU countries is explained by the regression model.

sqrt(summary(fit)$r.squared)
## [1] 0.4414751

This represents the multiple correlation coefficient, which is moderate at 0.45.