地理探测器 GD包下载及应用(R语言,基于Rstudio)
一些碎碎念
寫(xiě)論文過(guò)程中使用地理探測(cè)器做分析,發(fā)現(xiàn)離散方法及其分級(jí)數(shù)對(duì)其結(jié)果的影響較大,同時(shí)試驗(yàn)起來(lái)體量較大,使用GD包進(jìn)行自動(dòng)化處理就顯得比較方便。
下載
網(wǎng)址及引用
相關(guān)介紹及網(wǎng)址可以到至篇論文搜一下:
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包網(wǎng)址在論文里的Acknowledgements最后,有專門(mén)的說(shuō)明文檔,貼一下原文:
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均可實(shí)現(xiàn),比較推薦Rstudio,有單獨(dú)的plot窗口。
具體安裝教程網(wǎng)上很多,就不贅述了
可以直接用,加一句,下載GD包即可
應(yīng)用實(shí)例
給的案例
基礎(chǔ)數(shù)據(jù):rda文件
用的最簡(jiǎn)單的gdm函數(shù),兩個(gè)例子大差不差,細(xì)節(jié)不一樣
例子一
例子二
discmethod <- c("equal","natural","quantile") discitv <- c(4:6) continuous_variable <- colnames(h1n1_100)[-c(1,11)] ##通過(guò)colnames函數(shù)讀取表名 -c是除了1,11行 h1n1gdm <- gdm(H1N1 ~ .,continuous_variable = continuous_variable,data = h1n1_100,discmethod = discmethod, discitv = discitv) h1n1gdm plot(h1n1gdm)數(shù)據(jù)準(zhǔn)備
數(shù)據(jù)收集
一般樣方選擇就是正方形格網(wǎng)
或者行政區(qū)范圍內(nèi)
方法一:多矢量融合,選擇自己的字段
方法二:多值提取至點(diǎn), 最好用arcgis10.5以上的Arcmap,容易閃退
刪除異常值
獲得EXCEL、txt、dbf后需要進(jìn)行處理
刪掉所有excel中的索引列、經(jīng)緯度信息列和有空值的行
轉(zhuǎn)rda文件
轉(zhuǎn)txt轉(zhuǎn)rda文件的代碼如下,其實(shí)也可以直接用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")代碼修改
主要修改自己的參數(shù)(分級(jí)方法、分級(jí)數(shù)、自己的數(shù)據(jù)、因變量自變量、連續(xù)變量),5-6個(gè)地方
library(GD) discmethod <- c("equal","natural","quantile") ###分級(jí)方法 discitv <- c(4:6) ###分級(jí)數(shù) continuous_variable <- c("Tempchange", "GDP") ###連續(xù)變量 testdata <- load("D:/001_why/R/ndvi_40.rda") ###注意這里讀取自己的rda ndvigdm <- gdm(NDVIchange ~ Climatezone + Mining + Tempchange + GDP, ###設(shè)置因變量自變量continuous_variable = continuous_variable,data = data, ###注意這里要寫(xiě)data 而不是testdatadiscmethod = discmethod, discitv = discitv) ndvigdm plot(ndvigdm)見(jiàn)到的一些錯(cuò)誤
問(wèn)題1:Error in subset.default(data, select = formula.vars[1]) : 缺少參數(shù)"subset",也沒(méi)有缺省值
我這邊就是這行的問(wèn)題,改完就可以運(yùn)行了
問(wèn)題2:有時(shí)候plot窗口太小會(huì)報(bào)錯(cuò)
擴(kuò)大一點(diǎn),或者直接導(dǎo)出即可。
參考
這個(gè)博主用xlsx文件,添加了自己的循環(huán):
https://blog.csdn.net/weixin_43416590/article/details/124784074#comments_23901821
這個(gè)用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
總結(jié)
以上是生活随笔為你收集整理的地理探测器 GD包下载及应用(R语言,基于Rstudio)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [程序员面试金典][JAVA][第02.
- 下一篇: Android-Universal-Im