-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_jointpoint.Rmd
87 lines (67 loc) · 1.98 KB
/
06_jointpoint.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Joinpoint 联结点回归模型
```{r setup, include=FALSE}
options(digits = 4,
dplyr.print_min = 6,
dplyr.print_max = 6,
htmltools.dir.version = FALSE,
formatR.indent = 2,
width = 55
)
knitr::opts_chunk$set(
echo = TRUE,
warning = FALSE,
message = FALSE,
fig.width = 6,
fig.height = 4,
fig.showtext = TRUE
)
library(tidyverse)
library(ggplot2)
library(readxl)
library(showtext)
library(sf)
```
## 实战-数据处理
```{r eval=FALSE}
# 读取并查看数据
df <- read.csv("data/Global_HIV.csv",header = T)
colnames(df)
unique(df$measure)
unique(df$location)
unique(df$sex)
unique(df$age)
unique(df$cause)
unique(df$metric)
unique(df$year)
```
```{r eval=FALSE}
# 筛选数据:
number <- df |>
filter(cause%in%c("HIV/AIDS","Syphilis","Chlamydial infection",
"Gonococcal infection","Trichomoniasis",
"Genital herpes")) |>
filter(age=="All ages") |>
filter(metric=="Number") |>
filter(measure=="Incidence") |>
mutate(val=round(val,0), #将数据变为整数
upper=round(upper,0),
lower=round(lower,0)) |>
arrange(cause,sex,year) #重排序,非常重要
ASR <- df |>
filter(cause%in%c("HIV/AIDS","Syphilis","Chlamydial infection",
"Gonococcal infection","Trichomoniasis",
"Genital herpes")) |>
filter(age=="Age-standardized") |>
filter(measure=="Incidence") |>
filter(metric=="Rate") |>
mutate(se=(upper-lower)/(2*1.96)) |> #生成se
arrange(cause,sex,year) #重排序,非常重要
```
```{r eval=FALSE}
# 写出数据
write.csv(number,"data/number.csv",row.names = F)
write.csv(ASR,"data/ASR.csv",row.names = F)
```
```{r intro-ds-1, out.width = '90%', fig.align='center', echo = FALSE}
knitr::include_graphics("images/050z.png", dpi = 300)
```