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)
#create a dataframe with those vectors and assign it to an object
cvdta <- data.frame(DATE, Domestic, Oversea)
cvdta$DATE <- as.factor(cvdta$DATE)
library(tidyverse)
library(car)
scatterplot(Domestic ~ Oversea, 
            data = cvdta, 
            smooth = F)

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

# Fitting the simple linear regression model

cvmod <- lm(Domestic ~ Oversea, data = cvdta)
summary(cvmod)
## 
## Call:
## lm(formula = Domestic ~ Oversea, data = cvdta)
## 
## 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

H0=海外新增案例和本土新增案例之間無相關

H1=海外新增案例和本土新增案例之間有相關

由於T值小於2(T=1.102<2),則表示海外案例和本土案例的平均數差異不顯著,則兩者之間的相關不顯著。 故無法推翻虛無假設,表示海外新增案例和本土新增案例之間無相關。

H0=海外新增案例可以有效預測本土新增案例

H1=海外新增案例無法預測本土新增案例

由於P值大於0.05(P=0.285>0.05),則表示推翻虛無假設的犯錯機率偏高,故無法推翻虛無假設,則表示海外新增案例無法預測本土新增案例。

再以相關的方式來檢測資料

aov(Domestic ~ Oversea, data = cvdta)
## Call:
##    aov(formula = Domestic ~ Oversea, data = cvdta)
## 
## Terms:
##                  Oversea Residuals
## Sum of Squares   36970.7  548048.2
## Deg. of Freedom        1        18
## 
## Residual standard error: 174.491
## Estimated effects may be unbalanced
summary(aov(Domestic ~ Oversea, data = cvdta))
##             Df Sum Sq Mean Sq F value Pr(>F)
## Oversea      1  36971   36971   1.214  0.285
## Residuals   18 548048   30447

得到同樣的結果(P=0.285>0.05)

觀察溫度對總新增案例的預測程度

Temperature <- c(21, 28, 25, 17, 18, 24, 26, 23, 17, 15, 17, 21, 26, 26, 23, 24
                 , 28, 30, 29, 31)
Total <- c(139, 136, 103, 203, 127, 96, 163, 239, 235, 404, 280, 275, 278, 359
           , 531, 507, 573, 574, 630, 663)
scatterplot(Total ~ Temperature, 
            data = cvdta, 
            smooth = F)

ggplot(aes(x = Temperature, y = Total), data = cvdta) +
  geom_point() +
  geom_smooth(method = lm, se = T) +
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

cvmod2 <- lm(Total ~ Temperature, data = cvdta)
summary(cvmod2)
## 
## Call:
## lm(formula = Total ~ Temperature, data = cvdta)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -272.997 -109.759   -5.333  165.799  232.851 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  -103.29     199.63  -0.517   0.6112  
## Temperature    18.30       8.35   2.191   0.0418 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 173.7 on 18 degrees of freedom
## Multiple R-squared:  0.2106, Adjusted R-squared:  0.1667 
## F-statistic: 4.801 on 1 and 18 DF,  p-value: 0.04185

H0=溫度可以預測每日新增總案例

H1=溫度無法預測每日新增總案例

由於P值小於0.05(P=0.0418<0.05),則表示推翻虛無假設的犯錯機率偏低,故推翻虛無假設,則表示溫度可以預測每日新增總案例。