Assignment 1 FIT 3152

Michael Gowanto

Student ID: 31225381

Set The Working Directory

# (1) set the current working directory
setwd("D:/Uni/Year 4 Sem 1/FIT3152/Assignment 1")

Code Running for Covid-19 Data Analysis

rm(list = ls())
set.seed(31225381) # XXXXXXXX = your student ID
cvbase = read.csv("PsyCoronaBaselineExtract.csv")
cvbase <- cvbase[sample(nrow(cvbase), 40000), ] # 40000 rows

Library Package Access

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Question 1A-> Descriptive Analysis

# shows how many rows and columns in the data
dim(cvbase)
## [1] 40000    52
# shows the attributes of the data
names(cvbase)
##  [1] "employstatus_1"      "employstatus_2"      "employstatus_3"     
##  [4] "employstatus_4"      "employstatus_5"      "employstatus_6"     
##  [7] "employstatus_7"      "employstatus_8"      "employstatus_9"     
## [10] "employstatus_10"     "isoFriends_inPerson" "isoOthPpl_inPerson" 
## [13] "isoFriends_online"   "isoOthPpl_online"    "lone01"             
## [16] "lone02"              "lone03"              "happy"              
## [19] "lifeSat"             "MLQ"                 "bor01"              
## [22] "bor02"               "bor03"               "consp01"            
## [25] "consp02"             "consp03"             "rankOrdLife_1"      
## [28] "rankOrdLife_2"       "rankOrdLife_3"       "rankOrdLife_4"      
## [31] "rankOrdLife_5"       "rankOrdLife_6"       "c19perBeh01"        
## [34] "c19perBeh02"         "c19perBeh03"         "c19RCA01"           
## [37] "c19RCA02"            "c19RCA03"            "coronaClose_1"      
## [40] "coronaClose_2"       "coronaClose_3"       "coronaClose_4"      
## [43] "coronaClose_5"       "coronaClose_6"       "gender"             
## [46] "age"                 "edu"                 "coded_country"      
## [49] "c19ProSo01"          "c19ProSo02"          "c19ProSo03"         
## [52] "c19ProSo04"
# shows data types of each indicator
str(cvbase)
## 'data.frame':    40000 obs. of  52 variables:
##  $ employstatus_1     : int  NA NA 1 NA NA NA NA NA NA NA ...
##  $ employstatus_2     : int  1 NA NA 1 NA NA NA NA 1 NA ...
##  $ employstatus_3     : int  NA NA NA NA 1 NA NA NA NA 1 ...
##  $ employstatus_4     : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ employstatus_5     : int  NA NA NA NA NA NA NA 1 NA NA ...
##  $ employstatus_6     : int  NA 1 NA NA NA NA NA NA NA NA ...
##  $ employstatus_7     : int  NA NA NA NA NA NA 1 NA NA NA ...
##  $ employstatus_8     : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ employstatus_9     : int  NA NA NA NA NA 1 NA 1 1 NA ...
##  $ employstatus_10    : int  NA NA NA NA NA NA NA 1 NA NA ...
##  $ isoFriends_inPerson: int  2 3 3 5 3 3 0 1 0 2 ...
##  $ isoOthPpl_inPerson : int  7 1 2 1 0 0 1 1 2 3 ...
##  $ isoFriends_online  : int  7 7 3 0 7 7 1 2 7 1 ...
##  $ isoOthPpl_online   : int  4 2 0 0 0 7 0 1 7 0 ...
##  $ lone01             : int  1 2 1 4 1 3 2 3 1 1 ...
##  $ lone02             : int  2 4 2 4 4 4 4 4 2 1 ...
##  $ lone03             : int  1 3 1 4 1 2 1 2 1 1 ...
##  $ happy              : int  9 8 6 6 9 6 4 7 9 6 ...
##  $ lifeSat            : int  6 4 5 3 6 4 2 4 6 4 ...
##  $ MLQ                : int  2 1 2 1 3 1 -2 2 3 2 ...
##  $ bor01              : int  1 0 2 1 1 2 0 2 -3 -2 ...
##  $ bor02              : int  0 0 2 1 0 3 2 1 0 -2 ...
##  $ bor03              : int  2 -1 2 1 2 -1 2 1 2 3 ...
##  $ consp01            : int  7 9 4 4 9 7 10 10 10 2 ...
##  $ consp02            : int  7 8 4 10 10 7 10 9 10 6 ...
##  $ consp03            : int  4 8 6 3 6 6 9 10 9 6 ...
##  $ rankOrdLife_1      : chr  "E" "E" "F" "D" ...
##  $ rankOrdLife_2      : chr  "D" "D" "E" "C" ...
##  $ rankOrdLife_3      : chr  "F" "F" "D" "E" ...
##  $ rankOrdLife_4      : chr  "B" "C" "C" "B" ...
##  $ rankOrdLife_5      : chr  "A" "A" "A" "A" ...
##  $ rankOrdLife_6      : chr  "C" "B" "B" "F" ...
##  $ c19perBeh01        : int  2 1 3 1 2 3 3 3 3 0 ...
##  $ c19perBeh02        : int  2 2 3 3 2 3 3 3 3 2 ...
##  $ c19perBeh03        : int  1 2 2 2 2 3 3 3 3 2 ...
##  $ c19RCA01           : int  2 2 -1 2 2 0 2 3 3 3 ...
##  $ c19RCA02           : int  3 1 2 2 2 3 2 3 3 2 ...
##  $ c19RCA03           : int  1 1 -1 2 2 3 -2 1 1 2 ...
##  $ coronaClose_1      : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ coronaClose_2      : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ coronaClose_3      : int  NA NA NA NA NA NA 1 NA NA NA ...
##  $ coronaClose_4      : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ coronaClose_5      : int  NA NA NA 1 NA NA NA NA NA NA ...
##  $ coronaClose_6      : int  1 1 1 NA 1 1 NA 1 1 1 ...
##  $ gender             : int  1 1 1 2 2 1 2 1 1 2 ...
##  $ age                : int  2 3 2 3 6 1 7 4 3 4 ...
##  $ edu                : int  4 6 6 4 3 5 5 4 6 4 ...
##  $ coded_country      : chr  "Netherlands" "Kazakhstan" "Germany" "Philippines" ...
##  $ c19ProSo01         : int  2 1 3 2 2 1 2 2 -2 -1 ...
##  $ c19ProSo02         : int  1 1 3 1 2 0 0 2 -2 -3 ...
##  $ c19ProSo03         : int  0 1 3 1 2 0 1 2 -3 -2 ...
##  $ c19ProSo04         : int  2 1 3 1 2 2 3 2 -3 2 ...

The data is created with the objective of analysing behaviours of each country during the pandemic in 2019 by holding multiple responses from respondents of particular countries after the survey. It holds 40,000 observations and 52 attributes that are attributable to the “Pre-Social Behaviour of 2019” analysis. Observing the attributes of the data, it holds mostly integers and characters.

Concerning the numerical attributes, the data includes employment status, loneliness, satisfaction, age, education, corona pre-social behaviors, the isolation, boredom, conspiracy, proximity.

summary(cvbase)
##  employstatus_1  employstatus_2  employstatus_3  employstatus_4 
##  Min.   :1       Min.   :1       Min.   :1       Min.   :1      
##  1st Qu.:1       1st Qu.:1       1st Qu.:1       1st Qu.:1      
##  Median :1       Median :1       Median :1       Median :1      
##  Mean   :1       Mean   :1       Mean   :1       Mean   :1      
##  3rd Qu.:1       3rd Qu.:1       3rd Qu.:1       3rd Qu.:1      
##  Max.   :1       Max.   :1       Max.   :1       Max.   :1      
##  NA's   :34342   NA's   :33216   NA's   :29156   NA's   :36481  
##  employstatus_5  employstatus_6  employstatus_7  employstatus_8 
##  Min.   :1       Min.   :1       Min.   :1       Min.   :1      
##  1st Qu.:1       1st Qu.:1       1st Qu.:1       1st Qu.:1      
##  Median :1       Median :1       Median :1       Median :1      
##  Mean   :1       Mean   :1       Mean   :1       Mean   :1      
##  3rd Qu.:1       3rd Qu.:1       3rd Qu.:1       3rd Qu.:1      
##  Max.   :1       Max.   :1       Max.   :1       Max.   :1      
##  NA's   :37969   NA's   :36901   NA's   :36377   NA's   :39250  
##  employstatus_9  employstatus_10 isoFriends_inPerson isoOthPpl_inPerson
##  Min.   :1       Min.   :1       Min.   :0.000       Min.   :0.000     
##  1st Qu.:1       1st Qu.:1       1st Qu.:0.000       1st Qu.:0.000     
##  Median :1       Median :1       Median :1.000       Median :1.000     
##  Mean   :1       Mean   :1       Mean   :2.069       Mean   :1.954     
##  3rd Qu.:1       3rd Qu.:1       3rd Qu.:4.000       3rd Qu.:3.000     
##  Max.   :1       Max.   :1       Max.   :7.000       Max.   :7.000     
##  NA's   :31878   NA's   :39080   NA's   :341         NA's   :552       
##  isoFriends_online isoOthPpl_online     lone01          lone02     
##  Min.   :0.000     Min.   :0.00     Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000     1st Qu.:0.00     1st Qu.:1.000   1st Qu.:2.000  
##  Median :5.000     Median :2.00     Median :2.000   Median :3.000  
##  Mean   :4.394     Mean   :2.85     Mean   :2.416   Mean   :2.663  
##  3rd Qu.:7.000     3rd Qu.:5.00     3rd Qu.:3.000   3rd Qu.:4.000  
##  Max.   :7.000     Max.   :7.00     Max.   :5.000   Max.   :5.000  
##  NA's   :972       NA's   :1179     NA's   :85      NA's   :118    
##      lone03          happy           lifeSat          MLQ         
##  Min.   :1.000   Min.   : 1.000   Min.   :1.00   Min.   :-3.0000  
##  1st Qu.:1.000   1st Qu.: 5.000   1st Qu.:3.00   1st Qu.: 0.0000  
##  Median :2.000   Median : 7.000   Median :4.00   Median : 1.0000  
##  Mean   :2.079   Mean   : 6.342   Mean   :4.14   Mean   : 0.8531  
##  3rd Qu.:3.000   3rd Qu.: 8.000   3rd Qu.:5.00   3rd Qu.: 2.0000  
##  Max.   :5.000   Max.   :10.000   Max.   :6.00   Max.   : 3.0000  
##  NA's   :140     NA's   :510      NA's   :109    NA's   :114      
##      bor01             bor02              bor03            consp01      
##  Min.   :-3.0000   Min.   :-3.00000   Min.   :-3.0000   Min.   : 0.000  
##  1st Qu.:-1.0000   1st Qu.:-2.00000   1st Qu.:-1.0000   1st Qu.: 5.000  
##  Median : 0.0000   Median : 0.00000   Median : 0.0000   Median : 7.000  
##  Mean   : 0.3304   Mean   : 0.04674   Mean   : 0.3069   Mean   : 6.832  
##  3rd Qu.: 2.0000   3rd Qu.: 2.00000   3rd Qu.: 2.0000   3rd Qu.: 9.000  
##  Max.   : 3.0000   Max.   : 3.00000   Max.   : 3.0000   Max.   :10.000  
##  NA's   :153       NA's   :164        NA's   :163       NA's   :1527    
##     consp02          consp03      rankOrdLife_1      rankOrdLife_2     
##  Min.   : 0.000   Min.   : 0.00   Length:40000       Length:40000      
##  1st Qu.: 5.000   1st Qu.: 4.00   Class :character   Class :character  
##  Median : 8.000   Median : 5.00   Mode  :character   Mode  :character  
##  Mean   : 7.148   Mean   : 5.58                                        
##  3rd Qu.: 9.000   3rd Qu.: 8.00                                        
##  Max.   :10.000   Max.   :10.00                                        
##  NA's   :1556     NA's   :1576                                         
##  rankOrdLife_3      rankOrdLife_4      rankOrdLife_5      rankOrdLife_6     
##  Length:40000       Length:40000       Length:40000       Length:40000      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   c19perBeh01      c19perBeh02      c19perBeh03        c19RCA01    
##  Min.   :-3.000   Min.   :-3.000   Min.   :-3.000   Min.   :-3.00  
##  1st Qu.: 2.000   1st Qu.: 2.000   1st Qu.: 1.000   1st Qu.: 0.00  
##  Median : 3.000   Median : 3.000   Median : 2.000   Median : 2.00  
##  Mean   : 2.311   Mean   : 2.432   Mean   : 1.843   Mean   : 1.27  
##  3rd Qu.: 3.000   3rd Qu.: 3.000   3rd Qu.: 3.000   3rd Qu.: 3.00  
##  Max.   : 3.000   Max.   : 3.000   Max.   : 3.000   Max.   : 3.00  
##  NA's   :128      NA's   :126      NA's   :132      NA's   :132    
##     c19RCA02         c19RCA03      coronaClose_1   coronaClose_2  
##  Min.   :-3.000   Min.   :-3.000   Min.   :1       Min.   :1      
##  1st Qu.: 2.000   1st Qu.: 0.000   1st Qu.:1       1st Qu.:1      
##  Median : 3.000   Median : 2.000   Median :1       Median :1      
##  Mean   : 2.056   Mean   : 1.162   Mean   :1       Mean   :1      
##  3rd Qu.: 3.000   3rd Qu.: 3.000   3rd Qu.:1       3rd Qu.:1      
##  Max.   : 3.000   Max.   : 3.000   Max.   :1       Max.   :1      
##  NA's   :142      NA's   :145      NA's   :39456   NA's   :38741  
##  coronaClose_3   coronaClose_4   coronaClose_5   coronaClose_6  
##  Min.   :1       Min.   :1       Min.   :1       Min.   :1      
##  1st Qu.:1       1st Qu.:1       1st Qu.:1       1st Qu.:1      
##  Median :1       Median :1       Median :1       Median :1      
##  Mean   :1       Mean   :1       Mean   :1       Mean   :1      
##  3rd Qu.:1       3rd Qu.:1       3rd Qu.:1       3rd Qu.:1      
##  Max.   :1       Max.   :1       Max.   :1       Max.   :1      
##  NA's   :38401   NA's   :35098   NA's   :35542   NA's   :10718  
##      gender           age             edu        coded_country     
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Length:40000      
##  1st Qu.:1.000   1st Qu.:2.000   1st Qu.:4.000   Class :character  
##  Median :1.000   Median :3.000   Median :5.000   Mode  :character  
##  Mean   :1.391   Mean   :2.901   Mean   :4.406                     
##  3rd Qu.:2.000   3rd Qu.:4.000   3rd Qu.:5.000                     
##  Max.   :3.000   Max.   :8.000   Max.   :7.000                     
##  NA's   :228     NA's   :250     NA's   :268                       
##    c19ProSo01        c19ProSo02        c19ProSo03        c19ProSo04    
##  Min.   :-3.0000   Min.   :-3.0000   Min.   :-3.0000   Min.   :-3.000  
##  1st Qu.: 0.0000   1st Qu.: 0.0000   1st Qu.: 0.0000   1st Qu.: 0.000  
##  Median : 1.0000   Median : 1.0000   Median : 1.0000   Median : 2.000  
##  Mean   : 0.9778   Mean   : 0.6817   Mean   : 0.5512   Mean   : 1.291  
##  3rd Qu.: 2.0000   3rd Qu.: 2.0000   3rd Qu.: 2.0000   3rd Qu.: 2.000  
##  Max.   : 3.0000   Max.   : 3.0000   Max.   : 3.0000   Max.   : 3.000  
##  NA's   :125       NA's   :137       NA's   :145       NA's   :153

Missing Values

# calculate the number of missing values in each column
colSums(is.na(cvbase))
##      employstatus_1      employstatus_2      employstatus_3      employstatus_4 
##               34342               33216               29156               36481 
##      employstatus_5      employstatus_6      employstatus_7      employstatus_8 
##               37969               36901               36377               39250 
##      employstatus_9     employstatus_10 isoFriends_inPerson  isoOthPpl_inPerson 
##               31878               39080                 341                 552 
##   isoFriends_online    isoOthPpl_online              lone01              lone02 
##                 972                1179                  85                 118 
##              lone03               happy             lifeSat                 MLQ 
##                 140                 510                 109                 114 
##               bor01               bor02               bor03             consp01 
##                 153                 164                 163                1527 
##             consp02             consp03       rankOrdLife_1       rankOrdLife_2 
##                1556                1576                1706                1706 
##       rankOrdLife_3       rankOrdLife_4       rankOrdLife_5       rankOrdLife_6 
##                1706                1706                1706                1707 
##         c19perBeh01         c19perBeh02         c19perBeh03            c19RCA01 
##                 128                 126                 132                 132 
##            c19RCA02            c19RCA03       coronaClose_1       coronaClose_2 
##                 142                 145               39456               38741 
##       coronaClose_3       coronaClose_4       coronaClose_5       coronaClose_6 
##               38401               35098               35542               10718 
##              gender                 age                 edu       coded_country 
##                 228                 250                 268                   0 
##          c19ProSo01          c19ProSo02          c19ProSo03          c19ProSo04 
##                 125                 137                 145                 153

Distributions of Numerical Attributes.

Distributions of EmployStatus
# (1) takes all atributes related to employ status
# (2) then I use pivot_longer similar to melt 
# (3) create the new columns (variable) and (frequency)
data_long_employstatus<- pivot_longer(cvbase, cols = c("employstatus_1", "employstatus_2", "employstatus_3", "employstatus_4", "employstatus_5", "employstatus_6", "employstatus_7", "employstatus_8", "employstatus_9", "employstatus_10"),
                          names_to = "employstatus", values_to = "value")

# Plotting
ggplot(data_long_employstatus, aes(x = value)) +
  geom_histogram(bins = 10, fill = "blue", color = "black") +  # Adjust bin size as needed
  facet_wrap(~employstatus, scales = "free") +
  theme_minimal() +
  labs(title = "Distribution of Employ Status",
       x = "Response",
       y = "Frequency")
## Warning: Removed 354650 rows containing non-finite outside the scale range
## (`stat_bin()`).

Distributions of Conspiracy
data_long<- pivot_longer(cvbase, cols = c("consp01", "consp02", "consp03"),
                          names_to = "conspiracy", values_to = "value")

# Plotting
ggplot(data_long, aes(x = value)) +
  geom_histogram(bins = 10, fill = "blue", color = "black") +  # Adjust bin size as needed
  facet_wrap(~conspiracy, scales = "free") +
  theme_minimal() +
  labs(title = "Distribution of Conspiracy Beliefs",
       x = "Response",
       y = "Frequency")
## Warning: Removed 4659 rows containing non-finite outside the scale range
## (`stat_bin()`).

Distribution of Isolation and Loneliness
data_long_isolation_and_loneliness<- pivot_longer(cvbase, cols = c("isoFriends_inPerson", "isoOthPpl_inPerson", 
                                   "isoFriends_online", "isoOthPpl_online", "lone01", "lone02", "lone03"),
                          names_to = "isolation_and_loneliness", values_to = "value")

# Plotting
ggplot(data_long_isolation_and_loneliness, aes(x = value)) +
  geom_histogram(bins = 10, fill = "blue", color = "black") +  # Adjust bin size as needed
  facet_wrap(~isolation_and_loneliness, scales = "free") +
  theme_minimal() +
  labs(title = "Distribution of Isolation and Loneliness",
       x = "Response",
       y = "Frequency")
## Warning: Removed 3387 rows containing non-finite outside the scale range
## (`stat_bin()`).

Distribution of Happiness and Boredom
data_long_lifesat_and_boredom<- pivot_longer(cvbase, cols = c("happy", "lifeSat", "MLQ", "bor01", "bor02", "bor03"),
                          names_to = "life_sat_and_boredom", values_to = "value")

# Plotting
ggplot(data_long_lifesat_and_boredom, aes(x = value)) +
  geom_histogram(bins = 10, fill = "blue", color = "black") +  # Adjust bin size as needed
  facet_wrap(~life_sat_and_boredom, scales = "free") +
  theme_minimal() +
  labs(title = "Distribution of Life Satisfaction and Boredom",
       x = "Response",
       y = "Frequency")
## Warning: Removed 1213 rows containing non-finite outside the scale range
## (`stat_bin()`).

Distribution of Personal Behavior and Radical Action
data_long_personalbehavior_and_radicalaction <- pivot_longer(cvbase, cols = c("c19perBeh01", "c19perBeh02", "c19perBeh03", "c19RCA01", "c19RCA02", "c19RCA03"),
                          names_to = "personalbehavior_and_radicalaction", values_to = "value")

# Plotting
ggplot(data_long_personalbehavior_and_radicalaction, aes(x = value)) +
  geom_histogram(bins = 10, fill = "blue", color = "black") +  # Adjust bin size as needed
  facet_wrap(~personalbehavior_and_radicalaction, scales = "free") +
  theme_minimal() +
  labs(title = "Distribution of Personal Behavior and Radical Action",
       x = "Response",
       y = "Frequency")
## Warning: Removed 805 rows containing non-finite outside the scale range
## (`stat_bin()`).

Distribution of Proximity and PreSocial Behavior
data_long_proximity_and_presocial_behavior <- pivot_longer(cvbase, cols = c("coronaClose_1", "coronaClose_2", "coronaClose_3", "coronaClose_4","coronaClose_5", "coronaClose_6", "c19ProSo01", "c19ProSo02", "c19ProSo03", "c19ProSo04"),
                          names_to = "proximity_and_presocial_behavior", values_to = "value")

# Plotting
ggplot(data_long_proximity_and_presocial_behavior, aes(x = value)) +
  geom_histogram(bins = 10, fill = "blue", color = "black") +  # Adjust bin size as needed
  facet_wrap(~proximity_and_presocial_behavior, scales = "free") +
  theme_minimal() +
  labs(title = "Distribution of Proximity and PreSocial Behavior",
       x = "Response",
       y = "Frequency")
## Warning: Removed 198516 rows containing non-finite outside the scale range
## (`stat_bin()`).

Question 1B -> Pre-Processing / Data Manipulation

Descriptive Analysis (Happy and Social Isolation) => Graph 1
# select certain indicators for analysing happiness and social 
analysis1 <- cvbase

# calculate social isolation rate for each respondent
analysis1$averageIsolation <- round(rowMeans(analysis1[,c("isoFriends_inPerson", "isoOthPpl_inPerson", "isoFriends_online", "isoOthPpl_online")], na.rm = TRUE))

# create 3 categories for average social Isolation (Low, Medium, and High)
analysis1$iso_category <- cut(analysis1$averageIsolation, breaks=3, labels=c("Low", "Medium", "High"))

# show the data without any empty rows with respect to happy and isolation category
analysis1 <- analysis1 %>%
  filter(!is.na(analysis1$happy) & !is.na(analysis1$iso_category))

# convert data type of category to the factor as it has 3 main labels
analysis1$iso_category <- as.factor(analysis1$iso_category)

# plot the data
analysis1 %>% 
  # define the aesthetic with respect to 3 labels colored differently
  ggplot(aes(x=analysis1$happy, fill=analysis1$iso_category)) +
  geom_histogram(position="dodge", binwidth=1) +
  labs(title="Histogram of Happiness by Social Isolation Category", x="Happiness", y="Social Isolation") +
  # color the graph based on the palette
  scale_fill_brewer(palette="Pastel1") +
  theme_minimal()
## Warning: Use of `analysis1$happy` is discouraged.
## ℹ Use `happy` instead.
## Warning: Use of `analysis1$iso_category` is discouraged.
## ℹ Use `iso_category` instead.

# Calculate the number of missing values per column
missing_values <- colSums(is.na(cvbase))

# Calculate the threshold for removing columns (e.g., 50% of the rows)
threshold <- nrow(cvbase) * 0.50

# Identify columns that exceed the threshold
columns_to_remove <- names(missing_values[missing_values > threshold])

# Remove these columns from the dataframe
cvbase <- cvbase[, !(names(cvbase) %in% columns_to_remove)]
Data Cleaning: Using Imputation Method
for(column_name in names(cvbase))
{
  # select if the column data type is numeric
  if (is.numeric(cvbase[[column_name]]))
  {
      cvbase[[column_name]][is.na(cvbase[[column_name]])] <- 0
      cvbase[[column_name]] <- as.numeric(cvbase[[column_name]])
    }
  else
  {
    cvbase[[column_name]][is.na(cvbase[[column_name]])] <- "None"
    cvbase[[column_name]] <- as.factor(cvbase[[column_name]])
  }
}
Convert Data Type
# change the label of gender to M, F, Others
cvbase$gender <- factor(cvbase$gender, levels = c(0, 1, 2, 3), labels = c("None", "Male", "Female", "Other"))
cvbase$edu <- factor(cvbase$edu, levels = c(0,1,2,3,4,5,6,7), labels = c("None","Primary education", "General secondary
education","Vocational education","Higher
education", "Bachelors degree", "Masters degree", "PhD
degree"))

Question 2A

Extract both focus country and not focus country

cvbase_focuscountry <- "South Africa"
cvbase_focuscountry_table <- cvbase[which(cvbase$coded_country == cvbase_focuscountry),]
cvbase_nonfocuscountry_table <- cvbase[which(cvbase$coded_country != cvbase_focuscountry),]
Comparison Between Focus and Non With Respect to Conspiracy
# converts the data from wide to long for focus country
data_long_focuscountry <- pivot_longer(cvbase_focuscountry_table, cols = c("consp01", "consp02", "consp03"), 
                          names_to = "conspiracy", values_to = "value") %>%
  mutate(Country = "Focus")

# converts the data from wide to long for non focus country
data_long_nonfocuscountry <- pivot_longer(cvbase_nonfocuscountry_table, cols = c("consp01", "consp02", "consp03"), 
                          names_to = "conspiracy", values_to = "value") %>%
  mutate(Country = "Non-Focus")

# Combine both datasets
combined_data <- bind_rows(data_long_focuscountry, data_long_nonfocuscountry)

# Plotting histogram with ggplot2
ggplot(combined_data, aes(x = value)) +
  geom_histogram(bins = 10, fill = "blue", color = "black") +  
  # Adjust bin size as needed and combine all graphs with respect to the aspects required
  facet_grid(Country ~ conspiracy, scales = "free") +
  # create minimalistic background
  theme_minimal() +
  # creates the label for x and y axis, and the title
  labs(title = "Distribution of Conspiracy Beliefs by Country",
       x = "Response",
       y = "Frequency")

# shows the comparison through the hypothesis testing
t.test(cvbase_focuscountry_table$consp01, cvbase_nonfocuscountry_table$consp01, alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  cvbase_focuscountry_table$consp01 and cvbase_nonfocuscountry_table$consp01
## t = 6.5944, df = 954.92, p-value = 3.528e-11
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  0.4293746       Inf
## sample estimates:
## mean of x mean of y 
##  7.130820  6.558571
t.test(cvbase_focuscountry_table$consp02, cvbase_nonfocuscountry_table$consp02, alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  cvbase_focuscountry_table$consp02 and cvbase_nonfocuscountry_table$consp02
## t = 7.9016, df = 958.4, p-value = 3.766e-15
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  0.5190294       Inf
## sample estimates:
## mean of x mean of y 
##  7.511086  6.855440
t.test(cvbase_focuscountry_table$consp03, cvbase_nonfocuscountry_table$consp03, alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  cvbase_focuscountry_table$consp03 and cvbase_nonfocuscountry_table$consp03
## t = 3.0574, df = 951.06, p-value = 0.001148
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  0.1252683       Inf
## sample estimates:
## mean of x mean of y 
##  5.625277  5.353829
Comparison Between Focus and Non Focus With Respect to Pre-Social Behaviors
data_long_focuscountry <- pivot_longer(cvbase_focuscountry_table, cols = c("c19ProSo01", "c19ProSo02", "c19ProSo03", "c19ProSo04"), 
                          names_to = "presocialBehavior", values_to = "value") %>%
  mutate(Country = "Focus")

data_long_nonfocuscountry <- pivot_longer(cvbase_nonfocuscountry_table, cols = c("c19ProSo01", "c19ProSo02", "c19ProSo03", "c19ProSo04"), 
                          names_to = "presocialBehavior", values_to = "value") %>%
  mutate(Country = "Non-Focus")

# Combine both datasets
combined_data <- bind_rows(data_long_focuscountry, data_long_nonfocuscountry)

# Plotting with ggplot2
ggplot(combined_data, aes(x = value)) +
  geom_histogram(bins = 10, fill = "red", color = "black") +  # Adjust bin size as needed
  facet_grid(Country ~ presocialBehavior, scales = "free") +
  theme_minimal() +
  labs(title = "Distribution of Pre-Social Behavior by Country Category",
       x = "Response",
       y = "Frequency")

t.test(cvbase_focuscountry_table$c19ProSo01, cvbase_nonfocuscountry_table$c19ProSo01, alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  cvbase_focuscountry_table$c19ProSo01 and cvbase_nonfocuscountry_table$c19ProSo01
## t = -2.705, df = 938.71, p-value = 0.9965
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  -0.2267019        Inf
## sample estimates:
## mean of x mean of y 
## 0.8370288 0.9779528
t.test(cvbase_focuscountry_table$c19ProSo02, cvbase_nonfocuscountry_table$c19ProSo02, alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  cvbase_focuscountry_table$c19ProSo02 and cvbase_nonfocuscountry_table$c19ProSo02
## t = -0.60632, df = 949, p-value = 0.7278
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  -0.1170447        Inf
## sample estimates:
## mean of x mean of y 
## 0.6485588 0.6800604
t.test(cvbase_focuscountry_table$c19ProSo03, cvbase_nonfocuscountry_table$c19ProSo03, alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  cvbase_focuscountry_table$c19ProSo03 and cvbase_nonfocuscountry_table$c19ProSo03
## t = -3.4459, df = 942.08, p-value = 0.9997
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  -0.2888599        Inf
## sample estimates:
## mean of x mean of y 
## 0.3580931 0.5535577
t.test(cvbase_focuscountry_table$c19ProSo04, cvbase_nonfocuscountry_table$c19ProSo04, alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  cvbase_focuscountry_table$c19ProSo04 and cvbase_nonfocuscountry_table$c19ProSo04
## t = 6.7341, df = 954.67, p-value = 1.423e-11
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  0.2387933       Inf
## sample estimates:
## mean of x mean of y 
##  1.595344  1.279273

Question 2B

Extract the table of focus country by excluding the country name

# Extracts the data by removing coded country
# this is because the "coded country" column has 1 unique value
cvbase_focuscountry_table_withoutcoded <- cvbase_focuscountry_table %>% 
  select(-coded_country)
Identify Best Predictors for C19ProSo01
# (1) use linear regression to find independent variable used for predicting the dependable variable
fit_focuscountry_1 <- lm(cvbase_focuscountry_table_withoutcoded$c19ProSo01 ~., data = cvbase_focuscountry_table_withoutcoded)
# shows the summary of linear model
summary(fit_focuscountry_1)
## 
## Call:
## lm(formula = cvbase_focuscountry_table_withoutcoded$c19ProSo01 ~ 
##     ., data = cvbase_focuscountry_table_withoutcoded)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.0619 -0.6701  0.1520  0.8516  3.9849 
## 
## Coefficients: (10 not defined because of singularities)
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      1.046e+00  1.221e+00   0.857  0.39174    
## isoFriends_inPerson              1.012e-02  2.144e-02   0.472  0.63702    
## isoOthPpl_inPerson               2.212e-02  2.366e-02   0.935  0.35027    
## isoFriends_online                2.830e-02  2.134e-02   1.326  0.18507    
## isoOthPpl_online                -2.616e-02  2.060e-02  -1.269  0.20463    
## lone01                           1.077e-02  5.651e-02   0.190  0.84897    
## lone02                          -8.790e-03  5.103e-02  -0.172  0.86329    
## lone03                           2.588e-02  5.322e-02   0.486  0.62682    
## happy                            8.882e-03  2.940e-02   0.302  0.76263    
## lifeSat                         -1.493e-02  5.202e-02  -0.287  0.77424    
## MLQ                              3.606e-02  4.223e-02   0.854  0.39342    
## bor01                            5.938e-02  3.362e-02   1.766  0.07776 .  
## bor02                           -3.539e-02  3.393e-02  -1.043  0.29732    
## bor03                            7.281e-05  2.856e-02   0.003  0.99797    
## consp01                          3.370e-02  2.498e-02   1.349  0.17774    
## consp02                         -3.767e-02  2.633e-02  -1.430  0.15299    
## consp03                          2.550e-02  1.884e-02   1.354  0.17607    
## rankOrdLife_1B                   1.875e-02  3.500e-01   0.054  0.95729    
## rankOrdLife_1C                   2.105e-01  3.315e-01   0.635  0.52573    
## rankOrdLife_1D                  -1.518e-01  3.272e-01  -0.464  0.64289    
## rankOrdLife_1E                   3.979e-01  3.223e-01   1.234  0.21742    
## rankOrdLife_1F                   2.335e-01  2.969e-01   0.786  0.43182    
## rankOrdLife_1None                3.220e-03  7.300e-01   0.004  0.99648    
## rankOrdLife_2B                  -8.142e-02  2.307e-01  -0.353  0.72419    
## rankOrdLife_2C                  -5.311e-02  2.207e-01  -0.241  0.80989    
## rankOrdLife_2D                  -3.260e-01  2.275e-01  -1.433  0.15221    
## rankOrdLife_2E                   2.598e-01  2.449e-01   1.061  0.28908    
## rankOrdLife_2F                  -6.555e-02  3.219e-01  -0.204  0.83872    
## rankOrdLife_2None                       NA         NA      NA       NA    
## rankOrdLife_3B                  -1.402e-01  3.334e-01  -0.420  0.67429    
## rankOrdLife_3C                  -5.674e-02  3.258e-01  -0.174  0.86180    
## rankOrdLife_3D                  -1.935e-01  3.291e-01  -0.588  0.55675    
## rankOrdLife_3E                   8.421e-02  3.201e-01   0.263  0.79256    
## rankOrdLife_3F                   5.309e-02  3.245e-01   0.164  0.87010    
## rankOrdLife_3None                       NA         NA      NA       NA    
## rankOrdLife_4B                  -3.089e-02  2.205e-01  -0.140  0.88865    
## rankOrdLife_4C                  -2.903e-02  2.149e-01  -0.135  0.89255    
## rankOrdLife_4D                  -2.366e-01  2.457e-01  -0.963  0.33590    
## rankOrdLife_4E                   3.667e-01  2.715e-01   1.351  0.17720    
## rankOrdLife_4F                   3.147e-01  3.122e-01   1.008  0.31376    
## rankOrdLife_4None                       NA         NA      NA       NA    
## rankOrdLife_5B                  -1.716e-01  1.653e-01  -1.038  0.29943    
## rankOrdLife_5C                   1.533e-02  2.050e-01   0.075  0.94039    
## rankOrdLife_5D                  -4.537e-01  2.664e-01  -1.703  0.08897 .  
## rankOrdLife_5E                   3.388e-01  2.831e-01   1.197  0.23172    
## rankOrdLife_5F                  -3.507e-01  4.127e-01  -0.850  0.39561    
## rankOrdLife_5None                       NA         NA      NA       NA    
## rankOrdLife_6B                          NA         NA      NA       NA    
## rankOrdLife_6C                          NA         NA      NA       NA    
## rankOrdLife_6D                          NA         NA      NA       NA    
## rankOrdLife_6E                          NA         NA      NA       NA    
## rankOrdLife_6F                          NA         NA      NA       NA    
## rankOrdLife_6None                       NA         NA      NA       NA    
## c19perBeh01                      9.948e-02  5.715e-02   1.740  0.08214 .  
## c19perBeh02                     -3.282e-02  7.621e-02  -0.431  0.66684    
## c19perBeh03                     -3.776e-02  4.328e-02  -0.873  0.38318    
## c19RCA01                         4.825e-02  2.618e-02   1.843  0.06568 .  
## c19RCA02                        -1.480e-02  5.078e-02  -0.291  0.77076    
## c19RCA03                         3.247e-02  4.077e-02   0.797  0.42597    
## coronaClose_6                    2.309e-02  1.397e-01   0.165  0.86876    
## genderMale                      -1.556e+00  1.123e+00  -1.386  0.16626    
## genderFemale                    -1.275e+00  1.123e+00  -1.135  0.25660    
## genderOther                     -6.842e-01  1.478e+00  -0.463  0.64348    
## age                              4.971e-02  3.262e-02   1.524  0.12797    
## eduPrimary education             3.684e-01  6.395e-01   0.576  0.56465    
## eduGeneral secondary\neducation  3.810e-02  5.736e-01   0.066  0.94706    
## eduVocational education          1.059e-01  5.895e-01   0.180  0.85746    
## eduHigher\neducation             7.949e-02  5.704e-01   0.139  0.88919    
## eduBachelors degree              2.561e-01  5.734e-01   0.447  0.65521    
## eduMasters degree                2.861e-01  5.930e-01   0.482  0.62964    
## eduPhD\ndegree                   1.219e-01  6.789e-01   0.179  0.85759    
## c19ProSo02                       2.363e-01  3.709e-02   6.373 3.06e-10 ***
## c19ProSo03                       2.456e-01  3.481e-02   7.056 3.58e-12 ***
## c19ProSo04                       1.009e-01  3.780e-02   2.668  0.00777 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.311 on 838 degrees of freedom
## Multiple R-squared:  0.3332, Adjusted R-squared:  0.2831 
## F-statistic: 6.648 on 63 and 838 DF,  p-value: < 2.2e-16
Identify Best Predictors for C19ProSo02
fit_focuscountry_2 <- lm(cvbase_focuscountry_table_withoutcoded$c19ProSo02 ~., data = cvbase_focuscountry_table_withoutcoded)
summary(fit_focuscountry_2)
## 
## Call:
## lm(formula = cvbase_focuscountry_table_withoutcoded$c19ProSo02 ~ 
##     ., data = cvbase_focuscountry_table_withoutcoded)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.2234 -0.6873  0.0769  0.7470  3.2689 
## 
## Coefficients: (10 not defined because of singularities)
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     -1.6074058  1.1098606  -1.448   0.1479    
## isoFriends_inPerson             -0.0297522  0.0194789  -1.527   0.1270    
## isoOthPpl_inPerson              -0.0165531  0.0215303  -0.769   0.4422    
## isoFriends_online               -0.0086914  0.0194302  -0.447   0.6548    
## isoOthPpl_online                 0.0358779  0.0187208   1.916   0.0556 .  
## lone01                           0.0365553  0.0513935   0.711   0.4771    
## lone02                          -0.0088567  0.0464205  -0.191   0.8487    
## lone03                           0.0572754  0.0483777   1.184   0.2368    
## happy                            0.0270126  0.0267272   1.011   0.3125    
## lifeSat                         -0.0072666  0.0473211  -0.154   0.8780    
## MLQ                              0.0902635  0.0383089   2.356   0.0187 *  
## bor01                           -0.0184541  0.0306376  -0.602   0.5471    
## bor02                            0.0413469  0.0308556   1.340   0.1806    
## bor03                           -0.0171348  0.0259739  -0.660   0.5096    
## consp01                         -0.0169678  0.0227431  -0.746   0.4558    
## consp02                          0.0288051  0.0239634   1.202   0.2297    
## consp03                         -0.0147567  0.0171454  -0.861   0.3897    
## rankOrdLife_1B                  -0.1214995  0.3183462  -0.382   0.7028    
## rankOrdLife_1C                  -0.0005939  0.3016558  -0.002   0.9984    
## rankOrdLife_1D                   0.0576784  0.2976758   0.194   0.8464    
## rankOrdLife_1E                  -0.0079603  0.2934863  -0.027   0.9784    
## rankOrdLife_1F                   0.0293344  0.2701928   0.109   0.9136    
## rankOrdLife_1None               -0.1966368  0.6640694  -0.296   0.7672    
## rankOrdLife_2B                  -0.1646730  0.2097591  -0.785   0.4326    
## rankOrdLife_2C                  -0.0611873  0.2007546  -0.305   0.7606    
## rankOrdLife_2D                  -0.3186515  0.2069121  -1.540   0.1239    
## rankOrdLife_2E                  -0.2911793  0.2227162  -1.307   0.1914    
## rankOrdLife_2F                  -0.3239504  0.2926531  -1.107   0.2686    
## rankOrdLife_2None                       NA         NA      NA       NA    
## rankOrdLife_3B                  -0.3101391  0.3031194  -1.023   0.3065    
## rankOrdLife_3C                  -0.1554012  0.2963615  -0.524   0.6002    
## rankOrdLife_3D                  -0.3280219  0.2991970  -1.096   0.2732    
## rankOrdLife_3E                  -0.1973834  0.2911345  -0.678   0.4980    
## rankOrdLife_3F                  -0.0552062  0.2952305  -0.187   0.8517    
## rankOrdLife_3None                       NA         NA      NA       NA    
## rankOrdLife_4B                  -0.2059960  0.2004722  -1.028   0.3045    
## rankOrdLife_4C                  -0.2199088  0.1953295  -1.126   0.2606    
## rankOrdLife_4D                  -0.0586533  0.2236268  -0.262   0.7932    
## rankOrdLife_4E                  -0.1961302  0.2471923  -0.793   0.4278    
## rankOrdLife_4F                  -0.2112486  0.2840747  -0.744   0.4573    
## rankOrdLife_4None                       NA         NA      NA       NA    
## rankOrdLife_5B                  -0.0323847  0.1504744  -0.215   0.8297    
## rankOrdLife_5C                  -0.3095272  0.1861693  -1.663   0.0968 .  
## rankOrdLife_5D                  -0.0287979  0.2427653  -0.119   0.9056    
## rankOrdLife_5E                  -0.0866524  0.2577048  -0.336   0.7368    
## rankOrdLife_5F                  -0.3403268  0.3753775  -0.907   0.3649    
## rankOrdLife_5None                       NA         NA      NA       NA    
## rankOrdLife_6B                          NA         NA      NA       NA    
## rankOrdLife_6C                          NA         NA      NA       NA    
## rankOrdLife_6D                          NA         NA      NA       NA    
## rankOrdLife_6E                          NA         NA      NA       NA    
## rankOrdLife_6F                          NA         NA      NA       NA    
## rankOrdLife_6None                       NA         NA      NA       NA    
## c19perBeh01                      0.0697138  0.0520307   1.340   0.1807    
## c19perBeh02                      0.0785671  0.0692792   1.134   0.2571    
## c19perBeh03                      0.0126616  0.0393822   0.322   0.7479    
## c19RCA01                         0.0442361  0.0238126   1.858   0.0636 .  
## c19RCA02                         0.0017669  0.0461954   0.038   0.9695    
## c19RCA03                        -0.0160636  0.0370984  -0.433   0.6651    
## coronaClose_6                   -0.2642784  0.1267523  -2.085   0.0374 *  
## genderMale                       1.0372399  1.0218921   1.015   0.3104    
## genderFemale                     0.9085923  1.0221643   0.889   0.3743    
## genderOther                      0.8289580  1.3441395   0.617   0.5376    
## age                             -0.0281117  0.0297031  -0.946   0.3442    
## eduPrimary education             0.8340799  0.5811009   1.435   0.1516    
## eduGeneral secondary\neducation  0.9840391  0.5207104   1.890   0.0591 .  
## eduVocational education          0.9196756  0.5353661   1.718   0.0862 .  
## eduHigher\neducation             1.0142032  0.5176649   1.959   0.0504 .  
## eduBachelors degree              1.1835763  0.5200724   2.276   0.0231 *  
## eduMasters degree                1.0187981  0.5383753   1.892   0.0588 .  
## eduPhD\ndegree                   0.9595523  0.6167222   1.556   0.1201    
## c19ProSo01                       0.1955758  0.0306894   6.373 3.06e-10 ***
## c19ProSo03                       0.3854068  0.0297507  12.955  < 2e-16 ***
## c19ProSo04                       0.0162152  0.0345316   0.470   0.6388    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.193 on 838 degrees of freedom
## Multiple R-squared:  0.4422, Adjusted R-squared:  0.4003 
## F-statistic: 10.54 on 63 and 838 DF,  p-value: < 2.2e-16
Identify Best Predictors for C19ProSo03
fit_focuscountry_3 <- lm(cvbase_focuscountry_table_withoutcoded$c19ProSo03 ~., data = cvbase_focuscountry_table_withoutcoded)
summary(fit_focuscountry_3)
## 
## Call:
## lm(formula = cvbase_focuscountry_table_withoutcoded$c19ProSo03 ~ 
##     ., data = cvbase_focuscountry_table_withoutcoded)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.9559 -0.6438  0.1607  0.7436  3.7476 
## 
## Coefficients: (10 not defined because of singularities)
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     -0.611114   1.177562  -0.519  0.60392    
## isoFriends_inPerson              0.003147   0.020673   0.152  0.87905    
## isoOthPpl_inPerson               0.001368   0.022827   0.060  0.95223    
## isoFriends_online                0.013012   0.020591   0.632  0.52761    
## isoOthPpl_online                 0.003240   0.019884   0.163  0.87059    
## lone01                           0.082383   0.054411   1.514  0.13038    
## lone02                          -0.068813   0.049142  -1.400  0.16180    
## lone03                           0.029435   0.051306   0.574  0.56631    
## happy                           -0.017989   0.028337  -0.635  0.52572    
## lifeSat                          0.052289   0.050121   1.043  0.29713    
## MLQ                              0.047632   0.040703   1.170  0.24223    
## bor01                            0.048571   0.032435   1.497  0.13464    
## bor02                           -0.030288   0.032720  -0.926  0.35489    
## bor03                            0.059713   0.027458   2.175  0.02993 *  
## consp01                         -0.025600   0.024096  -1.062  0.28836    
## consp02                         -0.025919   0.025404  -1.020  0.30789    
## consp03                          0.017396   0.018170   0.957  0.33862    
## rankOrdLife_1B                   0.439945   0.337084   1.305  0.19220    
## rankOrdLife_1C                   0.270514   0.319572   0.846  0.39752    
## rankOrdLife_1D                   0.340524   0.315278   1.080  0.28042    
## rankOrdLife_1E                   0.445036   0.310670   1.433  0.15237    
## rankOrdLife_1F                   0.363821   0.286088   1.272  0.20383    
## rankOrdLife_1None                0.746224   0.703375   1.061  0.28903    
## rankOrdLife_2B                   0.120052   0.222355   0.540  0.58940    
## rankOrdLife_2C                   0.133088   0.212731   0.626  0.53174    
## rankOrdLife_2D                   0.289357   0.219377   1.319  0.18753    
## rankOrdLife_2E                   0.294757   0.236066   1.249  0.21215    
## rankOrdLife_2F                   0.376733   0.310121   1.215  0.22479    
## rankOrdLife_2None                      NA         NA      NA       NA    
## rankOrdLife_3B                   0.017475   0.321460   0.054  0.95666    
## rankOrdLife_3C                   0.150339   0.314106   0.479  0.63233    
## rankOrdLife_3D                   0.025131   0.317329   0.079  0.93690    
## rankOrdLife_3E                  -0.063918   0.308634  -0.207  0.83598    
## rankOrdLife_3F                  -0.003896   0.312905  -0.012  0.99007    
## rankOrdLife_3None                      NA         NA      NA       NA    
## rankOrdLife_4B                   0.300637   0.212349   1.416  0.15722    
## rankOrdLife_4C                   0.337741   0.206847   1.633  0.10289    
## rankOrdLife_4D                   0.376743   0.236662   1.592  0.11178    
## rankOrdLife_4E                   0.057889   0.262076   0.221  0.82523    
## rankOrdLife_4F                   0.607862   0.300441   2.023  0.04337 *  
## rankOrdLife_4None                      NA         NA      NA       NA    
## rankOrdLife_5B                   0.218173   0.159306   1.370  0.17120    
## rankOrdLife_5C                   0.033868   0.197632   0.171  0.86398    
## rankOrdLife_5D                   0.170627   0.257228   0.663  0.50730    
## rankOrdLife_5E                   0.320867   0.272921   1.176  0.24006    
## rankOrdLife_5F                   0.575698   0.397540   1.448  0.14795    
## rankOrdLife_5None                      NA         NA      NA       NA    
## rankOrdLife_6B                         NA         NA      NA       NA    
## rankOrdLife_6C                         NA         NA      NA       NA    
## rankOrdLife_6D                         NA         NA      NA       NA    
## rankOrdLife_6E                         NA         NA      NA       NA    
## rankOrdLife_6F                         NA         NA      NA       NA    
## rankOrdLife_6None                      NA         NA      NA       NA    
## c19perBeh01                     -0.063646   0.055160  -1.154  0.24889    
## c19perBeh02                      0.042062   0.073467   0.573  0.56712    
## c19perBeh03                      0.034941   0.041724   0.837  0.40259    
## c19RCA01                        -0.024753   0.025275  -0.979  0.32769    
## c19RCA02                        -0.004642   0.048960  -0.095  0.92448    
## c19RCA03                        -0.013569   0.039320  -0.345  0.73012    
## coronaClose_6                    0.117716   0.134624   0.874  0.38215    
## genderMale                       0.104045   1.083706   0.096  0.92354    
## genderFemale                     0.253120   1.083811   0.234  0.81539    
## genderOther                      0.704757   1.424694   0.495  0.62096    
## age                             -0.083504   0.031365  -2.662  0.00791 ** 
## eduPrimary education            -0.559758   0.616330  -0.908  0.36403    
## eduGeneral secondary\neducation -0.983222   0.552003  -1.781  0.07524 .  
## eduVocational education         -0.598513   0.568027  -1.054  0.29234    
## eduHigher\neducation            -0.819672   0.549170  -1.493  0.13593    
## eduBachelors degree             -0.937410   0.551948  -1.698  0.08981 .  
## eduMasters degree               -0.944950   0.570880  -1.655  0.09825 .  
## eduPhD\ndegree                  -0.672021   0.654161  -1.027  0.30458    
## c19ProSo01                       0.228325   0.032357   7.056 3.58e-12 ***
## c19ProSo02                       0.432916   0.033418  12.955  < 2e-16 ***
## c19ProSo04                       0.268388   0.035409   7.580 9.19e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.264 on 838 degrees of freedom
## Multiple R-squared:  0.4763, Adjusted R-squared:  0.4369 
## F-statistic:  12.1 on 63 and 838 DF,  p-value: < 2.2e-16
Identify Best Predictors for C19ProSo04
fit_focuscountry_4 <- lm(cvbase_focuscountry_table_withoutcoded$c19ProSo04 ~., data = cvbase_focuscountry_table_withoutcoded)
summary(fit_focuscountry_4)
## 
## Call:
## lm(formula = cvbase_focuscountry_table_withoutcoded$c19ProSo04 ~ 
##     ., data = cvbase_focuscountry_table_withoutcoded)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.4525 -0.5696  0.1106  0.7817  2.7698 
## 
## Coefficients: (10 not defined because of singularities)
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     -0.1025644  1.1115107  -0.092 0.926502    
## isoFriends_inPerson              0.0194318  0.0194991   0.997 0.319273    
## isoOthPpl_inPerson               0.0275265  0.0215221   1.279 0.201255    
## isoFriends_online                0.0236066  0.0194201   1.216 0.224489    
## isoOthPpl_online                 0.0002417  0.0187663   0.013 0.989728    
## lone01                           0.0418845  0.0514010   0.815 0.415385    
## lone02                           0.0263978  0.0464237   0.569 0.569761    
## lone03                          -0.0360179  0.0484138  -0.744 0.457110    
## happy                            0.0108907  0.0267473   0.407 0.683986    
## lifeSat                         -0.0132121  0.0473309  -0.279 0.780204    
## MLQ                             -0.0247750  0.0384354  -0.645 0.519370    
## bor01                            0.0635265  0.0305730   2.078 0.038026 *  
## bor02                           -0.0430032  0.0308604  -1.393 0.163845    
## bor03                            0.0494572  0.0259307   1.907 0.056825 .  
## consp01                         -0.0036032  0.0227558  -0.158 0.874226    
## consp02                          0.0571461  0.0239085   2.390 0.017059 *  
## consp03                         -0.0232523  0.0171383  -1.357 0.175228    
## rankOrdLife_1B                  -0.6446533  0.3176709  -2.029 0.042742 *  
## rankOrdLife_1C                  -0.2361967  0.3016181  -0.783 0.433790    
## rankOrdLife_1D                  -0.2791363  0.2975979  -0.938 0.348533    
## rankOrdLife_1E                  -0.0163697  0.2935565  -0.056 0.955544    
## rankOrdLife_1F                  -0.1086930  0.2702336  -0.402 0.687626    
## rankOrdLife_1None               -1.0566618  0.6632604  -1.593 0.111507    
## rankOrdLife_2B                  -0.3281692  0.2095803  -1.566 0.117764    
## rankOrdLife_2C                  -0.1423256  0.2007539  -0.709 0.478549    
## rankOrdLife_2D                  -0.2892804  0.2070135  -1.397 0.162663    
## rankOrdLife_2E                  -0.3234561  0.2227168  -1.452 0.146787    
## rankOrdLife_2F                  -0.1999578  0.2928560  -0.683 0.494931    
## rankOrdLife_2None                       NA         NA      NA       NA    
## rankOrdLife_3B                   0.0741011  0.3033709   0.244 0.807090    
## rankOrdLife_3C                   0.0544788  0.2964755   0.184 0.854250    
## rankOrdLife_3D                  -0.0495306  0.2994787  -0.165 0.868677    
## rankOrdLife_3E                   0.0945313  0.2912661   0.325 0.745600    
## rankOrdLife_3F                   0.0066581  0.2953077   0.023 0.982018    
## rankOrdLife_3None                       NA         NA      NA       NA    
## rankOrdLife_4B                  -0.2619890  0.2004425  -1.307 0.191553    
## rankOrdLife_4C                  -0.0392434  0.1955196  -0.201 0.840972    
## rankOrdLife_4D                  -0.3351080  0.2233901  -1.500 0.133964    
## rankOrdLife_4E                  -0.0502208  0.2473386  -0.203 0.839149    
## rankOrdLife_4F                  -0.5020063  0.2837073  -1.769 0.077182 .  
## rankOrdLife_4None                       NA         NA      NA       NA    
## rankOrdLife_5B                  -0.2493636  0.1502681  -1.659 0.097398 .  
## rankOrdLife_5C                  -0.2728097  0.1862828  -1.464 0.143435    
## rankOrdLife_5D                  -0.5298619  0.2421349  -2.188 0.028924 *  
## rankOrdLife_5E                  -0.3219576  0.2575442  -1.250 0.211610    
## rankOrdLife_5F                  -0.5378359  0.3751922  -1.433 0.152090    
## rankOrdLife_5None                       NA         NA      NA       NA    
## rankOrdLife_6B                          NA         NA      NA       NA    
## rankOrdLife_6C                          NA         NA      NA       NA    
## rankOrdLife_6D                          NA         NA      NA       NA    
## rankOrdLife_6E                          NA         NA      NA       NA    
## rankOrdLife_6F                          NA         NA      NA       NA    
## rankOrdLife_6None                       NA         NA      NA       NA    
## c19perBeh01                      0.0060951  0.0520985   0.117 0.906894    
## c19perBeh02                      0.2469739  0.0688222   3.589 0.000352 ***
## c19perBeh03                      0.0084765  0.0393930   0.215 0.829680    
## c19RCA01                         0.0160730  0.0238609   0.674 0.500743    
## c19RCA02                         0.0588852  0.0461617   1.276 0.202440    
## c19RCA03                         0.0631447  0.0370473   1.704 0.088671 .  
## coronaClose_6                   -0.0742414  0.1270853  -0.584 0.559253    
## genderMale                       0.2190709  1.0227382   0.214 0.830443    
## genderFemale                     0.0865160  1.0228879   0.085 0.932615    
## genderOther                     -0.1994145  1.3447506  -0.148 0.882149    
## age                             -0.0005174  0.0297262  -0.017 0.986117    
## eduPrimary education             0.0608788  0.5819510   0.105 0.916709    
## eduGeneral secondary\neducation  0.6840066  0.5214093   1.312 0.189933    
## eduVocational education          0.6932981  0.5359021   1.294 0.196125    
## eduHigher\neducation             0.5694880  0.5186010   1.098 0.272466    
## eduBachelors degree              0.5339813  0.5214765   1.024 0.306140    
## eduMasters degree                0.7583947  0.5390180   1.407 0.159800    
## eduPhD\ndegree                   1.1304745  0.6165255   1.834 0.067065 .  
## c19ProSo01                       0.0835145  0.0312992   2.668 0.007772 ** 
## c19ProSo02                       0.0162230  0.0345482   0.470 0.638779    
## c19ProSo03                       0.2390491  0.0315385   7.580 9.19e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.193 on 838 degrees of freedom
## Multiple R-squared:  0.3141, Adjusted R-squared:  0.2626 
## F-statistic: 6.092 on 63 and 838 DF,  p-value: < 2.2e-16

Question 2C

cvbase_nonfocuscountry_table_withoutcoded <- cvbase_nonfocuscountry_table %>% 
  select(-coded_country)
Identify Best Predictors with C19ProSo01
fit_nonfocuscountry_1 <- lm(cvbase_nonfocuscountry_table_withoutcoded$c19ProSo01 ~., data = cvbase_nonfocuscountry_table_withoutcoded)
summary(fit_nonfocuscountry_1)
## 
## Call:
## lm(formula = cvbase_nonfocuscountry_table_withoutcoded$c19ProSo01 ~ 
##     ., data = cvbase_nonfocuscountry_table_withoutcoded)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.6730 -0.5962  0.1314  0.7140  4.7413 
## 
## Coefficients: (4 not defined because of singularities)
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      0.645124   0.289447   2.229 0.025832 *  
## isoFriends_inPerson              0.006985   0.002757   2.534 0.011291 *  
## isoOthPpl_inPerson               0.017111   0.003078   5.560 2.72e-08 ***
## isoFriends_online                0.007487   0.002753   2.719 0.006547 ** 
## isoOthPpl_online                 0.006195   0.002572   2.409 0.016013 *  
## lone01                           0.048534   0.007528   6.447 1.16e-10 ***
## lone02                          -0.022285   0.006651  -3.351 0.000807 ***
## lone03                          -0.008733   0.007197  -1.213 0.225010    
## happy                            0.002406   0.003835   0.627 0.530389    
## lifeSat                         -0.002315   0.007024  -0.330 0.741685    
## MLQ                              0.042600   0.004912   8.672  < 2e-16 ***
## bor01                            0.011378   0.004220   2.696 0.007010 ** 
## bor02                           -0.006129   0.004218  -1.453 0.146217    
## bor03                            0.020943   0.003978   5.265 1.41e-07 ***
## consp01                          0.014086   0.003137   4.490 7.14e-06 ***
## consp02                         -0.003585   0.003236  -1.108 0.268042    
## consp03                          0.006293   0.002488   2.529 0.011446 *  
## rankOrdLife_1B                  -0.021543   0.089437  -0.241 0.809651    
## rankOrdLife_1C                  -0.064321   0.098258  -0.655 0.512721    
## rankOrdLife_1D                  -0.096948   0.103414  -0.937 0.348517    
## rankOrdLife_1E                  -0.098553   0.095266  -1.035 0.300909    
## rankOrdLife_1F                  -0.010314   0.081966  -0.126 0.899864    
## rankOrdLife_1None               -1.265399   1.204420  -1.051 0.293435    
## rankOrdLife_2B                   0.019021   0.086309   0.220 0.825577    
## rankOrdLife_2C                  -0.062261   0.096221  -0.647 0.517595    
## rankOrdLife_2D                  -0.104185   0.101580  -1.026 0.305065    
## rankOrdLife_2E                  -0.101941   0.093517  -1.090 0.275682    
## rankOrdLife_2F                  -0.035596   0.083120  -0.428 0.668473    
## rankOrdLife_2None                      NA         NA      NA       NA    
## rankOrdLife_3B                   0.057148   0.093327   0.612 0.540320    
## rankOrdLife_3C                  -0.001464   0.101159  -0.014 0.988454    
## rankOrdLife_3D                  -0.064292   0.106025  -0.606 0.544267    
## rankOrdLife_3E                  -0.042172   0.097869  -0.431 0.666542    
## rankOrdLife_3F                   0.008884   0.085935   0.103 0.917660    
## rankOrdLife_3None                      NA         NA      NA       NA    
## rankOrdLife_4B                   0.007552   0.084080   0.090 0.928436    
## rankOrdLife_4C                  -0.105659   0.094981  -1.112 0.265962    
## rankOrdLife_4D                  -0.137511   0.101157  -1.359 0.174033    
## rankOrdLife_4E                  -0.165817   0.093585  -1.772 0.076429 .  
## rankOrdLife_4F                  -0.159787   0.082596  -1.935 0.053053 .  
## rankOrdLife_4None                      NA         NA      NA       NA    
## rankOrdLife_5B                   0.024591   0.083857   0.293 0.769333    
## rankOrdLife_5C                  -0.067838   0.095228  -0.712 0.476232    
## rankOrdLife_5D                  -0.118481   0.101908  -1.163 0.244987    
## rankOrdLife_5E                  -0.119983   0.093802  -1.279 0.200866    
## rankOrdLife_5F                  -0.016093   0.081513  -0.197 0.843490    
## rankOrdLife_5None                      NA         NA      NA       NA    
## rankOrdLife_6B                  -0.064110   0.084339  -0.760 0.447171    
## rankOrdLife_6C                  -0.195694   0.095034  -2.059 0.039482 *  
## rankOrdLife_6D                  -0.234147   0.101031  -2.318 0.020478 *  
## rankOrdLife_6E                  -0.276897   0.092993  -2.978 0.002907 ** 
## rankOrdLife_6F                  -0.235827   0.078785  -2.993 0.002761 ** 
## rankOrdLife_6None                0.740593   1.181110   0.627 0.530642    
## c19perBeh01                      0.087703   0.007091  12.368  < 2e-16 ***
## c19perBeh02                      0.024245   0.008576   2.827 0.004698 ** 
## c19perBeh03                     -0.030052   0.005077  -5.919 3.26e-09 ***
## c19RCA01                         0.021756   0.003870   5.622 1.91e-08 ***
## c19RCA02                        -0.000680   0.006141  -0.111 0.911826    
## c19RCA03                        -0.014971   0.004187  -3.576 0.000349 ***
## coronaClose_6                   -0.058603   0.013706  -4.276 1.91e-05 ***
## genderMale                      -0.175069   0.098967  -1.769 0.076908 .  
## genderFemale                    -0.091733   0.099260  -0.924 0.355403    
## genderOther                     -0.085261   0.129826  -0.657 0.511357    
## age                              0.001819   0.004056   0.448 0.653923    
## eduPrimary education            -0.129860   0.104312  -1.245 0.213167    
## eduGeneral secondary\neducation -0.105196   0.093370  -1.127 0.259893    
## eduVocational education          0.016575   0.093932   0.176 0.859933    
## eduHigher\neducation            -0.057863   0.092590  -0.625 0.532015    
## eduBachelors degree             -0.040156   0.092489  -0.434 0.664167    
## eduMasters degree               -0.056860   0.092966  -0.612 0.540791    
## eduPhD\ndegree                  -0.058818   0.095368  -0.617 0.537405    
## c19ProSo02                       0.210162   0.004514  46.561  < 2e-16 ***
## c19ProSo03                       0.267839   0.004619  57.983  < 2e-16 ***
## c19ProSo04                       0.116062   0.004621  25.117  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.178 on 39028 degrees of freedom
## Multiple R-squared:  0.3571, Adjusted R-squared:  0.356 
## F-statistic: 314.2 on 69 and 39028 DF,  p-value: < 2.2e-16
Identify best predictors for C19ProSo02
fit_nonfocuscountry_2 <- lm(cvbase_nonfocuscountry_table_withoutcoded$c19ProSo02 ~., data = cvbase_nonfocuscountry_table_withoutcoded)
summary(fit_nonfocuscountry_2)
## 
## Call:
## lm(formula = cvbase_nonfocuscountry_table_withoutcoded$c19ProSo02 ~ 
##     ., data = cvbase_nonfocuscountry_table_withoutcoded)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.7513 -0.6851  0.1511  0.8005  5.5362 
## 
## Coefficients: (4 not defined because of singularities)
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     -0.068298   0.315965  -0.216 0.828866    
## isoFriends_inPerson              0.024920   0.003007   8.288  < 2e-16 ***
## isoOthPpl_inPerson              -0.017437   0.003360  -5.190 2.11e-07 ***
## isoFriends_online                0.010273   0.003005   3.418 0.000630 ***
## isoOthPpl_online                 0.010260   0.002807   3.655 0.000258 ***
## lone01                           0.041178   0.008219   5.010 5.47e-07 ***
## lone02                          -0.036832   0.007258  -5.075 3.90e-07 ***
## lone03                           0.001734   0.007856   0.221 0.825337    
## happy                            0.020527   0.004185   4.905 9.38e-07 ***
## lifeSat                          0.053740   0.007662   7.014 2.36e-12 ***
## MLQ                              0.065734   0.005357  12.271  < 2e-16 ***
## bor01                            0.051734   0.004599  11.249  < 2e-16 ***
## bor02                           -0.011348   0.004604  -2.465 0.013705 *  
## bor03                            0.006906   0.004343   1.590 0.111845    
## consp01                         -0.022291   0.003423  -6.512 7.52e-11 ***
## consp02                         -0.015937   0.003532  -4.512 6.43e-06 ***
## consp03                          0.004199   0.002716   1.546 0.122187    
## rankOrdLife_1B                  -0.160863   0.097621  -1.648 0.099395 .  
## rankOrdLife_1C                  -0.109127   0.107252  -1.017 0.308932    
## rankOrdLife_1D                   0.203093   0.112877   1.799 0.071989 .  
## rankOrdLife_1E                  -0.174742   0.103985  -1.680 0.092878 .  
## rankOrdLife_1F                  -0.417319   0.089445  -4.666 3.09e-06 ***
## rankOrdLife_1None               -0.588075   1.314696  -0.447 0.654655    
## rankOrdLife_2B                  -0.130175   0.094208  -1.382 0.167047    
## rankOrdLife_2C                  -0.042803   0.105030  -0.408 0.683620    
## rankOrdLife_2D                   0.305362   0.110870   2.754 0.005886 ** 
## rankOrdLife_2E                   0.025731   0.102079   0.252 0.800989    
## rankOrdLife_2F                  -0.251356   0.090721  -2.771 0.005597 ** 
## rankOrdLife_2None                      NA         NA      NA       NA    
## rankOrdLife_3B                  -0.127677   0.101870  -1.253 0.210090    
## rankOrdLife_3C                   0.003158   0.110420   0.029 0.977183    
## rankOrdLife_3D                   0.285156   0.115723   2.464 0.013739 *  
## rankOrdLife_3E                  -0.086633   0.106828  -0.811 0.417397    
## rankOrdLife_3F                  -0.369932   0.093784  -3.945 8.01e-05 ***
## rankOrdLife_3None                      NA         NA      NA       NA    
## rankOrdLife_4B                  -0.107252   0.091776  -1.169 0.242560    
## rankOrdLife_4C                   0.038144   0.103677   0.368 0.712943    
## rankOrdLife_4D                   0.320275   0.110408   2.901 0.003724 ** 
## rankOrdLife_4E                  -0.017472   0.102156  -0.171 0.864203    
## rankOrdLife_4F                  -0.286827   0.090150  -3.182 0.001466 ** 
## rankOrdLife_4None                      NA         NA      NA       NA    
## rankOrdLife_5B                  -0.112255   0.091532  -1.226 0.220056    
## rankOrdLife_5C                   0.001516   0.103946   0.015 0.988366    
## rankOrdLife_5D                   0.274524   0.111231   2.468 0.013589 *  
## rankOrdLife_5E                  -0.005402   0.102392  -0.053 0.957924    
## rankOrdLife_5F                  -0.356885   0.088957  -4.012 6.04e-05 ***
## rankOrdLife_5None                      NA         NA      NA       NA    
## rankOrdLife_6B                  -0.096451   0.092060  -1.048 0.294782    
## rankOrdLife_6C                  -0.010741   0.103740  -0.104 0.917536    
## rankOrdLife_6D                   0.241419   0.110281   2.189 0.028593 *  
## rankOrdLife_6E                  -0.078937   0.101517  -0.778 0.436827    
## rankOrdLife_6F                  -0.424903   0.085980  -4.942 7.77e-07 ***
## rankOrdLife_6None                0.344102   1.289243   0.267 0.789546    
## c19perBeh01                      0.032301   0.007754   4.166 3.11e-05 ***
## c19perBeh02                      0.024048   0.009361   2.569 0.010205 *  
## c19perBeh03                      0.025137   0.005543   4.535 5.77e-06 ***
## c19RCA01                         0.066576   0.004213  15.804  < 2e-16 ***
## c19RCA02                        -0.009369   0.006703  -1.398 0.162214    
## c19RCA03                         0.076272   0.004554  16.748  < 2e-16 ***
## coronaClose_6                   -0.062795   0.014961  -4.197 2.71e-05 ***
## genderMale                       0.235022   0.108025   2.176 0.029589 *  
## genderFemale                     0.156854   0.108345   1.448 0.147702    
## genderOther                      0.025107   0.141711   0.177 0.859376    
## age                             -0.014712   0.004427  -3.323 0.000891 ***
## eduPrimary education            -0.209731   0.113859  -1.842 0.065479 .  
## eduGeneral secondary\neducation -0.202755   0.101914  -1.989 0.046657 *  
## eduVocational education         -0.308952   0.102519  -3.014 0.002583 ** 
## eduHigher\neducation            -0.195247   0.101063  -1.932 0.053374 .  
## eduBachelors degree             -0.103313   0.100955  -1.023 0.306148    
## eduMasters degree               -0.065697   0.101477  -0.647 0.517370    
## eduPhD\ndegree                  -0.022457   0.104099  -0.216 0.829198    
## c19ProSo01                       0.250403   0.005378  46.561  < 2e-16 ***
## c19ProSo03                       0.329910   0.004982  66.214  < 2e-16 ***
## c19ProSo04                       0.029158   0.005082   5.737 9.71e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.286 on 39028 degrees of freedom
## Multiple R-squared:  0.3899, Adjusted R-squared:  0.3888 
## F-statistic: 361.5 on 69 and 39028 DF,  p-value: < 2.2e-16
Identify Best Predictors for C19ProSo03
fit_nonfocuscountry_3 <- lm(cvbase_nonfocuscountry_table_withoutcoded$c19ProSo03 ~., data = cvbase_nonfocuscountry_table_withoutcoded)
summary(fit_nonfocuscountry_3)
## 
## Call:
## lm(formula = cvbase_nonfocuscountry_table_withoutcoded$c19ProSo03 ~ 
##     ., data = cvbase_nonfocuscountry_table_withoutcoded)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.4295 -0.6942  0.1654  0.7319  5.7602 
## 
## Coefficients: (4 not defined because of singularities)
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     -5.407e-01  3.043e-01  -1.777 0.075635 .  
## isoFriends_inPerson              5.154e-03  2.899e-03   1.778 0.075372 .  
## isoOthPpl_inPerson               1.551e-02  3.236e-03   4.792 1.66e-06 ***
## isoFriends_online               -7.422e-03  2.895e-03  -2.564 0.010357 *  
## isoOthPpl_online                 1.511e-02  2.703e-03   5.590 2.29e-08 ***
## lone01                          -1.684e-02  7.920e-03  -2.127 0.033447 *  
## lone02                          -5.926e-03  6.994e-03  -0.847 0.396856    
## lone03                           4.794e-02  7.564e-03   6.338 2.35e-10 ***
## happy                            2.327e-03  4.032e-03   0.577 0.563829    
## lifeSat                          2.480e-02  7.384e-03   3.358 0.000786 ***
## MLQ                             -1.036e-02  5.170e-03  -2.003 0.045134 *  
## bor01                           -1.808e-03  4.437e-03  -0.408 0.683587    
## bor02                            1.347e-02  4.435e-03   3.037 0.002392 ** 
## bor03                            1.397e-02  4.183e-03   3.340 0.000839 ***
## consp01                         -1.265e-02  3.299e-03  -3.836 0.000125 ***
## consp02                         -2.282e-02  3.401e-03  -6.711 1.96e-11 ***
## consp03                          6.327e-03  2.617e-03   2.418 0.015603 *  
## rankOrdLife_1B                  -1.489e-03  9.404e-02  -0.016 0.987370    
## rankOrdLife_1C                   1.621e-01  1.033e-01   1.569 0.116575    
## rankOrdLife_1D                  -6.535e-02  1.087e-01  -0.601 0.547875    
## rankOrdLife_1E                   4.974e-02  1.002e-01   0.497 0.619487    
## rankOrdLife_1F                   2.046e-01  8.618e-02   2.374 0.017590 *  
## rankOrdLife_1None                4.967e-01  1.266e+00   0.392 0.694912    
## rankOrdLife_2B                   6.638e-02  9.075e-02   0.731 0.464496    
## rankOrdLife_2C                   2.846e-01  1.012e-01   2.813 0.004906 ** 
## rankOrdLife_2D                   5.082e-02  1.068e-01   0.476 0.634195    
## rankOrdLife_2E                   1.680e-01  9.833e-02   1.709 0.087549 .  
## rankOrdLife_2F                   3.241e-01  8.738e-02   3.709 0.000208 ***
## rankOrdLife_2None                       NA         NA      NA       NA    
## rankOrdLife_3B                   2.439e-02  9.813e-02   0.249 0.803693    
## rankOrdLife_3C                   1.587e-01  1.064e-01   1.492 0.135792    
## rankOrdLife_3D                  -4.323e-02  1.115e-01  -0.388 0.698188    
## rankOrdLife_3E                   4.389e-02  1.029e-01   0.427 0.669725    
## rankOrdLife_3F                   2.180e-01  9.035e-02   2.412 0.015851 *  
## rankOrdLife_3None                       NA         NA      NA       NA    
## rankOrdLife_4B                  -1.650e-02  8.841e-02  -0.187 0.851920    
## rankOrdLife_4C                   1.745e-01  9.987e-02   1.748 0.080512 .  
## rankOrdLife_4D                  -1.031e-01  1.064e-01  -0.969 0.332488    
## rankOrdLife_4E                   8.441e-03  9.840e-02   0.086 0.931642    
## rankOrdLife_4F                   1.750e-01  8.685e-02   2.015 0.043940 *  
## rankOrdLife_4None                       NA         NA      NA       NA    
## rankOrdLife_5B                   1.431e-02  8.817e-02   0.162 0.871051    
## rankOrdLife_5C                   2.284e-01  1.001e-01   2.281 0.022530 *  
## rankOrdLife_5D                   9.828e-03  1.072e-01   0.092 0.926924    
## rankOrdLife_5E                   1.291e-01  9.863e-02   1.309 0.190696    
## rankOrdLife_5F                   2.761e-01  8.570e-02   3.221 0.001277 ** 
## rankOrdLife_5None                       NA         NA      NA       NA    
## rankOrdLife_6B                  -1.988e-03  8.868e-02  -0.022 0.982115    
## rankOrdLife_6C                   1.345e-01  9.993e-02   1.346 0.178273    
## rankOrdLife_6D                  -1.241e-01  1.062e-01  -1.168 0.242911    
## rankOrdLife_6E                  -5.609e-02  9.779e-02  -0.574 0.566259    
## rankOrdLife_6F                   1.746e-01  8.284e-02   2.108 0.035023 *  
## rankOrdLife_6None               -1.708e-02  1.242e+00  -0.014 0.989028    
## c19perBeh01                     -3.000e-03  7.470e-03  -0.402 0.687962    
## c19perBeh02                     -4.955e-03  9.018e-03  -0.549 0.582688    
## c19perBeh03                      1.114e-02  5.340e-03   2.086 0.036987 *  
## c19RCA01                         1.021e-03  4.071e-03   0.251 0.801878    
## c19RCA02                        -2.244e-02  6.456e-03  -3.476 0.000509 ***
## c19RCA03                        -2.066e-02  4.401e-03  -4.694 2.69e-06 ***
## coronaClose_6                   -1.926e-02  1.441e-02  -1.336 0.181441    
## genderMale                       3.171e-05  1.041e-01   0.000 0.999757    
## genderFemale                     2.374e-02  1.044e-01   0.227 0.820060    
## genderOther                      7.979e-02  1.365e-01   0.585 0.558863    
## age                             -7.131e-02  4.250e-03 -16.781  < 2e-16 ***
## eduPrimary education             2.678e-02  1.097e-01   0.244 0.807119    
## eduGeneral secondary\neducation  1.547e-02  9.818e-02   0.158 0.874785    
## eduVocational education          1.193e-02  9.877e-02   0.121 0.903843    
## eduHigher\neducation             1.135e-02  9.736e-02   0.117 0.907155    
## eduBachelors degree              5.064e-02  9.725e-02   0.521 0.602581    
## eduMasters degree                7.093e-02  9.775e-02   0.726 0.468077    
## eduPhD\ndegree                   1.815e-01  1.003e-01   1.810 0.070246 .  
## c19ProSo01                       2.961e-01  5.107e-03  57.983  < 2e-16 ***
## c19ProSo02                       3.061e-01  4.623e-03  66.214  < 2e-16 ***
## c19ProSo04                       3.044e-01  4.649e-03  65.483  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.238 on 39028 degrees of freedom
## Multiple R-squared:  0.4482, Adjusted R-squared:  0.4472 
## F-statistic: 459.4 on 69 and 39028 DF,  p-value: < 2.2e-16
Identify Best Predictors for C19ProSo04
fit_nonfocuscountry_4 <- lm(cvbase_nonfocuscountry_table_withoutcoded$c19ProSo04 ~., data = cvbase_nonfocuscountry_table_withoutcoded)
summary(fit_nonfocuscountry_4)
## 
## Call:
## lm(formula = cvbase_nonfocuscountry_table_withoutcoded$c19ProSo04 ~ 
##     ., data = cvbase_nonfocuscountry_table_withoutcoded)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.6953 -0.6741  0.1325  0.8001  5.6338 
## 
## Coefficients: (4 not defined because of singularities)
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     -0.3531033  0.3145511  -1.123 0.261630    
## isoFriends_inPerson             -0.0164368  0.0029947  -5.489 4.08e-08 ***
## isoOthPpl_inPerson              -0.0009225  0.0033458  -0.276 0.782776    
## isoFriends_online                0.0116004  0.0029916   3.878 0.000106 ***
## isoOthPpl_online                -0.0030730  0.0027950  -1.099 0.271579    
## lone01                          -0.0362782  0.0081834  -4.433 9.31e-06 ***
## lone02                           0.0506738  0.0072236   7.015 2.34e-12 ***
## lone03                           0.0122201  0.0078212   1.562 0.118192    
## happy                           -0.0119964  0.0041671  -2.879 0.003994 ** 
## lifeSat                          0.0392686  0.0076302   5.146 2.67e-07 ***
## MLQ                             -0.0179764  0.0053423  -3.365 0.000766 ***
## bor01                           -0.0155168  0.0045850  -3.384 0.000714 ***
## bor02                            0.0207246  0.0045824   4.523 6.12e-06 ***
## bor03                            0.0235660  0.0043225   5.452 5.01e-08 ***
## consp01                          0.0310994  0.0034062   9.130  < 2e-16 ***
## consp02                          0.0038135  0.0035170   1.084 0.278235    
## consp03                         -0.0032435  0.0027043  -1.199 0.230393    
## rankOrdLife_1B                  -0.0136249  0.0971890  -0.140 0.888511    
## rankOrdLife_1C                   0.0443169  0.1067755   0.415 0.678109    
## rankOrdLife_1D                   0.0101439  0.1123789   0.090 0.928077    
## rankOrdLife_1E                   0.3359468  0.1035114   3.246 0.001173 ** 
## rankOrdLife_1F                   0.2268047  0.0890634   2.547 0.010883 *  
## rankOrdLife_1None                1.0712549  1.3088275   0.818 0.413086    
## rankOrdLife_2B                   0.0445959  0.0937904   0.475 0.634444    
## rankOrdLife_2C                   0.0542378  0.1045618   0.519 0.603962    
## rankOrdLife_2D                   0.0240368  0.1103863   0.218 0.827624    
## rankOrdLife_2E                   0.2082895  0.1016190   2.050 0.040399 *  
## rankOrdLife_2F                   0.1642959  0.0903212   1.819 0.068916 .  
## rankOrdLife_2None                       NA         NA      NA       NA    
## rankOrdLife_3B                  -0.0260386  0.1014175  -0.257 0.797376    
## rankOrdLife_3C                   0.0930447  0.1099266   0.846 0.397320    
## rankOrdLife_3D                  -0.0399203  0.1152160  -0.346 0.728982    
## rankOrdLife_3E                   0.2606439  0.1063446   2.451 0.014253 *  
## rankOrdLife_3F                   0.1945753  0.0933789   2.084 0.037192 *  
## rankOrdLife_3None                       NA         NA      NA       NA    
## rankOrdLife_4B                   0.0304354  0.0913683   0.333 0.739055    
## rankOrdLife_4C                   0.0344162  0.1032153   0.333 0.738803    
## rankOrdLife_4D                  -0.1031247  0.1099265  -0.938 0.348187    
## rankOrdLife_4E                   0.1260181  0.1016990   1.239 0.215305    
## rankOrdLife_4F                   0.0059417  0.0897602   0.066 0.947223    
## rankOrdLife_4None                       NA         NA      NA       NA    
## rankOrdLife_5B                  -0.0224134  0.0911256  -0.246 0.805714    
## rankOrdLife_5C                  -0.0403799  0.1034826  -0.390 0.696384    
## rankOrdLife_5D                  -0.1395902  0.1107414  -1.261 0.207495    
## rankOrdLife_5E                   0.1113017  0.1019337   1.092 0.274883    
## rankOrdLife_5F                  -0.0238572  0.0885790  -0.269 0.787675    
## rankOrdLife_5None                       NA         NA      NA       NA    
## rankOrdLife_6B                  -0.0157834  0.0916505  -0.172 0.863271    
## rankOrdLife_6C                  -0.0216681  0.1032775  -0.210 0.833821    
## rankOrdLife_6D                  -0.1553012  0.1097932  -1.414 0.157227    
## rankOrdLife_6E                   0.0862898  0.1010645   0.854 0.393216    
## rankOrdLife_6F                  -0.0386599  0.0856237  -0.452 0.651625    
## rankOrdLife_6None               -0.8917012  1.2834884  -0.695 0.487217    
## c19perBeh01                      0.0288094  0.0077193   3.732 0.000190 ***
## c19perBeh02                      0.1201711  0.0093003  12.921  < 2e-16 ***
## c19perBeh03                      0.0788599  0.0055050  14.325  < 2e-16 ***
## c19RCA01                         0.0260745  0.0042053   6.200 5.69e-10 ***
## c19RCA02                         0.0992844  0.0066545  14.920  < 2e-16 ***
## c19RCA03                        -0.0494739  0.0045433 -10.889  < 2e-16 ***
## coronaClose_6                   -0.1289673  0.0148836  -8.665  < 2e-16 ***
## genderMale                      -0.2324281  0.1075431  -2.161 0.030682 *  
## genderFemale                    -0.2510462  0.1078575  -2.328 0.019940 *  
## genderOther                     -0.0786837  0.1410792  -0.558 0.577034    
## age                              0.0534956  0.0043997  12.159  < 2e-16 ***
## eduPrimary education             0.1713024  0.1133528   1.511 0.130737    
## eduGeneral secondary\neducation  0.0327627  0.1014647   0.323 0.746774    
## eduVocational education          0.0236026  0.1020737   0.231 0.817136    
## eduHigher\neducation             0.0640335  0.1006163   0.636 0.524511    
## eduBachelors degree              0.0730171  0.1005059   0.726 0.467539    
## eduMasters degree                0.0851634  0.1010244   0.843 0.399234    
## eduPhD\ndegree                   0.1313112  0.1036329   1.267 0.205134    
## c19ProSo01                       0.1370544  0.0054567  25.117  < 2e-16 ***
## c19ProSo02                       0.0288981  0.0050372   5.737 9.71e-09 ***
## c19ProSo03                       0.3251746  0.0049658  65.483  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.28 on 39028 degrees of freedom
## Multiple R-squared:  0.3345, Adjusted R-squared:  0.3333 
## F-statistic: 284.2 on 69 and 39028 DF,  p-value: < 2.2e-16

Q3A: Clustering

set.seed(9999)  # For reproducibility
external_sources <- read.csv("external_sources.csv")
external_sources$coded_country <- iconv(external_sources$coded_country, "ISO-8859-1", "UTF-8")
external_sources_selected <- external_sources %>%
  select(health_security, VoiceAccountability, GovernanceEffectiveness, RuleOfLaw) %>%
  scale()  # Standardizes the data
# Perform k-means clustering
kmeans_result <- kmeans(external_sources_selected, centers = 2, nstart = 20)  # you can adjust the number of clusters
# calculate silhouette score
library(cluster)

external_sources = read.csv("external_sources.csv")

# gives the optimum number of clusters
i_silhouette_score = function(k){
  km = kmeans(external_sources_selected, k, nstart = 20)
  # ss gives all of the rows, which shows cluster, neighbour and sil_width
  # which is the score
  ss = silhouette(km$cluster, dist(external_sources_selected))
  # average the sil scores, higher the score the btter the clustering
  mean(ss[,3])
}

k = 2: 20
avg_sil = sapply(k, i_silhouette_score)
plot(k, avg_sil, type = 'b', xlab = 'Number of clusters', ylab = 'Average Silhouette Scores')

df = data.frame(k, avg_sil)
View(df)
df[which.max(df[,df$avg_sil])]
## data frame with 0 columns and 19 rows
external_sources$cluster <- kmeans_result$cluster
View(external_sources)
south_africa_cluster <- external_sources[external_sources$coded_country == "South Africa", "cluster"]
similar_countries_cluster <- external_sources[which(external_sources$cluster == south_africa_cluster),]
print(similar_countries_cluster$coded_country)
##  [1] "Argentina"                "Armenia"                 
##  [3] "Australia"                "Austria"                 
##  [5] "Barbados"                 "Belgium"                 
##  [7] "Bhutan"                   "Bulgaria"                
##  [9] "Canada"                   "Chile"                   
## [11] "Costa Rica"               "Croatia"                 
## [13] "Cyprus"                   "Czech Republic"          
## [15] "Denmark"                  "Estonia"                 
## [17] "Finland"                  "France"                  
## [19] "Georgia"                  "Germany"                 
## [21] "Greece"                   "Hungary"                 
## [23] "Iceland"                  "Ireland"                 
## [25] "Israel"                   "Italy"                   
## [27] "Japan"                    "Latvia"                  
## [29] "Liechtenstein"            "Lithuania"               
## [31] "Luxembourg"               "Malaysia"                
## [33] "Malta"                    "Mauritius"               
## [35] "Monaco"                   "Netherlands"             
## [37] "New Zealand"              "Norway"                  
## [39] "Panama"                   "Poland"                  
## [41] "Portugal"                 "Romania"                 
## [43] "Samoa"                    "San Marino"              
## [45] "Singapore"                "Slovenia"                
## [47] "South Africa"             "South Korea"             
## [49] "Spain"                    "Sweden"                  
## [51] "Switzerland"              "Thailand"                
## [53] "United Kingdom"           "United States of America"
## [55] "Uruguay"

Question 3B: P-Value

similar_countries <- c("Argentina", "Armenia", "Australia", "Austria", "Barbados", 
               "Belgium", "Bhutan", "Bulgaria", "Canada", "Chile", "Costa Rica", 
               "Croatia", "Cyprus", "Czech Republic", "Denmark", "Estonia", 
               "Finland", "France", "Georgia", "Germany", "Greece", "Hungary", 
               "Iceland", "Ireland", "Israel", "Italy", "Japan", "Latvia", 
               "Liechtenstein", "Lithuania", "Luxembourg", "Malaysia", "Malta", 
               "Mauritius", "Monaco", "Netherlands", "New Zealand", "Norway", 
               "Panama", "Poland", "Portugal", "Romania", "Samoa", "San Marino", 
               "Singapore", "Slovenia", "South Africa", "South Korea", "Spain", 
               "Sweden", "Switzerland", "Thailand", "United Kingdom", 
               "United States of America", "Uruguay")
cvbase_similar_countries <- cvbase %>% 
  filter(coded_country %in% similar_countries)
View(cvbase_similar_countries)

Extract The Data Without Coded Country

cvbase_similar_cluster_withoutcodedcountry <- cvbase_similar_countries %>% 
  select(-coded_country)
Identify Best Predictors In Similar Cluster Countries for c19ProSo01
cvbase_smilar_cluster_fit1 <- lm(cvbase_similar_cluster_withoutcodedcountry$c19ProSo01~., data = cvbase_similar_cluster_withoutcodedcountry)
summary(cvbase_smilar_cluster_fit1)
## 
## Call:
## lm(formula = cvbase_similar_cluster_withoutcodedcountry$c19ProSo01 ~ 
##     ., data = cvbase_similar_cluster_withoutcodedcountry)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.4894 -0.5983  0.1270  0.7251  4.2190 
## 
## Coefficients: (5 not defined because of singularities)
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      0.7208064  0.3018919   2.388 0.016964 *  
## isoFriends_inPerson              0.0099009  0.0034318   2.885 0.003917 ** 
## isoOthPpl_inPerson               0.0237658  0.0037690   6.306 2.91e-10 ***
## isoFriends_online                0.0095492  0.0033281   2.869 0.004117 ** 
## isoOthPpl_online                 0.0043603  0.0031390   1.389 0.164822    
## lone01                           0.0362418  0.0093187   3.889 0.000101 ***
## lone02                          -0.0189553  0.0082209  -2.306 0.021132 *  
## lone03                           0.0022157  0.0088066   0.252 0.801358    
## happy                           -0.0009339  0.0047129  -0.198 0.842921    
## lifeSat                          0.0140573  0.0086614   1.623 0.104607    
## MLQ                              0.0368874  0.0060749   6.072 1.28e-09 ***
## bor01                            0.0183070  0.0053476   3.423 0.000619 ***
## bor02                           -0.0080294  0.0054236  -1.480 0.138767    
## bor03                            0.0202562  0.0048527   4.174 3.00e-05 ***
## consp01                          0.0142833  0.0038888   3.673 0.000240 ***
## consp02                          0.0024222  0.0040944   0.592 0.554132    
## consp03                          0.0032615  0.0031496   1.036 0.300425    
## rankOrdLife_1B                  -0.0168172  0.0932175  -0.180 0.856833    
## rankOrdLife_1C                  -0.0602187  0.1012780  -0.595 0.552124    
## rankOrdLife_1D                  -0.0884626  0.1072949  -0.824 0.409674    
## rankOrdLife_1E                  -0.1194453  0.0984919  -1.213 0.225239    
## rankOrdLife_1F                  -0.0286569  0.0858266  -0.334 0.738463    
## rankOrdLife_1None               -0.5747026  0.2830399  -2.030 0.042319 *  
## rankOrdLife_2B                   0.0064775  0.0883029   0.073 0.941524    
## rankOrdLife_2C                  -0.0330524  0.0979824  -0.337 0.735871    
## rankOrdLife_2D                  -0.0647679  0.1041698  -0.622 0.534110    
## rankOrdLife_2E                  -0.0928921  0.0955664  -0.972 0.331051    
## rankOrdLife_2F                  -0.0145680  0.0872166  -0.167 0.867346    
## rankOrdLife_2None                       NA         NA      NA       NA    
## rankOrdLife_3B                   0.0375076  0.1003165   0.374 0.708487    
## rankOrdLife_3C                   0.0232018  0.1066649   0.218 0.827805    
## rankOrdLife_3D                  -0.0135378  0.1119901  -0.121 0.903784    
## rankOrdLife_3E                  -0.0410118  0.1033173  -0.397 0.691408    
## rankOrdLife_3F                   0.0083824  0.0926631   0.090 0.927922    
## rankOrdLife_3None                       NA         NA      NA       NA    
## rankOrdLife_4B                   0.0223110  0.0846023   0.264 0.792001    
## rankOrdLife_4C                  -0.0783414  0.0959762  -0.816 0.414360    
## rankOrdLife_4D                  -0.0990938  0.1036378  -0.956 0.339003    
## rankOrdLife_4E                  -0.1885101  0.0958213  -1.967 0.049158 *  
## rankOrdLife_4F                  -0.1285636  0.0865341  -1.486 0.137371    
## rankOrdLife_4None                       NA         NA      NA       NA    
## rankOrdLife_5B                   0.0426323  0.0843169   0.506 0.613128    
## rankOrdLife_5C                  -0.0289933  0.0963292  -0.301 0.763431    
## rankOrdLife_5D                  -0.0846799  0.1046757  -0.809 0.418537    
## rankOrdLife_5E                  -0.1130440  0.0961974  -1.175 0.239955    
## rankOrdLife_5F                  -0.0223181  0.0851519  -0.262 0.793249    
## rankOrdLife_5None                       NA         NA      NA       NA    
## rankOrdLife_6B                  -0.0470011  0.0849515  -0.553 0.580083    
## rankOrdLife_6C                  -0.1589303  0.0960077  -1.655 0.097857 .  
## rankOrdLife_6D                  -0.1859528  0.1032520  -1.801 0.071720 .  
## rankOrdLife_6E                  -0.3233111  0.0949727  -3.404 0.000664 ***
## rankOrdLife_6F                  -0.2647511  0.0806288  -3.284 0.001026 ** 
## rankOrdLife_6None                       NA         NA      NA       NA    
## c19perBeh01                      0.0812459  0.0086050   9.442  < 2e-16 ***
## c19perBeh02                      0.0342694  0.0105740   3.241 0.001193 ** 
## c19perBeh03                     -0.0298213  0.0060194  -4.954 7.31e-07 ***
## c19RCA01                         0.0269360  0.0045513   5.918 3.29e-09 ***
## c19RCA02                        -0.0019815  0.0071622  -0.277 0.782037    
## c19RCA03                        -0.0305175  0.0048169  -6.336 2.40e-10 ***
## coronaClose_6                   -0.0663058  0.0166124  -3.991 6.59e-05 ***
## genderMale                      -0.2241368  0.1137985  -1.970 0.048895 *  
## genderFemale                    -0.1357038  0.1142083  -1.188 0.234760    
## genderOther                     -0.0288704  0.1489097  -0.194 0.846273    
## age                              0.0031009  0.0048071   0.645 0.518886    
## eduPrimary education            -0.2924537  0.1250069  -2.339 0.019317 *  
## eduGeneral secondary\neducation -0.2230198  0.1144323  -1.949 0.051315 .  
## eduVocational education         -0.1576184  0.1151129  -1.369 0.170933    
## eduHigher\neducation            -0.2018900  0.1134066  -1.780 0.075049 .  
## eduBachelors degree             -0.2061813  0.1133778  -1.819 0.068994 .  
## eduMasters degree               -0.2172432  0.1138616  -1.908 0.056407 .  
## eduPhD\ndegree                  -0.2361961  0.1164008  -2.029 0.042452 *  
## c19ProSo02                       0.1907449  0.0052567  36.286  < 2e-16 ***
## c19ProSo03                       0.2982856  0.0054357  54.875  < 2e-16 ***
## c19ProSo04                       0.0813866  0.0059355  13.712  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.173 on 26524 degrees of freedom
## Multiple R-squared:  0.3505, Adjusted R-squared:  0.3489 
## F-statistic: 210.5 on 68 and 26524 DF,  p-value: < 2.2e-16
Identify Best Predictors In Similar Cluster Countries for c19ProSo02
cvbase_smilar_cluster_fit2 <- lm(cvbase_similar_cluster_withoutcodedcountry$c19ProSo02~., data = cvbase_similar_cluster_withoutcodedcountry)
summary(cvbase_smilar_cluster_fit2)
## 
## Call:
## lm(formula = cvbase_similar_cluster_withoutcodedcountry$c19ProSo02 ~ 
##     ., data = cvbase_similar_cluster_withoutcodedcountry)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.4461 -0.7415  0.1816  0.8660  5.5495 
## 
## Coefficients: (5 not defined because of singularities)
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     -0.059040   0.344228  -0.172 0.863822    
## isoFriends_inPerson              0.009157   0.003913   2.340 0.019284 *  
## isoOthPpl_inPerson              -0.011401   0.004300  -2.652 0.008017 ** 
## isoFriends_online                0.007619   0.003795   2.008 0.044688 *  
## isoOthPpl_online                 0.010486   0.003578   2.930 0.003388 ** 
## lone01                           0.021041   0.010627   1.980 0.047711 *  
## lone02                          -0.029547   0.009372  -3.153 0.001619 ** 
## lone03                           0.026624   0.010039   2.652 0.008006 ** 
## happy                            0.027966   0.005370   5.207 1.93e-07 ***
## lifeSat                          0.050259   0.009871   5.092 3.57e-07 ***
## MLQ                              0.049678   0.006924   7.175 7.44e-13 ***
## bor01                            0.033512   0.006095   5.498 3.87e-08 ***
## bor02                            0.007431   0.006184   1.202 0.229472    
## bor03                            0.014231   0.005534   2.572 0.010125 *  
## consp01                         -0.020599   0.004433  -4.647 3.39e-06 ***
## consp02                         -0.018371   0.004667  -3.936 8.29e-05 ***
## consp03                          0.011120   0.003590   3.097 0.001956 ** 
## rankOrdLife_1B                  -0.202139   0.106271  -1.902 0.057169 .  
## rankOrdLife_1C                  -0.092041   0.115468  -0.797 0.425393    
## rankOrdLife_1D                   0.140624   0.122327   1.150 0.250329    
## rankOrdLife_1E                  -0.188509   0.112289  -1.679 0.093205 .  
## rankOrdLife_1F                  -0.395406   0.097822  -4.042 5.31e-05 ***
## rankOrdLife_1None               -0.385373   0.322714  -1.194 0.232425    
## rankOrdLife_2B                  -0.140439   0.100672  -1.395 0.163022    
## rankOrdLife_2C                  -0.064252   0.111711  -0.575 0.565184    
## rankOrdLife_2D                   0.232829   0.118758   1.961 0.049943 *  
## rankOrdLife_2E                  -0.038545   0.108958  -0.354 0.723525    
## rankOrdLife_2F                  -0.320411   0.099417  -3.223 0.001271 ** 
## rankOrdLife_2None                      NA         NA      NA       NA    
## rankOrdLife_3B                  -0.173444   0.114368  -1.517 0.129392    
## rankOrdLife_3C                  -0.009202   0.121610  -0.076 0.939683    
## rankOrdLife_3D                   0.204770   0.127675   1.604 0.108762    
## rankOrdLife_3E                  -0.105643   0.117792  -0.897 0.369802    
## rankOrdLife_3F                  -0.322926   0.105628  -3.057 0.002236 ** 
## rankOrdLife_3None                      NA         NA      NA       NA    
## rankOrdLife_4B                  -0.149333   0.096452  -1.548 0.121571    
## rankOrdLife_4C                  -0.002576   0.109425  -0.024 0.981218    
## rankOrdLife_4D                   0.200242   0.118155   1.695 0.090135 .  
## rankOrdLife_4E                  -0.080474   0.109254  -0.737 0.461385    
## rankOrdLife_4F                  -0.334465   0.098641  -3.391 0.000698 ***
## rankOrdLife_4None                      NA         NA      NA       NA    
## rankOrdLife_5B                  -0.158987   0.096126  -1.654 0.098152 .  
## rankOrdLife_5C                  -0.030037   0.109826  -0.273 0.784478    
## rankOrdLife_5D                   0.186109   0.119338   1.560 0.118888    
## rankOrdLife_5E                  -0.052129   0.109678  -0.475 0.634583    
## rankOrdLife_5F                  -0.375176   0.097056  -3.866 0.000111 ***
## rankOrdLife_5None                      NA         NA      NA       NA    
## rankOrdLife_6B                  -0.145520   0.096851  -1.503 0.132974    
## rankOrdLife_6C                  -0.040246   0.109465  -0.368 0.713129    
## rankOrdLife_6D                   0.145887   0.117723   1.239 0.215267    
## rankOrdLife_6E                  -0.119256   0.108301  -1.101 0.270840    
## rankOrdLife_6F                  -0.402212   0.091912  -4.376 1.21e-05 ***
## rankOrdLife_6None                      NA         NA      NA       NA    
## c19perBeh01                      0.045429   0.009823   4.625 3.77e-06 ***
## c19perBeh02                      0.005497   0.012058   0.456 0.648480    
## c19perBeh03                      0.031257   0.006863   4.554 5.28e-06 ***
## c19RCA01                         0.067262   0.005176  12.995  < 2e-16 ***
## c19RCA02                        -0.003936   0.008166  -0.482 0.629823    
## c19RCA03                         0.047128   0.005488   8.587  < 2e-16 ***
## coronaClose_6                   -0.044389   0.018944  -2.343 0.019126 *  
## genderMale                       0.200199   0.129747   1.543 0.122844    
## genderFemale                     0.114638   0.130212   0.880 0.378652    
## genderOther                      0.035327   0.169774   0.208 0.835167    
## age                              0.020079   0.005479   3.665 0.000248 ***
## eduPrimary education            -0.224631   0.142530  -1.576 0.115032    
## eduGeneral secondary\neducation -0.372096   0.130455  -2.852 0.004344 ** 
## eduVocational education         -0.465292   0.131215  -3.546 0.000392 ***
## eduHigher\neducation            -0.231420   0.129296  -1.790 0.073491 .  
## eduBachelors degree             -0.195012   0.129266  -1.509 0.131410    
## eduMasters degree               -0.116212   0.129822  -0.895 0.370709    
## eduPhD\ndegree                  -0.022112   0.132720  -0.167 0.867682    
## c19ProSo01                       0.247941   0.006833  36.286  < 2e-16 ***
## c19ProSo03                       0.311987   0.006253  49.896  < 2e-16 ***
## c19ProSo04                       0.034395   0.006788   5.067 4.07e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.338 on 26524 degrees of freedom
## Multiple R-squared:  0.342,  Adjusted R-squared:  0.3403 
## F-statistic: 202.8 on 68 and 26524 DF,  p-value: < 2.2e-16
Identify Best Predictors In Similar Cluster Countries for c19ProSo03
cvbase_smilar_cluster_fit3 <- lm(cvbase_similar_cluster_withoutcodedcountry$c19ProSo03~., data = cvbase_similar_cluster_withoutcodedcountry)
summary(cvbase_smilar_cluster_fit3)
## 
## Call:
## lm(formula = cvbase_similar_cluster_withoutcodedcountry$c19ProSo03 ~ 
##     ., data = cvbase_similar_cluster_withoutcodedcountry)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.4544 -0.7060  0.1549  0.7487  5.9139 
## 
## Coefficients: (5 not defined because of singularities)
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     -7.158e-01  3.232e-01  -2.215 0.026776 *  
## isoFriends_inPerson              5.549e-03  3.674e-03   1.510 0.130980    
## isoOthPpl_inPerson               1.286e-02  4.037e-03   3.186 0.001445 ** 
## isoFriends_online               -6.225e-03  3.563e-03  -1.747 0.080646 .  
## isoOthPpl_online                 2.015e-02  3.358e-03   5.999 2.01e-09 ***
## lone01                           5.147e-03  9.978e-03   0.516 0.605969    
## lone02                          -4.192e-03  8.801e-03  -0.476 0.633885    
## lone03                           3.105e-02  9.425e-03   3.294 0.000989 ***
## happy                            7.643e-05  5.045e-03   0.015 0.987914    
## lifeSat                          2.171e-02  9.271e-03   2.342 0.019188 *  
## MLQ                             -1.052e-03  6.507e-03  -0.162 0.871545    
## bor01                           -2.355e-03  5.726e-03  -0.411 0.680840    
## bor02                            1.090e-02  5.806e-03   1.877 0.060549 .  
## bor03                            9.432e-03  5.196e-03   1.815 0.069503 .  
## consp01                         -9.765e-03  4.163e-03  -2.345 0.019012 *  
## consp02                         -2.097e-02  4.381e-03  -4.786 1.71e-06 ***
## consp03                          6.550e-03  3.371e-03   1.943 0.052045 .  
## rankOrdLife_1B                   1.337e-02  9.979e-02   0.134 0.893387    
## rankOrdLife_1C                   1.678e-01  1.084e-01   1.548 0.121716    
## rankOrdLife_1D                  -2.537e-03  1.149e-01  -0.022 0.982380    
## rankOrdLife_1E                   7.737e-02  1.054e-01   0.734 0.463047    
## rankOrdLife_1F                   1.729e-01  9.187e-02   1.883 0.059778 .  
## rankOrdLife_1None                6.014e-01  3.030e-01   1.985 0.047160 *  
## rankOrdLife_2B                   7.023e-02  9.452e-02   0.743 0.457494    
## rankOrdLife_2C                   2.755e-01  1.049e-01   2.627 0.008608 ** 
## rankOrdLife_2D                   7.645e-02  1.115e-01   0.686 0.492982    
## rankOrdLife_2E                   1.798e-01  1.023e-01   1.758 0.078813 .  
## rankOrdLife_2F                   3.041e-01  9.334e-02   3.258 0.001123 ** 
## rankOrdLife_2None                       NA         NA      NA       NA    
## rankOrdLife_3B                   6.284e-02  1.074e-01   0.585 0.558416    
## rankOrdLife_3C                   1.403e-01  1.142e-01   1.229 0.219016    
## rankOrdLife_3D                   1.980e-02  1.199e-01   0.165 0.868824    
## rankOrdLife_3E                   8.261e-02  1.106e-01   0.747 0.455118    
## rankOrdLife_3F                   2.180e-01  9.918e-02   2.197 0.027997 *  
## rankOrdLife_3None                       NA         NA      NA       NA    
## rankOrdLife_4B                  -2.983e-02  9.056e-02  -0.329 0.741871    
## rankOrdLife_4C                   1.725e-01  1.027e-01   1.679 0.093192 .  
## rankOrdLife_4D                  -6.870e-02  1.109e-01  -0.619 0.535789    
## rankOrdLife_4E                  -2.088e-02  1.026e-01  -0.204 0.838676    
## rankOrdLife_4F                   1.491e-01  9.263e-02   1.609 0.107536    
## rankOrdLife_4None                       NA         NA      NA       NA    
## rankOrdLife_5B                   1.837e-02  9.026e-02   0.204 0.838692    
## rankOrdLife_5C                   2.138e-01  1.031e-01   2.074 0.038116 *  
## rankOrdLife_5D                   6.195e-02  1.121e-01   0.553 0.580380    
## rankOrdLife_5E                   1.283e-01  1.030e-01   1.246 0.212692    
## rankOrdLife_5F                   2.744e-01  9.114e-02   3.011 0.002610 ** 
## rankOrdLife_5None                       NA         NA      NA       NA    
## rankOrdLife_6B                  -6.122e-03  9.094e-02  -0.067 0.946323    
## rankOrdLife_6C                   1.285e-01  1.028e-01   1.251 0.211086    
## rankOrdLife_6D                  -1.190e-01  1.105e-01  -1.077 0.281615    
## rankOrdLife_6E                  -7.531e-02  1.017e-01  -0.741 0.458965    
## rankOrdLife_6F                   1.346e-01  8.632e-02   1.559 0.119040    
## rankOrdLife_6None                       NA         NA      NA       NA    
## c19perBeh01                      5.794e-03  9.227e-03   0.628 0.530057    
## c19perBeh02                     -3.019e-02  1.132e-02  -2.667 0.007656 ** 
## c19perBeh03                      1.214e-02  6.446e-03   1.884 0.059628 .  
## c19RCA01                        -2.079e-03  4.875e-03  -0.426 0.669818    
## c19RCA02                        -2.772e-02  7.665e-03  -3.616 0.000300 ***
## c19RCA03                        -1.207e-02  5.160e-03  -2.340 0.019303 *  
## coronaClose_6                   -2.822e-02  1.779e-02  -1.586 0.112670    
## genderMale                       3.737e-02  1.218e-01   0.307 0.759057    
## genderFemale                     5.043e-02  1.223e-01   0.413 0.679974    
## genderOther                      7.408e-02  1.594e-01   0.465 0.642133    
## age                             -9.227e-02  5.115e-03 -18.041  < 2e-16 ***
## eduPrimary education             1.651e-01  1.338e-01   1.234 0.217270    
## eduGeneral secondary\neducation  2.084e-01  1.225e-01   1.701 0.088982 .  
## eduVocational education          2.323e-01  1.232e-01   1.885 0.059399 .  
## eduHigher\neducation             1.638e-01  1.214e-01   1.349 0.177205    
## eduBachelors degree              2.472e-01  1.214e-01   2.037 0.041692 *  
## eduMasters degree                2.432e-01  1.219e-01   1.995 0.046037 *  
## eduPhD\ndegree                   3.565e-01  1.246e-01   2.861 0.004223 ** 
## c19ProSo01                       3.418e-01  6.229e-03  54.875  < 2e-16 ***
## c19ProSo02                       2.750e-01  5.512e-03  49.896  < 2e-16 ***
## c19ProSo04                       3.109e-01  6.084e-03  51.109  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.256 on 26524 degrees of freedom
## Multiple R-squared:  0.4363, Adjusted R-squared:  0.4349 
## F-statistic: 301.9 on 68 and 26524 DF,  p-value: < 2.2e-16
Identify Best Predictors In Similar Cluster Countries for c19ProSo04
cvbase_smilar_cluster_fit4 <- lm(cvbase_similar_cluster_withoutcodedcountry$c19ProSo04~., data = cvbase_similar_cluster_withoutcodedcountry)
summary(cvbase_smilar_cluster_fit4)
## 
## Call:
## lm(formula = cvbase_similar_cluster_withoutcodedcountry$c19ProSo04 ~ 
##     ., data = cvbase_similar_cluster_withoutcodedcountry)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.5806 -0.5900  0.1365  0.7542  5.5145 
## 
## Coefficients: (5 not defined because of singularities)
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     -0.4203033  0.3112231  -1.350 0.176871    
## isoFriends_inPerson             -0.0072276  0.0035379  -2.043 0.041073 *  
## isoOthPpl_inPerson              -0.0003532  0.0038881  -0.091 0.927615    
## isoFriends_online                0.0182880  0.0034294   5.333 9.75e-08 ***
## isoOthPpl_online                 0.0010538  0.0032359   0.326 0.744677    
## lone01                          -0.0278099  0.0096072  -2.895 0.003798 ** 
## lone02                           0.0670697  0.0084652   7.923 2.41e-15 ***
## lone03                          -0.0073869  0.0090781  -0.814 0.415819    
## happy                           -0.0094178  0.0048579  -1.939 0.052553 .  
## lifeSat                          0.0198783  0.0089281   2.226 0.025990 *  
## MLQ                              0.0057923  0.0062664   0.924 0.355320    
## bor01                           -0.0215417  0.0055121  -3.908 9.33e-05 ***
## bor02                            0.0132142  0.0055905   2.364 0.018101 *  
## bor03                            0.0061272  0.0050038   1.224 0.220778    
## consp01                          0.0216056  0.0040076   5.391 7.06e-08 ***
## consp02                          0.0092371  0.0042203   2.189 0.028626 *  
## consp03                         -0.0129948  0.0032458  -4.004 6.26e-05 ***
## rankOrdLife_1B                   0.0368727  0.0960915   0.384 0.701186    
## rankOrdLife_1C                   0.1234948  0.1043987   1.183 0.236854    
## rankOrdLife_1D                   0.0957057  0.1106031   0.865 0.386878    
## rankOrdLife_1E                   0.4002398  0.1015018   3.943 8.06e-05 ***
## rankOrdLife_1F                   0.3150663  0.0884520   3.562 0.000369 ***
## rankOrdLife_1None                0.1263311  0.2917888   0.433 0.665052    
## rankOrdLife_2B                   0.0739827  0.0910245   0.813 0.416353    
## rankOrdLife_2C                   0.1229902  0.1010009   1.218 0.223344    
## rankOrdLife_2D                   0.0673687  0.1073817   0.627 0.530419    
## rankOrdLife_2E                   0.2440669  0.0985034   2.478 0.013228 *  
## rankOrdLife_2F                   0.2334383  0.0898944   2.597 0.009415 ** 
## rankOrdLife_2None                       NA         NA      NA       NA    
## rankOrdLife_3B                   0.0004744  0.1034099   0.005 0.996340    
## rankOrdLife_3C                   0.1201360  0.1099514   1.093 0.274567    
## rankOrdLife_3D                   0.0089981  0.1154432   0.078 0.937873    
## rankOrdLife_3E                   0.2946544  0.1064879   2.767 0.005661 ** 
## rankOrdLife_3F                   0.2421559  0.0955087   2.535 0.011237 *  
## rankOrdLife_3None                       NA         NA      NA       NA    
## rankOrdLife_4B                   0.0182885  0.0872110   0.210 0.833900    
## rankOrdLife_4C                   0.0401502  0.0989365   0.406 0.684879    
## rankOrdLife_4D                  -0.0931742  0.1068337  -0.872 0.383138    
## rankOrdLife_4E                   0.1381153  0.0987794   1.398 0.162059    
## rankOrdLife_4F                  -0.0288749  0.0892058  -0.324 0.746176    
## rankOrdLife_4None                       NA         NA      NA       NA    
## rankOrdLife_5B                  -0.0049496  0.0869172  -0.057 0.954589    
## rankOrdLife_5C                  -0.0047829  0.0992996  -0.048 0.961584    
## rankOrdLife_5D                  -0.1504688  0.1079006  -1.395 0.163175    
## rankOrdLife_5E                   0.1170135  0.0991635   1.180 0.238009    
## rankOrdLife_5F                  -0.0524715  0.0877770  -0.598 0.549991    
## rankOrdLife_5None                       NA         NA      NA       NA    
## rankOrdLife_6B                   0.0076730  0.0875714   0.088 0.930180    
## rankOrdLife_6C                   0.0042764  0.0989731   0.043 0.965536    
## rankOrdLife_6D                  -0.1190975  0.1064397  -1.119 0.263184    
## rankOrdLife_6E                   0.1213572  0.0979196   1.239 0.215225    
## rankOrdLife_6F                  -0.0196407  0.0831317  -0.236 0.813233    
## rankOrdLife_6None                       NA         NA      NA       NA    
## c19perBeh01                      0.0363807  0.0088824   4.096 4.22e-05 ***
## c19perBeh02                      0.1616897  0.0108569  14.893  < 2e-16 ***
## c19perBeh03                      0.0950594  0.0061804  15.381  < 2e-16 ***
## c19RCA01                         0.0016619  0.0046948   0.354 0.723346    
## c19RCA02                         0.1128538  0.0073504  15.353  < 2e-16 ***
## c19RCA03                        -0.0326091  0.0049651  -6.568 5.21e-11 ***
## coronaClose_6                   -0.1432177  0.0171071  -8.372  < 2e-16 ***
## genderMale                      -0.0587263  0.1173154  -0.501 0.616667    
## genderFemale                    -0.0947026  0.1177315  -0.804 0.421176    
## genderOther                      0.1096229  0.1534998   0.714 0.475137    
## age                              0.0398695  0.0049493   8.056 8.24e-16 ***
## eduPrimary education             0.0379293  0.1288745   0.294 0.768522    
## eduGeneral secondary\neducation -0.0980370  0.1179676  -0.831 0.405953    
## eduVocational education         -0.0434845  0.1186662  -0.366 0.714037    
## eduHigher\neducation            -0.0776007  0.1169094  -0.664 0.506844    
## eduBachelors degree             -0.0611924  0.1168803  -0.524 0.600598    
## eduMasters degree               -0.0112509  0.1173805  -0.096 0.923640    
## eduPhD\ndegree                   0.0255719  0.1199991   0.213 0.831250    
## c19ProSo01                       0.0864829  0.0063072  13.712  < 2e-16 ***
## c19ProSo02                       0.0281173  0.0055490   5.067 4.07e-07 ***
## c19ProSo03                       0.2883324  0.0056416  51.109  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.21 on 26524 degrees of freedom
## Multiple R-squared:  0.3415, Adjusted R-squared:  0.3398 
## F-statistic: 202.3 on 68 and 26524 DF,  p-value: < 2.2e-16