[Splm-commits] r254 - in pkg: . R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 17 09:01:15 CEST 2023


Author: gpiras
Date: 2023-07-17 09:01:14 +0200 (Mon, 17 Jul 2023)
New Revision: 254

Modified:
   pkg/NAMESPACE
   pkg/R/impacts.splm.R
   pkg/R/ivsplm.R
   pkg/R/spgm.R
   pkg/inst/CITATION
   pkg/man/spgm.Rd
Log:
impacts


Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2023-02-17 15:53:29 UTC (rev 253)
+++ pkg/NAMESPACE	2023-07-17 07:01:14 UTC (rev 254)
@@ -67,7 +67,7 @@
 S3method(summary, splm)
 S3method(sphtest, formula)
 S3method(sphtest, splm)
-S3method(impacts, splm)
+#S3method(impacts, splm)
 S3method(impacts, splm_GM)
 S3method(slag, pseries)
 S3method(rwtest, formula)

Modified: pkg/R/impacts.splm.R
===================================================================
--- pkg/R/impacts.splm.R	2023-02-17 15:53:29 UTC (rev 253)
+++ pkg/R/impacts.splm.R	2023-07-17 07:01:14 UTC (rev 254)
@@ -15,6 +15,7 @@
   
   object <- obj
   
+  
   if(is.null(listw) && is.null(tr)) stop("either listw or tr should be provided")
   if (!is.null(object$endo)) stop("impacts for model 
                                   with additional endogenous 
@@ -215,7 +216,9 @@
         p2 <- length(coefs)
         lambda <- coefs[1]
         beta <- coefs[2:p2]
-        names(beta) <- rownames(object$coefficients)[2:p2]
+        names(beta) <- names(object$coefficients)[2:p2]
+        colnames(object$vcov) <- rownames(object$vcov) <- names(object$coefficients)
+        
         p <- length(beta)
         p1 <- p + 1
         
@@ -239,10 +242,12 @@
         Sigma <- NULL
         
         if (!is.null(R)) {
+          
           mu <- c(lambda, beta)
           Sigma <- object$vcov[match(names(mu), rownames(object$vcov)),match(names(mu), rownames(object$vcov))]
+          
         }      
-        
+
         irho <- length(beta) + 1
         drop2beta <- length(beta) + 1
         
@@ -279,143 +284,143 @@
 
 
 
-impacts.splm <- function(obj, listw = NULL,
-                         time = NULL, ..., 
-                         tr = NULL, R = 200, 
-                         type = "mult", 
-                         empirical = FALSE, Q = NULL){
-
-if(is.null(listw) && is.null(tr)) stop("either listw or tr should be provided")
-
-	
-if(!is.null(listw) ){	
-	if(listw$style != "W") stop("Only row-standardised weights supported")
-	if(is.null(time) && is.null(tr)) stop("time periods should be provided")
-}
-
-
-if(is.null(tr)){
-	
-sparse.W <- listw2dgCMatrix(listw)
-s.lws <- kronecker(Diagonal(time) , sparse.W)
-tr <- trW(s.lws, type= type)
-	
-	}
-	
-if(is.na(match(obj$type, c("fixed effects lag","fixed effects sarar",
-                           "random effects ML", "fixed effects GM","lag GM",
-                           "fixed effects GM")))) stop("object type not recognized")
-	
-	if(obj$type == "fixed effects lag"){
-		
-class(obj)<- "Gmsar"	
-obj$type <- "SARAR"
-obj$data <- as.vector(obj$model)
-obj$s2 <- obj$sigma2
-obj$secstep_var <- obj$vcov
-imp <- spatialreg::impacts(obj, tr=tr, R=R, ...)
-
-	}
-	
-	if(obj$type == "fixed effects sarar"){
-
-class(obj)<- "Gmsar"	
-obj$type <- "SARAR"
-rho <- obj$coefficients[2]
-obj$coefficients <- obj$coefficients[-2]
-obj$data <- as.vector(obj$model)
-obj$s2 <- obj$sigma2
-obj$secstep_var <- obj$vcov[-2,-2]
-imp <- spatialreg::impacts(obj, tr=tr, R=R,...)		
-		
-	}
-
-	if(obj$type == "fixed effects error") stop("Impacts Estimates are not available for Error Model")
-
-	if(obj$type == "random effects ML")	{
-
-if(!is.null(obj$arcoef)) {
-class(obj)<- "Gmsar"	
-obj$type <- "SARAR"
-
-obj$coefficients <- c(obj$arcoef, obj$coefficients)
-obj$data <- as.vector(obj$model)
-obj$s2 <- obj$sigma2
-obj$secstep_var <- matrix(0,nrow(obj$vcov)+1,nrow(obj$vcov)+1)
-obj$secstep_var[1,1] <- obj$vcov.arcoef
-obj$secstep_var[(2:(nrow(obj$vcov)+1)),(2:(nrow(obj$vcov)+1))] <- obj$vcov
-imp <- spatialreg::impacts(obj, tr=tr, R=R, ...)		
-		}
-		else stop("Impacts Estimates are not available for Error Model")		
-		
-	}
-	
-
-	if(obj$type == "fixed effects GM"){
-		
-		if(is.null(obj$endog)) {
-obj$secstep_var <- vcov(obj)			
-class(obj)<- "Gmsar"	
-obj$type <- "SARAR"
-obj$data <- as.vector(obj$model)
-obj$s2 <- obj$sigma2
-
-imp <- impacts(obj, tr=tr, R=R, ...)		
-			
-			
-		}
-				
-		else stop("No impacts estimates when endogenous variables are present in the system")
-					
-	}
-
-if(obj$type == "lag GM")			{
-	
-		if(is.null(obj$endog)) {
-
-class(obj)<- "Gmsar"	
-obj$type <- "SARAR"
-obj$secstep_var <- obj$var			
-obj$data <- as.vector(obj$model)
-obj$s2 <- obj$sigma2
-
-imp <- impacts(obj, tr=tr, R=R, ...)		
-			
-			
-		}
-				
-		else stop("No impacts estimates when endogenous variables are present in the system")
-					
-
-	
-}
-
-
-if(obj$type == "random effects GM")			{
-	
-		if(is.null(obj$endog)) {
-
-class(obj)<- "Gmsar"	
-obj$type <- "SARAR"
-obj$secstep_var <- obj$vcov			
-obj$data <- as.vector(obj$model)
-obj$s2 <- obj$sigma2
-
-imp <- impacts(obj, tr=tr, R=R, ...)		
-			
-			
-		}
-				
-		else stop("No impacts estimates when endogenous variables are present in the system")
-					
-
-	
-}
-		
-
-
-
-	
-return(imp)	
-	
-}
+# impacts.splm <- function(obj, listw = NULL,
+#                          time = NULL, ..., 
+#                          tr = NULL, R = 200, 
+#                          type = "mult", 
+#                          empirical = FALSE, Q = NULL){
+# 
+# if(is.null(listw) && is.null(tr)) stop("either listw or tr should be provided")
+# 
+# 	
+# if(!is.null(listw) ){	
+# 	if(listw$style != "W") stop("Only row-standardised weights supported")
+# 	if(is.null(time) && is.null(tr)) stop("time periods should be provided")
+# }
+# 
+# 
+# if(is.null(tr)){
+# 	
+# sparse.W <- listw2dgCMatrix(listw)
+# s.lws <- kronecker(Diagonal(time) , sparse.W)
+# tr <- trW(s.lws, type= type)
+# 	
+# 	}
+# 	
+# if(is.na(match(obj$type, c("fixed effects lag","fixed effects sarar",
+#                            "random effects ML", "fixed effects GM","lag GM",
+#                            "fixed effects GM")))) stop("object type not recognized")
+# 	
+# 	if(obj$type == "fixed effects lag"){
+# 		
+# class(obj)<- "Gmsar"	
+# obj$type <- "SARAR"
+# obj$data <- as.vector(obj$model)
+# obj$s2 <- obj$sigma2
+# obj$secstep_var <- obj$vcov
+# imp <- spatialreg::impacts(obj, tr=tr, R=R, ...)
+# 
+# 	}
+# 	
+# 	if(obj$type == "fixed effects sarar"){
+# 
+# class(obj)<- "Gmsar"	
+# obj$type <- "SARAR"
+# rho <- obj$coefficients[2]
+# obj$coefficients <- obj$coefficients[-2]
+# obj$data <- as.vector(obj$model)
+# obj$s2 <- obj$sigma2
+# obj$secstep_var <- obj$vcov[-2,-2]
+# imp <- spatialreg::impacts(obj, tr=tr, R=R,...)		
+# 		
+# 	}
+# 
+# 	if(obj$type == "fixed effects error") stop("Impacts Estimates are not available for Error Model")
+# 
+# 	if(obj$type == "random effects ML")	{
+# 
+# if(!is.null(obj$arcoef)) {
+# class(obj)<- "Gmsar"	
+# obj$type <- "SARAR"
+# 
+# obj$coefficients <- c(obj$arcoef, obj$coefficients)
+# obj$data <- as.vector(obj$model)
+# obj$s2 <- obj$sigma2
+# obj$secstep_var <- matrix(0,nrow(obj$vcov)+1,nrow(obj$vcov)+1)
+# obj$secstep_var[1,1] <- obj$vcov.arcoef
+# obj$secstep_var[(2:(nrow(obj$vcov)+1)),(2:(nrow(obj$vcov)+1))] <- obj$vcov
+# imp <- spatialreg::impacts(obj, tr=tr, R=R, ...)		
+# 		}
+# 		else stop("Impacts Estimates are not available for Error Model")		
+# 		
+# 	}
+# 	
+# 
+# 	if(obj$type == "fixed effects GM"){
+# 		
+# 		if(is.null(obj$endog)) {
+# obj$secstep_var <- vcov(obj)			
+# class(obj)<- "Gmsar"	
+# obj$type <- "SARAR"
+# obj$data <- as.vector(obj$model)
+# obj$s2 <- obj$sigma2
+# 
+# imp <- impacts(obj, tr=tr, R=R, ...)		
+# 			
+# 			
+# 		}
+# 				
+# 		else stop("No impacts estimates when endogenous variables are present in the system")
+# 					
+# 	}
+# 
+# if(obj$type == "lag GM")			{
+# 	
+# 		if(is.null(obj$endog)) {
+# 
+# class(obj)<- "Gmsar"	
+# obj$type <- "SARAR"
+# obj$secstep_var <- obj$var			
+# obj$data <- as.vector(obj$model)
+# obj$s2 <- obj$sigma2
+# 
+# imp <- impacts(obj, tr=tr, R=R, ...)		
+# 			
+# 			
+# 		}
+# 				
+# 		else stop("No impacts estimates when endogenous variables are present in the system")
+# 					
+# 
+# 	
+# }
+# 
+# 
+# if(obj$type == "random effects GM")			{
+# 	
+# 		if(is.null(obj$endog)) {
+# 
+# class(obj)<- "Gmsar"	
+# obj$type <- "SARAR"
+# obj$secstep_var <- obj$vcov			
+# obj$data <- as.vector(obj$model)
+# obj$s2 <- obj$sigma2
+# 
+# imp <- impacts(obj, tr=tr, R=R, ...)		
+# 			
+# 			
+# 		}
+# 				
+# 		else stop("No impacts estimates when endogenous variables are present in the system")
+# 					
+# 
+# 	
+# }
+# 		
+# 
+# 
+# 
+# 	
+# return(imp)	
+# 	
+# }

Modified: pkg/R/ivsplm.R
===================================================================
--- pkg/R/ivsplm.R	2023-02-17 15:53:29 UTC (rev 253)
+++ pkg/R/ivsplm.R	2023-07-17 07:01:14 UTC (rev 254)
@@ -143,6 +143,6 @@
     result$legacy <- FALSE
     result$listw_style <- NULL
     result$call <- match.call()
-    result$nfimpacts <- "lag_gm"
+    
 result
 }

Modified: pkg/R/spgm.R
===================================================================
--- pkg/R/spgm.R	2023-02-17 15:53:29 UTC (rev 253)
+++ pkg/R/spgm.R	2023-07-17 07:01:14 UTC (rev 254)
@@ -65,7 +65,7 @@
 	                lag = lag, listw = listw, 
 	                lag.instruments = lag.instruments, Durbin = Durbin)
 	
-	
+	results$nfimpacts <- "lag_gm"
 	}
 
 
@@ -81,7 +81,8 @@
                               optim.method = optim.method, pars = pars, Durbin = Durbin)
 #, initial.GMerror = initial.GMerror
 
-else results <- spsarargm(formula = formula, data = data, index = index, 
+else {
+  results <- spsarargm(formula = formula, data = data, index = index, 
                           listw = listw, listw2 = listw2,  
                           moments = moments, lag = lag, endog = endog, 
                           instruments = instruments, verbose = verbose, 
@@ -88,8 +89,10 @@
                           effects = effects, control = control, 
                           lag.instruments = lag.instruments, 
                           optim.method = optim.method, pars = pars, twow = twow, Durbin = Durbin)
+  results$nfimpacts <- "sarar_gm"
 
-	}
+}
+}
 #results$lag <- lag
 #results$error <- error
 results$call <- cl
@@ -98,7 +101,7 @@
 results$endog <- endog
 results$est.meth <- "GM"
 results$Durbin <- Durbin
-class(results) <- c("splm","splm_GM")
+class(results) <- c("splm_GM", "splm")
 results
 
 }
@@ -1215,7 +1218,9 @@
     spmod <- list(coefficients=betaGLS, errcomp=  errcomp,
                 vcov=  covbeta, vcov.errcomp=NULL,
                 residuals=as.numeric(egls), fitted.values=fv,
-                sigma2=SGLS,type=type, rho=errcomp, model=model.data, logLik=NULL, coy=yt, cox=xt, rhs=k, type = type)
+                sigma2=SGLS,type=type, rho=errcomp, model=model.data,
+                logLik=NULL, coy=yt, cox=xt, rhs=k, type = type, 
+                nfimpacts = "sarar_gm")
   
 	}
 		}, 

Modified: pkg/inst/CITATION
===================================================================
--- pkg/inst/CITATION	2023-02-17 15:53:29 UTC (rev 253)
+++ pkg/inst/CITATION	2023-07-17 07:01:14 UTC (rev 254)
@@ -1,10 +1,8 @@
 citHeader("To cite splm in publications use:")
 
-citEntry(entry="Article",
+bibentry("Article",
          title="A Review of Software for Spatial Econometrics in {R}",
-         author=personList(as.person("Roger Bivand"), 
-                           as.person("Giovanni Millo"),
-                           as.person("Gianfranco Piras")),
+         author=c("Roger Bivand", "Giovanni Millo","Gianfranco Piras"),
          journal="Mathematics",
          year="2021",
          volume="9",
@@ -17,10 +15,9 @@
          "http://dx.doi.org/10.3390/math9111276.")
 )
 
-citEntry(entry = "Article",
+bibentry("Article",
   title        = "{splm}: Spatial Panel Data Models in {R}",
-  author       = personList(as.person("Giovanni Millo"),
-                   as.person("Gianfranco Piras")),
+  author       = c("Giovanni Millo", "Gianfranco Piras"),
   journal      = "Journal of Statistical Software",
   year         = "2012",
   volume       = "47",

Modified: pkg/man/spgm.Rd
===================================================================
--- pkg/man/spgm.Rd	2023-02-17 15:53:29 UTC (rev 253)
+++ pkg/man/spgm.Rd	2023-07-17 07:01:14 UTC (rev 254)
@@ -151,7 +151,7 @@
 data(Produc)
 data(usaww)
 ########SPATIAL LAG MODEL######
-#no space no endog: error usa plm
+#no space no endog: error use plm
 \dontrun{GM_lag_b2sls <- spgm(log(gsp) ~ log(pcap) + log(pc) + unemp, data=Produc,
                      lag = FALSE, spatial.error = FALSE, method = "b2sls",
                      listw = usaww)}



More information about the Splm-commits mailing list