資料來源:
-https://www.ris.gov.tw/app/portal/346
-https://airtw.epa.gov.tw/CHT/Query/His_Data.aspx
-https://data.gov.tw/dataset/6399
使用到的檔案:
https://drive.google.com/drive/folders/13AjnRjaWTWI67ZjU4HW2H5FYmmyG_oCT?usp=share_link
將檔案輸入
drive_download("File_17848.csv", type = "csv",
overwrite = TRUE)
drive_download("人口.csv", type = "csv",
overwrite = TRUE)
drive_download("空汙.csv", type = "csv",
overwrite = TRUE)
df <- read_csv("File_17848.csv")
people <- read_csv("人口.csv")
airp <- read_csv("空汙.csv")
將人口與空污的資料整理成與癌症數據相同格式
people <- pivot_longer(people, cols = 2:7,
names_to = "癌症診斷年",
values_to = "number") |>
rename("縣市別" = "...1") |>
mutate(癌症診斷年 = as.numeric(癌症診斷年))
airp <- pivot_longer(airp, cols = 2:7,
names_to = "癌症診斷年",
values_to = "airpollution_factor") |>
rename("縣市別" = "...1") |>
mutate(癌症診斷年 = as.numeric(癌症診斷年))
將癌症資料中感興趣的部分即肺癌相關數據儲存為df_01,與人口及空污合併後存為df_02
df_01 <- filter(df, 縣市別 != "全國",
癌症別 == "肺、支氣管及氣管",
性別 == "全")
df_02 <- inner_join(df_01, people) |>
inner_join(airp)
glimpse(df_01)
## Rows: 891
## Columns: 9
## $ 癌症診斷年 <dbl> 1979, 1979, 1979…
## $ 性別 <chr> "全", "全", "全"…
## $ 縣市別 <chr> "台北市", "台中…
## $ 癌症別 <chr> "肺、支氣管及氣…
## $ `年齡標準化發生率 WHO 2000世界標準人口 (每10萬人口)` <dbl> 23.45, 8.24, 6.4…
## $ 癌症發生數 <dbl> 356, 85, 75, 76,…
## $ 平均年齡 <dbl> 59.3, 55.4, 56.2…
## $ 年齡中位數 <dbl> 60.0, 57.0, 59.0…
## $ `粗率 (每10萬人口)` <dbl> 16.21, 5.45, 4.9…
glimpse(df_02)
## Rows: 132
## Columns: 11
## $ 癌症診斷年 <dbl> 2014, 2014, 2014…
## $ 性別 <chr> "全", "全", "全"…
## $ 縣市別 <chr> "台北市", "台中…
## $ 癌症別 <chr> "肺、支氣管及氣…
## $ `年齡標準化發生率 WHO 2000世界標準人口 (每10萬人口)` <dbl> 34.52, 34.31, 36…
## $ 癌症發生數 <dbl> 1575, 1229, 1071…
## $ 平均年齡 <dbl> 68.0, 66.3, 67.2…
## $ 年齡中位數 <dbl> 69.0, 66.0, 69.0…
## $ `粗率 (每10萬人口)` <dbl> 58.28, 45.19, 56…
## $ number <dbl> 2702315, 2719835…
## $ airpollution_factor <dbl> 65, 81, 88, 96, …
了解各縣市肺癌的分布情形
ggplot(df_01, aes(x = 縣市別, y = 癌症發生數,
fill = as.factor(癌症診斷年))) +
geom_col(position = "dodge") +
ggtitle("全台灣肺癌各縣市逐年確診數") +
theme(legend.title=element_blank(),
axis.text.x = element_text(angle = 45))
若只關注新北市的數據會有較明確認識
ggplot(filter(df_01, 縣市別 == "新北市"),
aes(x = 癌症診斷年, y = 癌症發生數)) +
geom_col(fill = "lightblue") +
ggtitle("肺癌新北市逐年確診數")
發現人口數會大大的影響確診率因此使用人口比例進行討論較為合適
df_02 <- mutate(df_02,
"比例" = 癌症發生數 / number * 10000)
ggplot(df_02, aes(x = reorder(縣市別, 比例), y = 比例)) +
geom_col(fill = "lightblue") +
labs(title = "各縣市肺癌盛行率",
subtitle = "(每萬人)",
x = "縣市別") +
theme(axis.text.x = element_text(angle = 45))
嘗試討論空氣品質標與罹患肺癌人口數的關係
發現相關性不高因此嘗試以不同角度去分析
-按年份分群
-按縣市分群
除少數縣市外(連江)皆得到相似的結果
ggplot(df_02, aes(x = airpollution_factor, y = 比例)) +
geom_point(size = 3, aes(color = 縣市別)) +
labs(title = "空氣品質指標對罹患肺癌比率作圖",
x = "空氣品質指標",
y = "比例(每萬人)") +
theme(text = element_text(size = 20)) +
geom_smooth(method = "lm")
ggplot(df_02, aes(x = airpollution_factor, y = 比例)) +
facet_wrap(vars(縣市別)) +
geom_point(size = 1) +
geom_smooth(method = "lm") +
labs(title = "空氣品質指標對罹患肺癌比率作圖",
subtitle = "各縣市",
x = "空氣品質指標",
y = "比例(每萬人)")
ggplot(df_02, aes(x = airpollution_factor, y = 比例)) +
facet_wrap(vars(癌症診斷年)) +
geom_point(size = 1) +
geom_smooth(method = "lm") +
labs(title = "空氣品質指標對罹患肺癌比率作圖",
subtitle = "各年分",
x = "空氣品質指標",
y = "比例(每萬人)")
利用線性回歸模型進一步確認
airp_lm <- lm(airpollution_factor ~ 比例, data = df_02)
summary(airp_lm)
##
## Call:
## lm(formula = airpollution_factor ~ 比例, data = df_02)
##
## Residuals:
## Min 1Q Median 3Q Max
## -32.600 -9.535 1.310 11.542 28.070
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 80.4942 5.7360 14.033 <2e-16 ***
## 比例 -2.1945 0.9246 -2.374 0.0191 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.64 on 130 degrees of freedom
## Multiple R-squared: 0.04154, Adjusted R-squared: 0.03416
## F-statistic: 5.634 on 1 and 130 DF, p-value: 0.01908