地理探测器 GD包下载及应用(R语言,基于Rstudio)
一些碎碎念
寫論文過程中使用地理探測器做分析,發現離散方法及其分級數對其結果的影響較大,同時試驗起來體量較大,使用GD包進行自動化處理就顯得比較方便。
下載
網址及引用
相關介紹及網址可以到至篇論文搜一下:
Yongze Song, Jinfeng Wang, Yong Ge & Chengdong Xu (2020) An optimal
parameters-based geographical detector model enhances geographic characteristics of explanatory
variables for spatial heterogeneity analysis: cases with different types of spatial data, GIScience &
Remote Sensing, 57:5, 593-610, DOI: 10.1080/15481603.2020.1760434
GD包網址在論文里的Acknowledgements最后,有專門的說明文檔,貼一下原文:
The authors wish to thank the R community for the efforts during releasing the package. The R package, its manual and all case datasets are available at https://cran.r-project.org/web/packages/GD/.
R編譯器
visual studio code 、pycharm及Rstudio均可實現,比較推薦Rstudio,有單獨的plot窗口。
具體安裝教程網上很多,就不贅述了
可以直接用,加一句,下載GD包即可
應用實例
給的案例
基礎數據:rda文件
用的最簡單的gdm函數,兩個例子大差不差,細節不一樣
例子一
例子二
discmethod <- c("equal","natural","quantile") discitv <- c(4:6) continuous_variable <- colnames(h1n1_100)[-c(1,11)] ##通過colnames函數讀取表名 -c是除了1,11行 h1n1gdm <- gdm(H1N1 ~ .,continuous_variable = continuous_variable,data = h1n1_100,discmethod = discmethod, discitv = discitv) h1n1gdm plot(h1n1gdm)數據準備
數據收集
一般樣方選擇就是正方形格網
或者行政區范圍內
方法一:多矢量融合,選擇自己的字段
方法二:多值提取至點, 最好用arcgis10.5以上的Arcmap,容易閃退
刪除異常值
獲得EXCEL、txt、dbf后需要進行處理
刪掉所有excel中的索引列、經緯度信息列和有空值的行
轉rda文件
轉txt轉rda文件的代碼如下,其實也可以直接用xls文件、csv文件。
data = read.table("D:/001_why/qxsj/data_1030/txt/12_2.txt",header=T,na.strings = c("NA")) save(data, file = "D:/001_why/qxsj/data_1030/rda/12_2.rda")代碼修改
主要修改自己的參數(分級方法、分級數、自己的數據、因變量自變量、連續變量),5-6個地方
library(GD) discmethod <- c("equal","natural","quantile") ###分級方法 discitv <- c(4:6) ###分級數 continuous_variable <- c("Tempchange", "GDP") ###連續變量 testdata <- load("D:/001_why/R/ndvi_40.rda") ###注意這里讀取自己的rda ndvigdm <- gdm(NDVIchange ~ Climatezone + Mining + Tempchange + GDP, ###設置因變量自變量continuous_variable = continuous_variable,data = data, ###注意這里要寫data 而不是testdatadiscmethod = discmethod, discitv = discitv) ndvigdm plot(ndvigdm)見到的一些錯誤
問題1:Error in subset.default(data, select = formula.vars[1]) : 缺少參數"subset",也沒有缺省值
我這邊就是這行的問題,改完就可以運行了
問題2:有時候plot窗口太小會報錯
擴大一點,或者直接導出即可。
參考
這個博主用xlsx文件,添加了自己的循環:
https://blog.csdn.net/weixin_43416590/article/details/124784074#comments_23901821
這個用csv文件
https://blog.csdn.net/weixin_41608080/article/details/114048972?ops_request_misc=&request_id=&biz_id=102&utm_term=%E5%9C%B0%E7%90%86%E6%8E%A2%E6%B5%8B%E5%99%A8%20GD%E5%8C%85&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-3-114048972.142v62pc_search_tree,201v3control,213v1t3_esquery_v3&spm=1018.2226.3001.4187
最主要的就是GD包的作者:
Yongze Song, Jinfeng Wang, Yong Ge & Chengdong Xu (2020) An optimal
parameters-based geographical detector model enhances geographic characteristics of explanatory
variables for spatial heterogeneity analysis: cases with different types of spatial data, GIScience &
Remote Sensing, 57:5, 593-610, DOI: 10.1080/15481603.2020.1760434
總結
以上是生活随笔為你收集整理的地理探测器 GD包下载及应用(R语言,基于Rstudio)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [程序员面试金典][JAVA][第02.
- 下一篇: Android-Universal-Im