[R] Help with Using spTimer or spTDyn to estimate "GP" Model

@iex_rugu m@iii@g oii y@hoo@com @iex_rugu m@iii@g oii y@hoo@com
Sun Jan 31 19:35:28 CET 2021


When I run the following scripts I get the following error and I do not understand the source. I believe N is specified as the number of observations by year in the time series variables.  The error is
#######################################
Output: GP models 
Error in spGP.Gibbs(formula = formula, data = data, time.data = time.data,  : 
   Error: Years, Months, and Days are misspecified,
 i.e., total number of observations in the data set should be equal to N
  : N = n * r * T 
   where, N = total number of observations in the data,
          n = total number of sites,
          r = total number of years,
          T = total number of days. 
## Check spT.time function.

The scrip is
######################
library(spTimer)
library(spTDyn)
library(tidyverse)
library(ggmap)


register_google(key=" your key ") # for use with ggmap
getOption("ggmap")


#Data to analyze is from plm package
#The data include US States Production, which is a panel of 48 observations from 1970 to 1986
#A data frame containing :
#state: the state
#year : the year
#region : the region
#pcap : public capital stock
#hwy :  highway and streets
#water : water and sewer facilities
#util : other public buildings and structures
#pc : private capital stock
#gsp : gross state product
#emp :labor input measured by the employment in non–agricultural payrolls
#unemp : state unemployment rateA panel of 48 observations from 1970 to 1986


data("Produc", package = "plm")
glimpse(Produc)


#Estimate Geolocation of states to account for spill over effects
states_df <- data.frame(as.character(unique(Produc$state)))
names(states_df)<- c("state")


state_geo_df <- mutate_geocode(states_df, state)

#Join the data

Product_geo <- full_join(state_geo_df, Produc)
glimpse(Product_geo)


#Create the time series variable
#number of state
ns <- length(unique(Product_geo$state))


#number of year
ny <- length(unique(Product_geo$year))
####################################################
# I want to do Spatio-Temporal Bayesian Modeling Using spTimer or spTDyn
#defines the time series in the Spatio-temporal data.


ts_STD <- def.time(t.series=ns, segments=ny)


##################Estimate the model using spTDyn package
#Also note that the spT.Gibbs in spTimer gives the same error


GibbsDyn(gsp ~ pcap + hwy + water + util + pc , 
       data=Product_geo, model="GP", 
         time.data=ts_STD, 
         coords=~lon + lat,
          nItr=5000, nBurn=1000, report=1, tol.dist=0.05,
            distance.method="geodetic:km", cov.fnc="exponential", 
             spatial.decay=decay(distribution="FIXED"),truncation.para=list(at=0,lambda=2))


#Also I will appreciate showing how to deal with unbalanced panel data
#Delete some of the rows
Product_geo$cond = with(Product_geo,  if_else(state=="ALABAMA" & year==1971, 0,
                                         if_else(state=="COLORADO" & year==1971 | year==1973 , 0,
                                         if_else(state=="TEXAS" & year==1971 | year==1973 | year==1985, 0, 1))))

#Create an unbalanced panel
Product_geo_unb <- Product_geo %>% filter(cond==1) %>% select(-cond)
glimpse(Product_geo_unb)


#How to use GibbsDyn or spT.Gibbs function to estimate the "GP" model for such unbalanced panel data?



More information about the R-help mailing list