alex_bn_lee

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

统计

【814】Static hotspot analysis and emerging hotspot analysis based on the R library of sfdep

Ref: Emerging Hot Spot Analysis

Ref:

Ref:


Static hotspot analysis

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
library (tidyverse)
library (sf)
library (openxlsx)
library (ggplot2)
library (tmap)
tmap_mode ( "view" )
library (sfhotspot)
 
# Set default work directory
setwd ( "/Users/libingnan/Documents/09-Samsung/12-Polygon-based emerging hotspot analysis" )
 
hist <-  read.xlsx ( "epiwatch_monkeypox.xlsx" ) %>%
  mutate (PubDate   =  as.Date (`insert-timestamp`, origin =  "1899-12-30" )) %>%
  # filter(PubDate >= as.Date("2020-01-01")) %>%
  mutate (Longitude =  as.numeric (long),
         Latitude  =  as.numeric (lat)) %>%
  drop_na (Longitude, Latitude) %>%
  # filter(diseases == "covid19") %>%
  # line below removes diseases with less than 5 occurrences
  # group_by(diseases) %>% filter(n() >=5) %>% ungroup() %>%
  #drop_na(diseases) %>%
  st_as_sf (coords =  c ( "Longitude" "Latitude" ), crs = 4326) %>%
  st_transform (3857)
 
results <-  hotspot_classify (data = hist,
                            time = PubDate,
                            period =  "1 week" ,
                            cell_size = 500000,  # 500 km
                            #cell_size = 200000, # 200 km
                            quiet = F,
                            params =  hotspot_classify_params (
                              nb_dist = 0.1)  # default is to use points outside of cell.
                            # changed to minimum distance to reduce confusion
)
 
 
#autoplot(results)
 
tm_shape (results, name =  "Hotspot Detection" ) +
  tm_polygons ( "hotspot_category" , title =  "Hotspot Category" ,
              palette =  c ( "persistent hotspot" "red" ,
                          "emerging hotspot" "orange" ,
                          "intermittent hotspot" "yellow" ,
                          "former hotspot" "darkgreen" ,
                          "no pattern" NA ),
              alpha = 0.7, lwd = 0.8) +
  
  tm_shape (hist, name =  "Reports" ) +
  tm_dots (jitter=0.1)

结果显示:

Emerging hotspot analysis

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
library (tidyverse)
library (sf)
library (openxlsx)
library (ggplot2)
library (tmap)
tmap_mode ( "view" )
library (sfhotspot)
library (sfdep)
library (dplyr)
 
# get directories of files
df_fp <-  system.file ( "extdata" "bos-ecometric.csv" , package =  "sfdep" )
geo_fp <-  system.file ( "extdata" "bos-ecometric.geojson" , package =  "sfdep" )
 
# read in data
df <- readr:: read_csv (df_fp, col_types =  "ccidD" )
 
geo <- sf:: read_sf (geo_fp)
 
# Create spacetime object called `bos`
bos <-  spacetime (df, geo,
                 .loc_col =  ".region_id" ,
                 .time_col =  "time_period" )
 
# conduct EHSA
ehsa <-  emerging_hotspot_analysis (
  x = bos,
  .var =  "value" ,
  k = 1,
  nsim = 9
)
 
# should put geo in the first place, otherwise it will triger the projection error
geo_ehsa <-  merge (geo, ehsa, by.x= ".region_id" , by.y= "location" )
 
# tm_shape: Specify the shape object
# tm_polygons: Draw polygons
# "clssification" is a column of hotspot_results
 
tm_shape (geo_ehsa, name =  "Hotspot Detection" ) +
  tm_polygons ( "classification" , title =  "Hotspot Category" ,
              palette =  c ( "no pattern detected" "#4576b5" ),
              alpha = 0.7, lwd = 0.8)

结果显示: 

 

posted on   McDelfino  阅读(31)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2012-03-10 【020】在 VS2010 中添加配置文件
2012-03-10 【019】SQL 基础学习
点击右上角即可分享
微信分享提示