library(tidyverse)
library(car)
DATE <- c("324", "325", "326", "327", "328", "329", "330", "331", "401", "402", "403", "404", "405", "406", "407", "408", "409", "410", "411", "412")
Domestic <- c(15, 14, 21, 83, 34, 33, 56, 87, 104, 160, 183, 133, 216, 281, 382, 384, 442, 431, 439, 551)
Oversea <- c(124, 122, 82, 120, 93, 63, 107, 152, 132, 244, 97, 142, 65, 78, 149, 123, 136, 144, 191, 112)
cvdaydta <- data.frame(DATE, Domestic, Oversea)
cvdaydta$DATE <- as.factor(cvdaydta$DATE)
scatterplot(Domestic ~ Oversea, data = cvdaydta, smooth = F)

ggplot(aes(x = Oversea, y = Domestic), data = cvdaydta) +
  geom_point() +
  geom_smooth(method = lm, se = T) +
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

cvmod <- lm(Domestic ~ Oversea, data = cvdaydta)
summary(cvmod)
## 
## Call:
## lm(formula = Domestic ~ Oversea, data = cvdaydta)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -187.66 -136.95  -97.39  156.82  360.77 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)   74.210    122.743   0.605    0.553
## Oversea        1.036      0.940   1.102    0.285
## 
## Residual standard error: 174.5 on 18 degrees of freedom
## Multiple R-squared:  0.0632, Adjusted R-squared:  0.01115 
## F-statistic: 1.214 on 1 and 18 DF,  p-value: 0.285
vac <- read.csv("vaccinations.csv", h = T)
death <- read.csv("total_deaths.csv", h = T)
case <- read.csv("total_cases.csv", h = T)
world <- filter(vac, location == "World")
vd <- world %>% select(date, people_fully_vaccinated)
death <- filter(death, date >= "2020-12-02" & date <= "2022-04-11") 
case <- filter(case, date >= "2020-12-02" & date <= "2022-04-11")
vd$death <- death$World
vd$case <- case$World
vd$date <- as.factor(vd$date)
scatterplot(death ~ people_fully_vaccinated, data = vd, smooth = F)

scatterplot(case ~ people_fully_vaccinated, data = vd, smooth = F)

cv <- lm(death ~ case + people_fully_vaccinated, data = vd)
summary(cv)
## 
## Call:
## lm(formula = death ~ case + people_fully_vaccinated, data = vd)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -991498 -261989   90768  221542  634872 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             2.373e+06  5.313e+04  44.665   <2e-16 ***
## case                    3.987e-03  4.164e-04   9.576   <2e-16 ***
## people_fully_vaccinated 4.800e-04  2.746e-05  17.476   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 383000 on 482 degrees of freedom
##   (因為不存在,11 個觀察量被刪除了)
## Multiple R-squared:  0.9145, Adjusted R-squared:  0.9141 
## F-statistic:  2577 on 2 and 482 DF,  p-value: < 2.2e-16