if (requireNamespace("spdep")) {
  data("measles.weser")
  measles <- disProg2sts(measles.weser)
  ## parametric powerlaw weights require neighbourhood orders in the data
  neighbourhood(measles) <- nbOrder(neighbourhood(measles), maxlag=Inf)
  ## a simple hhh4 model with power-law decay of spatial interaction
  m <- list(ar = list(f = ~ 1),
            ne = list(f = ~ 1, weights = powerlaw(maxlag=4, log=FALSE)),
            end = list(f = addSeason2formula(~-1 + ri(), S=1, period=52),
                       offset = population(measles)),
            family = "NegBin1", verbose=TRUE)
  ## fit the model
  set.seed(1)  # random intercepts are initialized randomly
  fit <- hhh4(measles, m)
  summary(fit)  # "neweights.d" is the decay parameter
}Run the code above in your browser using DataLab