[Gogarch-commits] r18 - in pkg: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Feb 4 19:58:22 CET 2009
Author: bpfaff
Date: 2009-02-04 19:58:22 +0100 (Wed, 04 Feb 2009)
New Revision: 18
Modified:
pkg/DESCRIPTION
pkg/R/All-classes.R
pkg/R/GoGARCH-show.R
pkg/R/Goestnls-goest.R
pkg/R/gogarch.R
pkg/R/gonls.R
pkg/R/gotheta.R
pkg/man/GoGARCH-class.Rd
pkg/man/Goestml-class.Rd
pkg/man/Goestnls-class.Rd
Log:
Added slot to GoGARCH and nls-method improved.
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/DESCRIPTION 2009-02-04 18:58:22 UTC (rev 18)
@@ -1,8 +1,8 @@
Package: gogarch
-Version: 0.4-0
+Version: 0.4-2
Type: Package
Title: Generalized Orthogonal GARCH (GO-GARCH) models
-Date: 2009-02-03
+Date: 2009-02-04
Author: Bernhard Pfaff
Maintainer: Bernhard Pfaff <bernhard at pfaffikus.de>
Depends: R (>= 2.7.0), methods, stats, fGarch
@@ -11,3 +11,4 @@
License: GPL (>= 2)
LazyLoad: yes
LazyLoad: yes
+
Modified: pkg/R/All-classes.R
===================================================================
--- pkg/R/All-classes.R 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/R/All-classes.R 2009-02-04 18:58:22 UTC (rev 18)
@@ -5,7 +5,7 @@
##
## Class definition of GO-GARCH objects
##
-setClass(Class = "GoGARCH", representation(Z = "matrix", Y = "matrix", H = "list", models = "list", estby = "character", CALL = "call"), contains = "Goinit")
+setClass(Class = "GoGARCH", representation(Z = "matrix", U = "matrix", Y = "matrix", H = "list", models = "list", estby = "character", CALL = "call"), contains = "Goinit")
##
## Class definition of GO-GARCH objects, estimated by Maximum-Likelihood
##
Modified: pkg/R/GoGARCH-show.R
===================================================================
--- pkg/R/GoGARCH-show.R 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/R/GoGARCH-show.R 2009-02-04 18:58:22 UTC (rev 18)
@@ -12,13 +12,13 @@
cat("\n")
cat(paste("Formula for component GARCH models:", paste(as.character(object at garchf), collapse = " "), "\n"))
cat("\n")
- if(length(object at Z) != 0){
+ if(length(object at U) != 0){
+ cat("Orthonormal Matrix U:\n")
+ print(object at U)
+ cat("\n")
cat("Linar Map Z:\n")
- print(object at Z, quote = FALSE)
+ print(object at Z)
cat("\n")
- cat("and its inverse:\n")
- print(solve(object at Z), quote = FALSE)
- cat("\n")
}
cat("Estimated GARCH coefficients:\n")
print(coef(object))
Modified: pkg/R/Goestnls-goest.R
===================================================================
--- pkg/R/Goestnls-goest.R 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/R/Goestnls-goest.R 2009-02-04 18:58:22 UTC (rev 18)
@@ -5,23 +5,25 @@
Dsqr <- object at Dsqr
Dsqri <- diag(1 / diag(Dsqr))
P <- object at P
- S <- data.frame(t(X %*% Dsqri %*% P))
- SSI <- lapply(S, function(x) x %*% t(x) - diag(m))
+ S <- X %*% P %*% Dsqri
+ SSI <- list()
+ length(SSI) <- n
+ for(i in 1:n){
+ SSI[[i]] <- S[i, ] %*% t(S[i, ]) - diag(m)
+ }
SSI0 <- SSI[-1]
SSI1 <- SSI[-n]
SSI <- list(SSI0 = SSI0, SSI1 = SSI1)
- nlsobj <- optim(par = initial, fn = gonls, SSI = SSI, ...)
+ nlsobj <- nlminb(start = initial, objective = gonls, SSI = SSI, ...)
B <- unvech(nlsobj$par)
U <- svd(B)$u
- U <- eigen(B)$vectors
Z <- P %*% Dsqr %*% t(U)
- Zinv <- solve(Z)
- Y <- X %*% Zinv
+ Y <- S %*% U
fitted <- apply(Y, 2, function(x) do.call("garchFit", c(list(formula = object at garchf, data = quote(x)), garchlist)))
H <- matrix(unlist(lapply(fitted, function(x) x at h.t)), ncol = m, nrow = n)
Hdf <- data.frame(t(H))
Ht <- lapply(Hdf, function(x) Z %*% diag(x) %*% t(Z))
names(Ht) <- rownames(object at X)
- result <- new("Goestnls", nls = nlsobj, estby = "non-linear Least-Squares", Z = Z, Y = Y, H = Ht, models = fitted, X = object at X, P = object at P, Dsqr = object at Dsqr, V = object at V, garchf = object at garchf, name = object at name)
+ result <- new("Goestnls", nls = nlsobj, estby = "non-linear Least-Squares", U = U, Z = Z, Y = Y, H = Ht, models = fitted, X = object at X, P = object at P, Dsqr = object at Dsqr, V = object at V, garchf = object at garchf, name = object at name)
return(result)
})
Modified: pkg/R/gogarch.R
===================================================================
--- pkg/R/gogarch.R 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/R/gogarch.R 2009-02-04 18:58:22 UTC (rev 18)
@@ -1,5 +1,8 @@
gogarch <- function(data, formula, scale = FALSE, method = c("ml", "nls"), initial = NULL, garchlist = list(init.rec = "mci", delta = 2, skew = 1, shape = 4, cond.dist = "norm", include.mean = FALSE, include.delta = NULL, include.skew = NULL, include.shape = NULL, leverage = NULL, trace = FALSE, algorithm = "nlminb", hessian = "ropt", control = list(), title = NULL, description = NULL), ...){
method <- match.arg(method)
+ if(missing(garchlist)){
+ garchlist <- list(init.rec = "mci", delta = 2, skew = 1, shape = 4, cond.dist = "norm", include.mean = FALSE, include.delta = NULL, include.skew = NULL, include.shape = NULL, leverage = NULL, trace = FALSE, algorithm = "nlminb", hessian = "ropt", control = list(), title = NULL, description = NULL)
+ }
Call <- match.call()
d <- ncol(data)
gini <- goinit(X = data, garchf = formula, scale = scale)
@@ -28,7 +31,7 @@
}
}
goestnls <- new("Goestnls", gomod)
- gogarch <- goest(object = goestnls, initial = initial, garchlist = garchlist, ...)
+ gogarch <- goest(goestnls, initial, garchlist, ...)
}
gogarch at CALL <- Call
gogarch at name <- deparse(substitute(data))
Modified: pkg/R/gonls.R
===================================================================
--- pkg/R/gonls.R 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/R/gonls.R 2009-02-04 18:58:22 UTC (rev 18)
@@ -5,7 +5,8 @@
fl <- list()
length(fl) <- n
for(i in 1:n){
- fl[[i]] <- (SSI[[1]][[i]] - B %*% SSI[[2]][[i]] %*% B)^2
+ M <- (SSI[[1]][[i]] - B %*% SSI[[2]][[i]] %*% B)
+ fl[[i]] <- M %*% M
}
f <- sum(unlist(lapply(fl, function(x) sum(diag(x))))) / n
return(f)
Modified: pkg/R/gotheta.R
===================================================================
--- pkg/R/gotheta.R 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/R/gotheta.R 2009-02-04 18:58:22 UTC (rev 18)
@@ -19,6 +19,6 @@
Hdf <- data.frame(t(H))
Ht <- lapply(Hdf, function(x) Z %*% diag(x) %*% t(Z))
names(Ht) <- rownames(object at X)
- result <- new("GoGARCH", Z = Z, Y = Y, H = Ht, models = fitted, X = object at X, P = object at P, Dsqr = object at Dsqr, V = object at V, garchf = object at garchf, name = object at name, CALL = match.call())
+ result <- new("GoGARCH", U = U, Z = Z, Y = Y, H = Ht, models = fitted, X = object at X, P = object at P, Dsqr = object at Dsqr, V = object at V, garchf = object at garchf, name = object at name, CALL = match.call())
return(result)
}
Modified: pkg/man/GoGARCH-class.Rd
===================================================================
--- pkg/man/GoGARCH-class.Rd 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/man/GoGARCH-class.Rd 2009-02-04 18:58:22 UTC (rev 18)
@@ -31,6 +31,7 @@
\section{Slots}{
\describe{
\item{\code{Z}:}{Object of class \code{"matrix"}: Transformation matrix.}
+ \item{\code{U}:}{Object of class \code{"matrix"}: Orthonormal matrix.}
\item{\code{Y}:}{Object of class \code{"matrix"}: Extracted
component matrix.}
\item{\code{H}:}{Object of class \code{"list"}: List of conditional
Modified: pkg/man/Goestml-class.Rd
===================================================================
--- pkg/man/Goestml-class.Rd 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/man/Goestml-class.Rd 2009-02-04 18:58:22 UTC (rev 18)
@@ -41,6 +41,7 @@
\item{\code{opt}:}{Object of class \code{"list"}: List returned by
\code{nlminb}.}
\item{\code{Z}:}{Object of class \code{"matrix"}: Transformation matrix.}
+ \item{\code{U}:}{Object of class \code{"matrix"}: Orthonormal matrix.}
\item{\code{Y}:}{Object of class \code{"matrix"}: Extracted
component matrix.}
\item{\code{H}:}{Object of class \code{"list"}: List of conditional
Modified: pkg/man/Goestnls-class.Rd
===================================================================
--- pkg/man/Goestnls-class.Rd 2009-02-03 21:42:00 UTC (rev 17)
+++ pkg/man/Goestnls-class.Rd 2009-02-04 18:58:22 UTC (rev 18)
@@ -35,6 +35,7 @@
\item{\code{nls}:}{Object of class \code{"list"}: List returned by
\code{nlminb}.}
\item{\code{Z}:}{Object of class \code{"matrix"}: Transformation matrix.}
+ \item{\code{U}:}{Object of class \code{"matrix"}: Orthonormal matrix.}
\item{\code{Y}:}{Object of class \code{"matrix"}: Extracted
component matrix.}
\item{\code{H}:}{Object of class \code{"list"}: List of conditional
More information about the Gogarch-commits
mailing list