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)
Hsinchu <- c(1, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 7, 8, 4, 5, 3, 6, 10, 10, 8)
#將Domestic、Hsinchu和Oversea存入cvdta
cvdta <- data.frame(DATE, Domestic, Oversea, Hsinchu)
#將DATE轉為類別變項
cvdta$DATE <- as.factor(cvdta$DATE)
#繪製Domestic和Oversea的相關圖
scatterplot(Oversea ~ Domestic,
data = cvdta,
smooth = F)
#繪製Domestic和Oversea的相關圖
ggplot(aes(x = Domestic, y = Oversea), data = cvdta) +
geom_point() +
geom_smooth(method = lm, se = T) +
theme_bw()
## `geom_smooth()` using formula 'y ~ x'
從2個圖中可以看見國外病例和本土病例的增加趨勢呈現正相關,但整體落點是分散的
#散佈圖 加上模型預測區域
cvLM <- lm(Oversea ~ Domestic, data = cvdta)
summary(cvLM)
##
## Call:
## lm(formula = Oversea ~ Domestic, data = cvdta)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.627 -26.893 0.536 14.216 122.790
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 111.44894 14.67281 7.596 5.09e-07 ***
## Domestic 0.06101 0.05536 1.102 0.285
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 42.35 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
虛無假設:Oversea變異數=Domestic變異數
對立假設:Oversea變異數≠Domestic變異數
R-squared數值為0.01115,預測解釋力低,且p-value未達顯著水準,因此可以推論Domestic的數值無法有效預測Oversea。
#繪製Domestic和Hsinchu的相關圖
scatterplot(Hsinchu ~ Domestic,
data = cvdta,
smooth = F)
#繪製Domestic和Hsinchu的相關圖
ggplot(aes(x = Domestic, y = Hsinchu), data = cvdta) +
geom_point() +
geom_smooth(method = lm, se = T) +
theme_bw()
## `geom_smooth()` using formula 'y ~ x'
從2個圖中可以看見新竹病例和本土病例的增加趨勢呈現正相關,且整體收斂程度比國外病例好,可以預期本土病例與新竹病例之間的相關比本土病例對國外更高。
#散佈圖 加上模型預測區域
cvLM2 <- lm(Hsinchu ~ Domestic, data = cvdta)
summary(cvLM2)
##
## Call:
## lm(formula = Hsinchu ~ Domestic, data = cvdta)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.4228 -1.2456 -0.6188 0.5938 4.1342
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.98106 0.70760 1.386 0.183
## Domestic 0.01417 0.00267 5.308 4.79e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.042 on 18 degrees of freedom
## Multiple R-squared: 0.6101, Adjusted R-squared: 0.5885
## F-statistic: 28.17 on 1 and 18 DF, p-value: 4.794e-05
虛無假設:Hsinchu變異數=Domestic變異數
對立假設:Hsinchu變異數≠Domestic變異數
R-squared數值為0.5885,預測解釋力比對國外病例高,且p-value達顯著水準,因此可以推論Domestic的數值或許更能有效預測Hsinchu的病例增長趨勢。