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, 511)
Oversea <- c(124, 122, 82, 120, 93, 63, 107, 152, 132, 244, 97, 142, 65, 78, 149, 123, 136, 144, 191, 112)
covid <- data.frame(DATE, Domestic, Oversea)
scatterplot(Domestic ~ Oversea,
data = covid,
smooth = F)
#灰色範圍越小越準確
ggplot(aes(x = Oversea, y = Domestic), data = covid ) +
geom_point() +
geom_smooth(method = lm) +
theme_bw()
## `geom_smooth()` using formula 'y ~ x'
#連續變項
cvmod <- lm(Domestic ~ Oversea, data = covid)
summary(cvmod)
##
## Call:
## lm(formula = Domestic ~ Oversea, data = covid)
##
## Residuals:
## Min 1Q Median 3Q Max
## -185.66 -134.49 -95.09 158.33 322.93
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 70.5145 119.6416 0.589 0.563
## Oversea 1.0496 0.9163 1.145 0.267
##
## Residual standard error: 170.1 on 18 degrees of freedom
## Multiple R-squared: 0.06794, Adjusted R-squared: 0.01616
## F-statistic: 1.312 on 1 and 18 DF, p-value: 0.267
p-value > 0.05,無法虛無假設,且t-value與0距離1.145,不具有足夠解釋力。 R-squared = 0.01616,Domestic中只有0.01616的變異量可以被oversea預測,表示有其他factor能更有效解釋。
rain <- c(0,0.5,14.5,42,75,11.5,0,0,0,23,10.5,0,0,0,0,0,0,0,0,0)
cvrain <- data.frame(DATE, Domestic, rain)
ggplot(aes(x = rain, y = Domestic), data = cvrain ) +
geom_point() +
geom_smooth(method = lm) +
theme_bw()
## `geom_smooth()` using formula 'y ~ x'
cvRain <- lm(Domestic ~ rain, data = cvrain)
summary(cvRain)
##
## Call:
## lm(formula = Domestic ~ rain, data = cvrain)
##
## Residuals:
## Min 1Q Median 3Q Max
## -215.56 -147.28 -8.25 151.94 280.44
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 230.560 40.496 5.693 2.12e-05 ***
## rain -3.402 1.979 -1.719 0.103
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 163.3 on 18 degrees of freedom
## Multiple R-squared: 0.141, Adjusted R-squared: 0.09327
## F-statistic: 2.954 on 1 and 18 DF, p-value: 0.1028
p-value > 0.05,無法拒絕虛無假設,且t-value與0距離1.719,獨變項沒有足夠的解釋力。 R-squared = 0.09327,Domestic中只有9.327%的變異量可以被每日雨量預測,表示有其他factor能更有效解釋。
UV <- c(7,11,7,5,3,7,8,7,3,3,3,10,11,11,8,11,12,12,13,12)
cvUV <- data.frame(DATE, Domestic, UV)
ggplot(aes(x = UV, y = Domestic), data = cvUV ) +
geom_point() +
geom_smooth(method = lm) +
theme_bw()
## `geom_smooth()` using formula 'y ~ x'
cvuvlm <- lm(Domestic ~ UV, data = cvUV)
summary(cvuvlm)
##
## Call:
## lm(formula = Domestic ~ UV, data = cvUV)
##
## Residuals:
## Min 1Q Median 3Q Max
## -274.357 -125.415 -5.276 113.998 191.248
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -56.991 80.747 -0.706 0.48935
## UV 31.395 9.114 3.445 0.00289 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 136.8 on 18 degrees of freedom
## Multiple R-squared: 0.3973, Adjusted R-squared: 0.3638
## F-statistic: 11.87 on 1 and 18 DF, p-value: 0.002889
p-value < 0.05,拒絕虛無假設,且t-value與0距離3.445,獨變項有解釋力。 R-squared = 0.3638,Domestic中有36.38%的變異量可以被每日紫外線量預測。
VX <- c(76.39,76.43,76.43,76.46,76.46,76.52,76.56,76.60,76.65,76.65,76.65,76.65,76.65,76.73,76.78,76.84,76.91,76.98,77.04,77.06)
cvVX <- data.frame(DATE, Domestic, VX)
ggplot(aes(x = VX, y = Domestic), data = cvVX ) +
geom_point() +
geom_smooth(method = lm) +
theme_bw()
## `geom_smooth()` using formula 'y ~ x'
cvVXlm <- lm(Domestic ~ VX, data = cvVX)
summary(cvVXlm)
##
## Call:
## lm(formula = Domestic ~ VX, data = cvVX)
##
## Residuals:
## Min 1Q Median 3Q Max
## -78.881 -47.020 1.775 35.612 95.304
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -61027.99 4102.38 -14.88 1.48e-11 ***
## VX 798.58 53.51 14.93 1.40e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 48.17 on 18 degrees of freedom
## Multiple R-squared: 0.9252, Adjusted R-squared: 0.9211
## F-statistic: 222.8 on 1 and 18 DF, p-value: 1.402e-11
p-value < 0.05,拒絕虛無假設,且t-value與0距離14,獨變項有解釋力。 R-squared = 0.9211,Domestic中有92.11%的變異量可以被每日台灣新冠疫苗施打兩劑占總人口比率解釋。