【问题标题】:Random points in a space time时空中的随机点
【发布时间】:2018-08-28 07:29:54
【问题描述】:

我有一套日期堆肥,在路上死了几年。我的数据是坐标 x&y。我需要创建一个随机分布的数据作为对照,以便能够将我的数据与随机对照进行比较,看看是否存在死亡率热点。我知道可以用 R 创建一组随机点,但我不知道如何使两者在时间上具有可比性。我怎样才能在几年内累积这些积分?

再次感谢您

极光

【问题讨论】:

  • 一般来说,runifrexprnorm 等函数用于在 R 中构建随机数据。查看这些函数。您可以通过键入例如来获得帮助。 ?runif 在控制台中
  • 欢迎来到 SO!在这个社区中,如果您可以发布一些数据作为示例,展示您的尝试和so on,则更容易获得帮助。
  • 这里你应该使用poisson分布来生成样本数据。
  • 非常感谢!!我会尝试所有这些,然后我会回到你身边,看看我是否能做到!谢谢。

标签: r random coordinates


【解决方案1】:

要识别热点,最好使用2D kernel density estimation。请参阅下面来自data portal for the State of Washington 的道路死亡死亡率示例。使用contour plot 和kde2d 函数来识别热点。请看下面的代码:

library(lubridate)
mort <- read.csv("https://data.wa.gov/api/views/mcp7-tcwf/rows.csv?accessType=DOWNLOAD", stringsAsFactors = FALSE)

ll <- t(sapply(mort$Location, function(x) na.omit(as.numeric(unlist(strsplit(x, "\\(|\\,| |\\)"))))))
rownames(ll) <- NULL
colnames(ll) <- c("lat", "lon")
mort2 <- cbind(mort, ll)
mort2$Salvage.Date.Time2 <- mdy_hms(mort2$Salvage.Date.Time)
mort2$month <- month(mort2$Salvage.Date.Time2)
mort2$year <- year(mort2$Salvage.Date.Time2)
mort2 <- mort2[mort2$year> 2016, ]

mort3 <- mort2[with(mort2, lat > 45.5 & lat < 49.& lon > -125 & lon < -116), ]
f1 <- with(mort3, kde2d(lat, lon, n = 100))

plot(mort3$lat, mort3$lon, pch = 18, col = "lightblue")
contour(f1, levels  =  c(0.01, 0.05, 0.1, 0.2), add = TRUE, labcex = 1)

输出:

【讨论】:

    猜你喜欢
    • 2011-01-19
    • 2019-10-28
    • 2020-09-04
    • 2013-05-20
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    相关资源
    最近更新 更多