tests/testthat/test.bandwith_option.R

# Context("Bandwith option: Version avec pseudo-CV / fixed bw")

library(testthat)

test_that("Bandwith option: Version avec pseudo-CV / adaptive bw", {
  Produc <- readRDS(system.file("Produc.rds", package = "gwpr"))
  USStates <- readRDS(system.file("USStates.rds", package = "gwpr"))

  USStates@data$id <- c(1:length(unique(USStates@data[,"state"])))
  data <- merge(USStates@data, Produc, by="state", all=T)

  dMat <- GWmodel::gw.dist(sp::coordinates(USStates), p=2, longlat=F)
  Equation <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp

  bwCV.A <-  bw.CV.A(formula=Equation, data=data, index=c("id","year"),
                     effect='individual', model="within", kernel="bisquare",
                     dMat=dMat, bws=c(30:40))

  expect_equal(bwCV.A, 34)
})

test_that("Bandwith option: Version avec pseudo-CV / fixed bw", {
  Produc <- readRDS(system.file("Produc.rds", package = "gwpr"))
  USStates <- readRDS(system.file("USStates.rds", package = "gwpr"))

  USStates@data$id <- c(1:length(unique(USStates@data[,"state"])))
  data <- merge(USStates@data, Produc, by="state", all=T)

  dMat <- GWmodel::gw.dist(sp::coordinates(USStates), p=2, longlat=F)
  Equation <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp

  ## fixed bw
  bwCV.F <-  bw.CV.F(formula=Equation, data=data, index=c("id","year"),
                     effect='individual', model="within",
                     kernel="bisquare", dMat=dMat, interval=c(1500000, 2500000))

  expect_equal(bwCV.F, 2038054.18356155, tolerance=1e-3)
})
LAEQ/gwpr documentation built on June 28, 2020, 8:23 p.m.