0
$\begingroup$

I want to perform a spatio-temporal analysis by highlighting spatial as well as temporal dependencies of the data (I have a 'weight matrix' highlighting spatial dependencies of the counties) on the dengue cases in India 'india_states_data' (from 1990 to 2019) and I have data for 30 counties.

> dput(head(india_states_data[, c(1, 3)]))
structure(list(Year = 1990:1995, Arunachal.Pradesh = c(43.79769245, 
42.90789583, 42.28709458, 41.92135401, 41.79549369, 41.89042979
)), row.names = c(NA, 6L), class = "data.frame")

> dput(head(weight_matrix[, c(1, 3)]))
structure(c(0, 0.000209253, 0.000100017, 0.000598749, 0.0068957, 
0.000496679, 0.001596943, 0.018993939, 0, 0.002587399, 0.002846017, 
0.000626505), dim = c(6L, 2L), dimnames = list(NULL, c("Andhra.Pradesh", 
"Assam")))

I need to get the best p(lags) and d(order of differencing) parameters. But the code gives error for d>0.

I tried this code to search for best p and d values for my model

library(gstar)
library(xts)

india_states_data <- read.csv("/Users/shashankgupta/Desktop/Bombay/DenDataInd.csv")

cases_data <- india_states_data[, -1] 

india_states_data_xts <- xts(as.matrix(cases_data), order.by = as.Date(paste0(india_states_data$Year, "-07-01")))
colnames(india_states_data_xts) <- india_states_data$State_Name
nrow(x_train)==length(orde)
weight_matrix <- as.matrix(read.csv("/Users/shashankgupta/Desktop/Bombay/weight_matrix.csv"))
dim(weight_matrix)

s <- round(nrow(india_states_data_xts) * 0.8)
x_train <- india_states_data_xts[1:s, ]
x_test <- india_states_data_xts[-c(1:s), ]

length(index(india_states_data_xts))
nrow(x_train)
for (p in 0:4) {
  for (d in 0:2) {
    tryCatch({
      fit <- gstar(x_train, weight = weight_matrix, p = p, d = d, est = "OLS")
      print(paste("Model for p =", p, "and d =", d, "fit successfully."))
    }, error = function(e) {
      print(paste("Error for p =", p, "and d =", d, ": ", e$message))
    })
  }
}

I was expecting the model to fit for all p and d values.

But the output:

[1] "Error for p = 0 and d = 0 :  attempt to select less than one element in integerOneIndex"
[1] "Error for p = 0 and d = 1 :  attempt to select less than one element in integerOneIndex"
[1] "Error for p = 0 and d = 2 :  attempt to select less than one element in integerOneIndex"
[1] "Model for p = 1 and d = 0 fit successfully."
[1] "Error for p = 1 and d = 1 :  NROW(x) must match length(order.by)"
[1] "Error for p = 1 and d = 2 :  NROW(x) must match length(order.by)"
[1] "Model for p = 2 and d = 0 fit successfully."
[1] "Error for p = 2 and d = 1 :  NROW(x) must match length(order.by)"
[1] "Error for p = 2 and d = 2 :  NROW(x) must match length(order.by)"
[1] "Model for p = 3 and d = 0 fit successfully."
[1] "Error for p = 3 and d = 1 :  NROW(x) must match length(order.by)"
[1] "Error for p = 3 and d = 2 :  NROW(x) must match length(order.by)"
[1] "Model for p = 4 and d = 0 fit successfully."
[1] "Error for p = 4 and d = 1 :  NROW(x) must match length(order.by)"
[1] "Error for p = 4 and d = 2 :  NROW(x) must match length(order.by)"

there seems to be a problem when d is greater than zero. How do I solve this?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.