Re: Help with Using spTimer or spTDyn to estimate "GP" Model

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Help with Using spTimer or spTDyn to estimate "GP" Model

R help mailing list-2
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?

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Help with Using spTimer or spTDyn to estimate "GP" Model

Bert Gunter-2
Please not per the posting guide linked below:

"For questions about functions in standard packages distributed with R (see
the FAQ Add-on packages in R
<https://cran.r-project.org/doc/FAQ/R-FAQ.html#Add-on-packages-in-R>), ask
questions on R-help.
If the question relates to a *contributed package* , e.g., one downloaded
from CRAN, try contacting the package maintainer first. You can also use
find("functionname") and packageDescription("packagename") to find this
information. *Only* send such questions to R-help or R-devel if you get no
reply or need further assistance. This applies to both requests for help
and to bug reports."

So do not be disappointed if you do not receive a (helpful) response here.
You could, but ... There are, after all, around 25,000 R packages out
there, and this list cannot possibly support them all.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Jan 31, 2021 at 11:26 AM alex_rugu--- via R-help <
[hidden email]> wrote:

> 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?
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Help with Using spTimer or spTDyn to estimate "GP" Model

Bert Gunter-2
Also note that you should have a higher likelihood of getting a helpful
response on the r-sig-geo list rather than here.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Jan 31, 2021 at 12:34 PM Bert Gunter <[hidden email]> wrote:

> Please not per the posting guide linked below:
>
> "For questions about functions in standard packages distributed with R
> (see the FAQ Add-on packages in R
> <https://cran.r-project.org/doc/FAQ/R-FAQ.html#Add-on-packages-in-R>),
> ask questions on R-help.
> If the question relates to a *contributed package* , e.g., one downloaded
> from CRAN, try contacting the package maintainer first. You can also use
> find("functionname") and packageDescription("packagename") to find this
> information. *Only* send such questions to R-help or R-devel if you get
> no reply or need further assistance. This applies to both requests for help
> and to bug reports."
>
> So do not be disappointed if you do not receive a (helpful) response here.
> You could, but ... There are, after all, around 25,000 R packages out
> there, and this list cannot possibly support them all.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Jan 31, 2021 at 11:26 AM alex_rugu--- via R-help <
> [hidden email]> wrote:
>
>> 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?
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.