Merge branch 'PUB'

* PUB:
  minor update
  第9次课
  update
This commit is contained in:
Ming Su 2024-04-02 09:11:10 +08:00
commit 7c06e29cbe
13 changed files with 160 additions and 3 deletions

View File

@ -7,18 +7,112 @@ format: html
# 下载airquality.xlsx并读取数据 # 下载airquality.xlsx并读取数据
```{r} ```{r}
#| eval: false
#| execute: false
# 下载至临时文件 # 下载至临时文件
tmpxlsxpath <- file.path(tempdir(), "airquality.xlsx") tmpxlsxpath <- file.path(tempdir(), "airquality.xlsx")
download.file("https://drwater.rcees.ac.cn/git/course/RWEP/raw/branch/PUB/data/airquality.xlsx", download.file("https://drwater.rcees.ac.cn/git/course/RWEP/raw/branch/PUB/data/airquality.xlsx",
destfile = tmpxlsxpath) destfile = tmpxlsxpath)
airqualitydf <- readxl::read_xlsx(tmpxlsxpath, sheet = 1) airqualitydf <- readxl::read_xlsx(tmpxlsxpath, sheet = 2)
metadf <- readxl::read_xlsx(tmpxlsxpath, sheet = 2) metadf <- readxl::read_xlsx(tmpxlsxpath, sheet = 1)
``` ```
# 根据`airqualitydf.xlsx`按采样点统计白天8:00-20:00与夜晚20:00-8:00中空气质量指数AQI中位数按城市统计低于所有采样点AQI30%分位值的采样点占比列出上述占比最高的10个城市不考虑采样点数低于5个的城市 # 根据`airqualitydf.xlsx`按采样点统计白天8:00-20:00与夜晚20:00-8:00中空气质量指数AQI中位数按城市统计低于所有采样点AQI30%分位值的采样点占比列出上述占比最高的10个城市不考虑采样点数低于5个的城市
```{r}
#| eval: false
#| execute: false
require(tidyverse)
airqualitydf |>
select(datetime, site, AQI) |>
filter(!is.na(AQI)) |>
group_by(site) |>
summarize(AQI.median = median(AQI, na.rm = TRUE)) |>
left_join(metadf |> select(site, city = Area)) |>
group_by(city) |>
filter(n() > 5) |>
summarize(p = sum(AQI.median < quantile(airqualitydf$AQI, probs = 0.5, na.rm = TRUE)) / n()) |>
top_n(10, p)
airqualitydf |>
select(datetime, site, AQI) |>
filter(!is.na(AQI)) |>
group_by(site) |>
summarize(AQI.median = median(AQI, na.rm = TRUE))
airqualitydf |>
select(datetime, site, AQI) |>
filter(!is.na(AQI)) |>
left_join(metadf |> select(site, city = Area)) |>
group_by(city) |>
filter(length(unique(site)) >= 5) |>
summarize(p = sum(AQI < quantile(airqualitydf$AQI, probs = 0.2,
na.rm = TRUE)) / n()) |>
slice_max(p, n = 10)
```
# 按照不同城市分组统计白天与夜晚AQI中位数是否具有显著差异。 # 按照不同城市分组统计白天与夜晚AQI中位数是否具有显著差异。
```{r}
#| eval: false
if (FALSE) {
require(infer)
testdf <- airqualitydf |>
select(datetime, site, AQI) |>
filter(!is.na(AQI)) |>
left_join(metadf |> select(site, city = Area)) |>
group_by(city) |>
filter(length(unique(site)) >= 5) |>
mutate(dayornight = factor(ifelse(between(hour(datetime), 8, 20), "day", "night"),
levels = c("day", "night"))
) |>
group_by(city) |>
nest(citydf = -city) |>
mutate(median_diff = purrr::map_dbl(citydf, ~
.x |>
specify(AQI ~ dayornight) |>
calculate(stat = "diff in medians", order = c("day", "night")) |>
pull(stat)
)) |>
ungroup() |>
# slice_sample(n = 12) |>
mutate(null_dist = purrr::map(citydf, ~
.x |>
specify(AQI ~ dayornight) |>
hypothesize(null = "independence") |>
generate(reps = 1000, type = "permute") |>
calculate(stat = "diff in medians", order = c("day", "night"))
)) |>
mutate(fig = purrr::pmap(list(null_dist, median_diff, city),
~ visualize(..1) +
shade_p_value(obs_stat = ..2, direction = "both") +
ggtitle(..3)
)) |>
mutate(p_value = purrr::map2_dbl(null_dist, median_diff,
~ get_p_value(.x, obs_stat = .y, direction = "both") |>
pull(p_value)
)) |>
arrange(p_value) |>
mutate(sigdiff = ifelse(p_value < 0.01, "显著差异", "无显著差异"))
testdf |>
select(city, sigdiff) |>
knitr::kable()
lang <- "cn"
(testdf |>
slice_sample(n = 9) |>
pull(fig)) |>
patchwork::wrap_plots(ncol = 3) +
dwfun::theme_sci(5, 5)
dwfun::ggsavep("./testdf.pdf")
}
```

View File

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -97,3 +97,8 @@ geom_bar(position = "fill")
## 综合实践:三维荧光数据处理 ## 综合实践:三维荧光数据处理
## 欢迎讨论!{.center}
`r rmdify::slideend(wechat = FALSE, type = "public", tel = FALSE, thislink = "https://drwater.rcees.ac.cn/course/public/RWEP/@PUB/SD/")`

View File

@ -0,0 +1 @@
../../_extensions

View File

@ -0,0 +1,49 @@
---
title: "课后作业9"
subtitle: 《区域水环境污染数据分析实践》<br>Data analysis practice of regional water environment pollution
author: 苏命、王为东<br>中国科学院大学资源与环境学院<br>中国科学院生态环境研究中心
date: today
lang: zh
format:
revealjs:
theme: dark
slide-number: true
chalkboard:
buttons: true
preview-links: auto
lang: zh
toc: true
toc-depth: 1
toc-title: 大纲
logo: ./_extensions/inst/img/ucaslogo.png
css: ./_extensions/inst/css/revealjs.css
pointer:
key: "p"
color: "#32cd32"
pointerSize: 18
revealjs-plugins:
- pointer
filters:
- d2
---
```{r}
#| include: false
#| cache: false
lang <- "cn"
require(tidyverse)
require(learnr)
```
## 第9次课后作业
自选数据集使用R语言开展不同因子如年份、季节、处理方式等间某指标的差异分析采用图表方式形成简要报告。
作业模板:[第9次课后作业_模板.qmd](https://drwater.rcees.ac.cn/git/course/RWEP/raw/branch/main/SD/20240402_9_课后作业/第9次课后作业_模板.qmd)
## 欢迎讨论!{.center}
`r rmdify::slideend(wechat = FALSE, type = "public", tel = FALSE, thislink = "https://drwater.rcees.ac.cn/course/public/RWEP/@PUB/SD/")`

View File

@ -0,0 +1,8 @@
---
title: 课后作业9
author: 姓名
format: html
---
要求自选数据集使用R语言开展不同因子间如年份、季节、处理方式等某指标的差异分析采用图表+文字说明等方式形成简要报告。

Binary file not shown.

View File

@ -19,4 +19,4 @@ subtitle: "课程简介"
- 网页公开:[https://drwater.rcees.ac.cn/course/public/RWEP/\@PUB/index.html](https://drwater.rcees.ac.cn/course/public/RWEP/@PUB/index.html) - 网页公开:[https://drwater.rcees.ac.cn/course/public/RWEP/\@PUB/index.html](https://drwater.rcees.ac.cn/course/public/RWEP/@PUB/index.html)
- 课件代码:[https://drwater.rcees.ac.cn/git/course/RWEP.git](https://drwater.rcees.ac.cn/git/course/RWEP.git) - 课件代码:[https://drwater.rcees.ac.cn/git/course/RWEP.git](https://drwater.rcees.ac.cn/git/course/RWEP.git)
- 代码web界面[https://on.tty-share.com/s/KHxahtDKk7EIIMFFA60dQfh4-YgnWkkXRjzkaFV_7pSj96kDw_VxTC6Qa76UpG4Yee8/](https://on.tty-share.com/s/KHxahtDKk7EIIMFFA60dQfh4-YgnWkkXRjzkaFV_7pSj96kDw_VxTC6Qa76UpG4Yee8/) - 代码web界面[https://on.tty-share.com/s/2YElKFjzniilfg3vH-d1PUqqmz_MQzNki5dyxWWL7QONCX_77GzsdP9EEAgBQu3ONwM/](https://on.tty-share.com/s/2YElKFjzniilfg3vH-d1PUqqmz_MQzNki5dyxWWL7QONCX_77GzsdP9EEAgBQu3ONwM/)