[Splm-commits] r252 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Feb 16 12:21:43 CET 2023


Author: rsbivand
Date: 2023-02-16 12:21:42 +0100 (Thu, 16 Feb 2023)
New Revision: 252

Modified:
   pkg/R/semREmod.R
Log:
add NA_real_ return to ll.c if lambda not finite

Modified: pkg/R/semREmod.R
===================================================================
--- pkg/R/semREmod.R	2022-11-22 16:19:10 UTC (rev 251)
+++ pkg/R/semREmod.R	2023-02-16 11:21:42 UTC (rev 252)
@@ -62,21 +62,26 @@
         ## retrieve parms
         phi <- philambda[1]
         lambda <- philambda[2]
-        ## calc inverse sigma
-        sigma.1 <- invSigma(philambda, n, t., w2)
-        ## do GLS step to get e, s2e
-        glsres <- GLSstep(X, y, sigma.1)
-        e <- glsres[["ehat"]]
-        s2e <- glsres[["sigma2"]]
-        ## calc ll
-        zero <- 0
-        due <- detSigma(phi, lambda, n, t., w2)
-        tre <- -n * t./2 * log(s2e)
-        quattro <- -1/(2 * s2e) * crossprod(e, sigma.1) %*% e
-        const <- -(n * t.)/2 * log(2 * pi)
-        ll.c <- const + zero + due + tre + quattro
-        ## invert sign for minimization
-        llc <- -ll.c
+        if (!is.finite(lambda)) {
+            llc <- NA_real_
+        } else {
+            ## calc inverse sigma
+            sigma.1 <- invSigma(philambda, n, t., w2)
+            ## do GLS step to get e, s2e
+            glsres <- GLSstep(X, y, sigma.1)
+            e <- glsres[["ehat"]]
+            s2e <- glsres[["sigma2"]]
+            ## calc ll
+            zero <- 0
+            due <- detSigma(phi, lambda, n, t., w2)
+            tre <- -n * t./2 * log(s2e)
+            quattro <- -1/(2 * s2e) * crossprod(e, sigma.1) %*% e
+            const <- -(n * t.)/2 * log(2 * pi)
+            ll.c <- const + zero + due + tre + quattro
+            ## invert sign for minimization
+            llc <- -ll.c
+        }
+        llc
     }
 
     ## set bounds for optimizer



More information about the Splm-commits mailing list