[Gmm-commits] r202 - pkg/momentfit/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Aug 12 04:20:25 CEST 2022


Author: chaussep
Date: 2022-08-12 04:20:25 +0200 (Fri, 12 Aug 2022)
New Revision: 202

Modified:
   pkg/momentfit/R/gmm4.R
   pkg/momentfit/R/momentModel-methods.R
   pkg/momentfit/R/momentModel.R
Log:
removed ifs with class and string

Modified: pkg/momentfit/R/gmm4.R
===================================================================
--- pkg/momentfit/R/gmm4.R	2022-08-01 13:21:50 UTC (rev 201)
+++ pkg/momentfit/R/gmm4.R	2022-08-12 02:20:25 UTC (rev 202)
@@ -33,7 +33,7 @@
             model <- try(momentModel(g=g, x=x, theta0=theta0, grad=grad, vcov=vcov2,
                                   vcovOptions=vcovOptions,survOptions=survOptions,
                                   centeredVcov=centeredVcov, data=data), silent=TRUE)
-        if (is.null(model) || class(model)=="try-error")
+        if (is.null(model) || inherits(model,"try-error"))
             model <- sysMomentModel(g=g, h=x, theta0=theta0, vcov=vcov2,
                                  vcovOptions=vcovOptions,survOptions=survOptions,
                                  centeredVcov=centeredVcov, data=data)

Modified: pkg/momentfit/R/momentModel-methods.R
===================================================================
--- pkg/momentfit/R/momentModel-methods.R	2022-08-01 13:21:50 UTC (rev 201)
+++ pkg/momentfit/R/momentModel-methods.R	2022-08-12 02:20:25 UTC (rev 202)
@@ -173,13 +173,13 @@
                   if (!is.null(res$fLHS))
                       {
                           lhs <- try(eval(res$fLHS, varList))
-                          if (any(class(lhs)=="try-error"))
+                          if (inherits(lhs, "try-error"))
                               stop("Cannot evaluate the LHS")
                       } else {
                           lhs <- 0
                       }
                   rhs <- try(eval(res$fRHS, varList))
-                  if (any(class(rhs)=="try-error"))
+                  if (inherits(rhs, "try-error"))
                       stop("Cannot evaluate the RHS")
                   c(lhs-rhs)
               })
@@ -218,7 +218,7 @@
                   if (!is.null(res$fLHS[[i]]))
                   {
                       lhs <- try(eval(res$fLHS[[i]], varList))
-                      if (any(class(lhs)=="try-error"))
+                      if (inherits(lhs, "try-error"))
                           stop("Cannot evaluate the LHS")
                   } else {
                       lhs <- 0
@@ -226,7 +226,7 @@
                   if (!is.null(res$fRHS[[i]]))
                   {
                       rhs <- try(eval(res$fRHS[[i]], varList))
-                      if (any(class(lhs)=="try-error"))
+                      if (inherits(rhs, "try-error"))
                           stop("Cannot evaluate the RHS")
                   } else {
                       lhs <- 0
@@ -906,7 +906,7 @@
              chk <- validObject(model, TRUE)
              if (!chk)
                  stop("model is not a valid momentModel object")
-             if (initW == "tsls" && class(model) != "linearModel")
+             if (initW == "tsls" && !is(model,"linearModel"))
                  stop("initW='tsls' is for linear models only")
              if (is.character(weights) && !(weights%in%c("optimal","ident")))
                  stop("weights is a matrix or one of 'optimal' or 'ident'")
@@ -941,7 +941,7 @@
                             efficientGmm=efficientGmm)
                  return(ans)
              }
-             if (class(model) == "linearModel")
+             if (is(model,"linearModel"))
              {
                  if (model at vcov == "iid")
                      if (is.character(weights) && weights == "optimal")

Modified: pkg/momentfit/R/momentModel.R
===================================================================
--- pkg/momentfit/R/momentModel.R	2022-08-01 13:21:50 UTC (rev 201)
+++ pkg/momentfit/R/momentModel.R	2022-08-12 02:20:25 UTC (rev 202)
@@ -98,7 +98,7 @@
         survOptions <- .getSurvOptions(data, survOptions)
         if (!is.list(data) & !is.environment(data) & !is.function(g)) 
             stop("'data' must be a list or an environment")    
-        if (any(class(g)=="formula"))
+        if (inherits(g,"formula"))
             {
                 chk <- names(theta0) %in% all.vars(g)
                 if (length(chk) == 0 | all(!chk))
@@ -161,7 +161,7 @@
             } else {
                 if (!is.null(x))
                     stop("For formula Models, x must be NULL. The moments are only defined as a list of formulas")
-                if (class(g) != "list")
+                if (!is.list(g))
                     stop("For formula Models, g must be a list of formulas")
                 if (any(sapply(g, function(gi) class(gi)) != "formula"))
                     stop("For formula Models, g must be a list of formulas")



More information about the Gmm-commits mailing list