[Gmm-commits] r99 - in pkg: gmm/R gmmExtra gmmExtra/R gmmExtra/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 24 19:50:57 CET 2017


Author: chaussep
Date: 2017-01-24 19:50:57 +0100 (Tue, 24 Jan 2017)
New Revision: 99

Modified:
   pkg/gmm/R/gmmTests.R
   pkg/gmmExtra/NAMESPACE
   pkg/gmmExtra/R/KConfig.R
   pkg/gmmExtra/man/KConfid.Rd
Log:
partially fixed the check errors in gmmExtra

Modified: pkg/gmm/R/gmmTests.R
===================================================================
--- pkg/gmm/R/gmmTests.R	2017-01-20 18:36:12 UTC (rev 98)
+++ pkg/gmm/R/gmmTests.R	2017-01-24 18:50:57 UTC (rev 99)
@@ -53,7 +53,6 @@
 	fT <- colSums(gt)
 	n <- nrow(gt)
 	q <- ncol(gt)
-        print(q)
 	All <- cbind(gt,qT)
 	All <- sweep(All,2,colMeans(All),FUN="-")
 	f <- function(x)

Modified: pkg/gmmExtra/NAMESPACE
===================================================================
--- pkg/gmmExtra/NAMESPACE	2017-01-20 18:36:12 UTC (rev 98)
+++ pkg/gmmExtra/NAMESPACE	2017-01-24 18:50:57 UTC (rev 99)
@@ -2,6 +2,7 @@
 importFrom(car, linearHypothesis, makeHypothesis, printHypothesis)
 importFrom(parallel, mclapply)
 importFrom(gmm, gmm, specTest, gmmWithConst, KTest)
+importFrom(graphics, plot)
 
 export(KConfid, bootGmm, plot.bootGmm, summary.bootGmm, bootJ, linearHypothesis.bootGmm, print.bootGmm)
 

Modified: pkg/gmmExtra/R/KConfig.R
===================================================================
--- pkg/gmmExtra/R/KConfig.R	2017-01-20 18:36:12 UTC (rev 98)
+++ pkg/gmmExtra/R/KConfig.R	2017-01-24 18:50:57 UTC (rev 99)
@@ -1,5 +1,5 @@
 KConfid <- function(obj, which, type = c("K", "KJ"), alpha = 0.05, alphaJ = 0.01, n = 4,
-                    mc.cores=2)
+                    mc.cores=1)
 	{
         theApply <- mclapply
         if (Sys.info()[["sysname"]] == "Windows")
@@ -30,7 +30,7 @@
 		} else {
 		if (any(which>length(obj$coefficients)) | any(which<=0))
 			stop("indices in which are not valid")
-		}
+            }
 	getUniInt <- function(tetx, obj, which, value=NULL, type , alpha, alphaJ, alphaK)
 		{
 		# value is the value of the other coefficient when we have 2 restrictions
@@ -39,7 +39,7 @@
 		if (is.null(value))
 			value <- tetx
 		else
-			value <- c(tetx,value)
+                    value <- c(tetx,value)
 		res <- gmmWithConst(obj, which = which, value = value)
 		test <- KTest(res)
 		if (type == "K")
@@ -62,16 +62,16 @@
 		step <- 5*sqrt(diag(vcov(obj)))[which]
 		X0 <- obj$coef[which]
 		getBoth <- function(d)
-			{
+                    {
 			res <- try(uniroot(getUniInt,c(X0,X0+d*step),
                                            obj = obj, which = which, type = type, 
                                            alpha = alpha, alphaJ = alphaJ, alphaK = alphaK,
                                            tol=1e-4), silent=TRUE)
 			if (class(res) == "try-error")
-				return(NA)
+                            return(NA)
 			else
-				return(res$root)
-			}
+                            return(res$root)
+                    }
 		res <- theApply(c(-1,1), getBoth, mc.cores=mc.cores)
 		c(res[[1]],res[[2]])
 	} else {

Modified: pkg/gmmExtra/man/KConfid.Rd
===================================================================
--- pkg/gmmExtra/man/KConfid.Rd	2017-01-20 18:36:12 UTC (rev 98)
+++ pkg/gmmExtra/man/KConfid.Rd	2017-01-24 18:50:57 UTC (rev 99)
@@ -5,14 +5,17 @@
 \description{The confidence is either an interval or an ellipse.
 }
 \usage{
-KConfid(obj, which, type = c("K", "KJ"), alpha = 0.05, alphaJ = 0.01, n = 4)
+KConfid(obj, which, type = c("K", "KJ"), alpha = 0.05, alphaJ = 0.01,
+        n = 4, mc.cores=1)
 }
 \arguments{
  \item{obj}{Object of class "gmm" returned by \link{gmm} (not restricted)}
  \item{type}{Should we base the confidence interval on the K or K-J statistics.}
  \item{which}{A 2x1 vector or a scalar. The interval is computed for \code{coef(obj)[which]}. }
  \item{alpha, alphaJ}{The overall size and the size for the J-test when type is "KS".}
- \item{n}{The number of points to compute the confidence region is 4(n-1). It must be greater than 2.}
+ \item{n}{The number of points to compute the confidence region is
+   4(n-1). It must be greater than2.}
+ \item{mc.cores}{The number of cores to use in \link{mclapply}}
 }
 
 
@@ -39,10 +42,11 @@
 f1 <- zm
 f2 <- Finance[1:300, "hml"] - rf
 f3 <- Finance[1:300, "smb"] - rf
-res <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3)
+## Kconfid fails with prewhite=1
+res <- gmm(z ~ f1 + f2 + f3, ~ f1 + f2 + f3, prewhite=0)
 
-KConfid(res,2)
-sol <- KConfid(res,c(2,3))
+KConfid(res,2, mc.cores=4)
+sol <- KConfid(res,c(2,3), mc.cores=4)
 plot(sol, main="Confidence Region")
 polygon(sol,col="grey")
 points(res$coef[2],res$coef[3],pch=21,bg=1)



More information about the Gmm-commits mailing list