【问题标题】:How to create a bootstrap sample with certain properties?如何创建具有某些属性的引导示例?
【发布时间】:2015-02-15 08:19:30
【问题描述】:

我有一些天气变量的经纬度每日数据,例如 maxT 和 minT。我希望从这些数据中重新采样,这样如果选择一天的纬度/经度作为样本,则该纬度/经度(邻居)300 公里内的所有纬度/经度也应该是样本的一部分.我不知道该怎么做。到目前为止,我已经使用 spdep 包中的命令 dnearneigh 来识别每个纬度/经度 300 公里内的纬度/经度。

提前感谢您的帮助。这是我的示例数据和 R 代码。

dput(head(rad_aod_temp_daily,1))

structure(list(latitude = 23L, longitude = 68L, year = 2000L, 
month = 11L, day = 21L, xygrid_id = 632L, solar_rad = 2.070422, 
aod = 0.27, day_of_season = 1L, cntry = structure(1L, .Label = "India", class = "factor"), 
state = structure(2L, .Label = c("Bihar", "Gujarat", "Haryana", 
"Madhya Pradesh", "Maharashtra", "Punjab", "Rajasthan", "Uttar Pradesh"
), class = "factor"), log_sr = 0.7277523, time = 1L, time2 = 1L, 
date = structure(1275L, .Label = c("01-Apr-01", "01-Apr-02", 
"01-Apr-03", "01-Apr-04", "01-Apr-05", "01-Apr-06", "01-Apr-07", 
"01-Apr-08", "01-Apr-09", "01-Apr-10", "01-Apr-11", "01-Apr-12", 
"01-Apr-13", "01-Dec-00", "01-Dec-01", "01-Dec-02", "01-Dec-03", 
"01-Dec-04", "01-Dec-05", "01-Dec-06", "01-Dec-07", "01-Dec-08", 
"01-Dec-09", "01-Dec-10",class = "factor"), maxt = 31.22, mint = 16.11, 
meant = 23.67), .Names = c("latitude", "longitude", "year", 
"month", "day", "xygrid_id", "solar_rad", "aod", "day_of_season", 
"cntry", "state", "log_sr", "time", "time2", "date", "maxt", 
"mint", "meant"), row.names = 1L, class = "data.frame")

library(spdep)
coords <- as.matrix(cbind(rad_aod_temp_daily$longitude,rad_aod_temp_daily$latitude))
nlist <- dnearneigh(coords, d1=0,d2=300,longlat=TRUE)

【问题讨论】:

    标签: r spatial statistics-bootstrap


    【解决方案1】:

    确定符合条件的案例后,创建一个新数据框并引导该数据框。

    #create data frame
    X1=rnorm(1000,0,1)
    X2=rnorm(1000,0,1)
    df=cbind(X1,X2)
    #create indicator to bootstrap
    df$indicator=ifelse(X1>.75,1,0) #I select only cases greater than .75 on X1
    df.new=df[df$indicator==1,]
    

    在您创建 df.new boostrap 后这些数据。

    【讨论】:

      猜你喜欢
      • 2018-09-17
      • 2021-11-18
      • 1970-01-01
      • 2015-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-30
      相关资源
      最近更新 更多