[Gogarch-commits] r7 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 25 14:17:42 CET 2009


Author: bpfaff
Date: 2009-01-25 14:17:42 +0100 (Sun, 25 Jan 2009)
New Revision: 7

Added:
   pkg/R/Goinit-class.R
   pkg/R/Goinit-show.R
   pkg/R/goinit.R
   pkg/man/Goinit-class.Rd
   pkg/man/goinit.Rd
   pkg/man/validGoinitObject.Rd
Modified:
   pkg/DESCRIPTION
   pkg/NAMESPACE
   pkg/R/Orthom-class.R
   pkg/R/Orthom-show.R
   pkg/man/Orthom-class.Rd
Log:
Goinit class added.


Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2009-01-25 13:14:02 UTC (rev 6)
+++ pkg/DESCRIPTION	2009-01-25 13:17:42 UTC (rev 7)
@@ -1,12 +1,13 @@
 Package: gogarch
-Version: 0.0-4
+Version: 0.0-8
 Type: Package
 Title: Generalized Orthogonal GARCH (GO-GARCH) models
-Date: 2009-01-22
+Date: 2009-01-23
 Author: Bernhard Pfaff
 Maintainer: Bernhard Pfaff <bernhard at pfaffikus.de>
 Depends: R (>= 2.7.0), methods, fGarch
+Suggests: vars
 Description: Implementation of the GO-GARCH model class. 
 License: GPL (>= 2)
 LazyLoad: yes
-Packaged: Thu Jan 22 17:27:27 2009; pfaffb
+Packaged: Fri Jan 23 17:47:00 2009; pfaffb

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2009-01-25 13:14:02 UTC (rev 6)
+++ pkg/NAMESPACE	2009-01-25 13:17:42 UTC (rev 7)
@@ -2,10 +2,10 @@
 import(methods)
 
 ## Functions
-export(gollh, Rd2, UprodR, unvech, validOrthomObject)
+export(goinit, gollh, Rd2, UprodR, unvech, validOrthomObject)
 
 ## Classes       
-exportClasses("Orthom")
+exportClasses("Goinit", "Orthom")
 
 ## Methods
-exportMethods("show")
+exportMethods("show", "print")

Added: pkg/R/Goinit-class.R
===================================================================
--- pkg/R/Goinit-class.R	                        (rev 0)
+++ pkg/R/Goinit-class.R	2009-01-25 13:17:42 UTC (rev 7)
@@ -0,0 +1,36 @@
+##
+## Validity function for objects of class Goinit
+##
+validGoinitObject <- function(object){
+  m <- nrow(object at V)
+  if(all.equal(diff(dim(object at V)), 0, check.attributes = FALSE)){
+    TRUE
+  } else {
+    stop("\nObject 'V' is not a square matrix.\n")
+  }
+  if(all.equal(diff(dim(object at P)), 0, check.attributes = FALSE)){
+    TRUE
+  } else {
+    stop("\nObject 'P' is not a square matrix.\n")
+  }
+  if(all.equal(diff(dim(object at Dsqr)), 0, check.attributes = FALSE)){
+    TRUE
+  } else {
+    stop("\nObject 'Dsqr' is not a square matrix.\n")
+  }
+  if(all.equal(det(object at Dsqr), prod(diag(object at Dsqr)), check.attributes = FALSE)){
+    TRUE
+  } else {
+    stop("\nObject 'Dsqr' is not a diagonal matrix.\n")
+  }  
+  if(all.equal(object at V, object at P %*% object at Dsqr^2 %*% t(object at P), check.attributes = FALSE)){ 
+    TRUE
+  } else {
+    stop("\nCovariance matrix cannot be replicated from singular values.\n")
+  }
+}
+##
+## Class definition of initial GO-GARCH objects
+##
+setClass(Class = "Goinit", representation(X = "matrix", V = "matrix", P = "matrix", Dsqr = "matrix", garchf = "formula"), validity = validGoinitObject)
+

Added: pkg/R/Goinit-show.R
===================================================================
--- pkg/R/Goinit-show.R	                        (rev 0)
+++ pkg/R/Goinit-show.R	2009-01-25 13:17:42 UTC (rev 7)
@@ -0,0 +1,26 @@
+setMethod(f = "show", signature = "Goinit", function(object){
+  title <- "*** Object of class Goinit ***"
+  stars <- paste(rep("*", nchar(title)), collapse = "")
+  cat("\n")
+  cat(paste(stars, "\n"))
+  cat(paste(title, "\n"))
+  cat(paste(stars, "\n"))  
+  cat("\n")
+  if(length(object at X) != 0){
+     cat("Head of data matrix X:\n")
+     print(head(object at X), quote = FALSE)
+     cat("\n")
+  } 
+  if(length(object at P) != 0){
+    cat("Projection matrix P:\n")
+    print(object at P, quote = FALSE)
+    cat("\n")
+  }
+  if(length(object at Dsqr) != 0){
+    cat("Square root of eigenvalues Dsqr:\n")
+    print(formatC(object at Dsqr), quote = FALSE)
+    cat("\n")
+  }
+  cat(paste("Formula for component GARCH models:\n", paste(as.character(object at garchf), collapse = " "), "\n"))
+}
+)

Modified: pkg/R/Orthom-class.R
===================================================================
--- pkg/R/Orthom-class.R	2009-01-25 13:14:02 UTC (rev 6)
+++ pkg/R/Orthom-class.R	2009-01-25 13:17:42 UTC (rev 7)
@@ -1,8 +1,4 @@
 ##
-## Class definition of orthogonal matrices
-##
-setClass("Orthom", representation(M = "matrix"))
-##
 ## Validity function for objects of class Orthom
 ##
 validOrthomObject <- function(object){
@@ -24,6 +20,7 @@
   }
 }
 ##
-## Setting validOrthomObject() as validity function
+## Class definition of orthogonal matrices
 ##
-setValidity("Orthom", validOrthomObject)
+setClass(Class = "Orthom", representation(M = "matrix"), validity = validOrthomObject)
+

Modified: pkg/R/Orthom-show.R
===================================================================
--- pkg/R/Orthom-show.R	2009-01-25 13:14:02 UTC (rev 6)
+++ pkg/R/Orthom-show.R	2009-01-25 13:17:42 UTC (rev 7)
@@ -1,4 +1,4 @@
 ##
-## show-method for objects of class orthom
+## show-method for objects of class Orthom
 ##
-setMethod("show", "Orthom", function(object) print(object at M))
+setMethod(f = "show", signature = "Orthom", function(object) print(object at M))

Added: pkg/R/goinit.R
===================================================================
--- pkg/R/goinit.R	                        (rev 0)
+++ pkg/R/goinit.R	2009-01-25 13:17:42 UTC (rev 7)
@@ -0,0 +1,16 @@
+goinit <- function(X, garchf = ~ garch(1, 1), scale = FALSE){
+  X <- as.matrix(X)
+  if(ncol(X) > nrow(X)){
+    stop("\nMatrix has more columns than rows.\n")
+  }
+  garchf <- as.formula(garchf)
+  if(scale){
+    X <- scale(X)
+  }
+  V <- t(X) %*% X / nrow(X)
+  svd <- svd(V)
+  P <- svd$u
+  Dsqr <- diag(sqrt(svd$d))
+  result <- new("Goinit", X = X, V = V, P = P, Dsqr = Dsqr, garchf = garchf)
+  return(result)
+}

Added: pkg/man/Goinit-class.Rd
===================================================================
--- pkg/man/Goinit-class.Rd	                        (rev 0)
+++ pkg/man/Goinit-class.Rd	2009-01-25 13:17:42 UTC (rev 7)
@@ -0,0 +1,52 @@
+\name{Goinit-class}
+
+\docType{class}
+
+\alias{Goinit-class}
+\alias{show,Goinit-method}
+
+\encoding{latin1}
+
+\title{Class "Goinit": Initialisation of GO-GARCH models}
+
+\description{This class defines the required slots for estimating
+  GO-GARCH models.}
+
+\section{Objects from the Class}{
+  Objects can be created by calls of the form \code{new("Goinit", ...)},
+  or more conveniently by \code{goinit()}. 
+}
+
+\section{Slots}{
+	 \describe{
+    \item{\code{X}:}{Object of class \code{"matrix"}: The data matrix.}
+    \item{\code{V}:}{Object of class \code{"matrix"}: Covariance matrix
+	 of \code{X}.}
+    \item{\code{P}:}{Object of class \code{"matrix"}: Left singular
+	 values of Var/Cov matrix of \code{X}.}
+    \item{\code{Dsqr}:}{Object of class \code{"matrix"}: Square roots of
+      eigenvalues on diagonal, else zero.}
+    \item{\code{garchf}:}{Object of class \code{"formula"}: Garch
+	 formula used for uncorrelated component GARCH models.}
+
+  }
+}
+
+\section{Methods}{
+  \describe{
+    \item{show}{Prints the slots, whereby for \code{X} only the head is
+  displayed.} 
+	 }
+}
+
+\author{Bernhard Pfaff}
+
+\seealso{
+  \code{\link[fGarch]{garchFit}}, \code{\link{goinit}} 
+}
+
+\examples{
+showClass("Goinit")
+}
+
+\keyword{classes}

Modified: pkg/man/Orthom-class.Rd
===================================================================
--- pkg/man/Orthom-class.Rd	2009-01-25 13:14:02 UTC (rev 6)
+++ pkg/man/Orthom-class.Rd	2009-01-25 13:17:42 UTC (rev 7)
@@ -4,6 +4,7 @@
 
 \alias{Orthom-class}
 \alias{show,Orthom-method}
+\alias{print,Orthom-method}
 
 \encoding{latin1}
 
@@ -28,7 +29,8 @@
 
 \section{Methods}{
   \describe{
-    \S4method{show}{print-method applied to \code{object at M}.}
+    \S4method{show}{show-method for objects of class \code{Orthom}.}
+    \S4method{print}{print-method for objects of class \code{Orthom}.}
   }
 }
 

Added: pkg/man/goinit.Rd
===================================================================
--- pkg/man/goinit.Rd	                        (rev 0)
+++ pkg/man/goinit.Rd	2009-01-25 13:17:42 UTC (rev 7)
@@ -0,0 +1,59 @@
+\name{goinit}
+
+\alias{goinit}
+
+\encoding{latin1}
+
+\title{
+  Constructor function for objects of class "Goinit"
+}
+\description{
+  This function can be utilized to create objects of class
+  \code{Goinit}. These objects are the starting point for estimating
+  GO-GARCH models.
+}
+\usage{
+goinit(X, garchf = ~garch(1, 1), scale = FALSE)
+}
+
+\arguments{
+  \item{X}{Matrix: the data matrix.}
+  \item{garchf}{Formula: A formula object that will be used in the GARCH
+  models of the uncorrelated components.}
+  \item{scale}{Logical, if \code{TRUE} the data \code{X} will be scaled,
+  the default value is \code{FALSE} for no scaling of the data.}
+}
+
+\details{
+  This function computes the variance/covariance matrix of
+  \code{X}. Next the singular value decomposition is applied and the
+  projection matrix as well as the diagonal matrix with the square roots
+  of the eigen values are computed.
+}
+
+\value{
+  An object of class \code{Goinit}.
+}
+
+\author{
+  Bernhard Pfaff
+}
+
+\seealso{
+  \code{\linkS4class{Goinit}}
+}
+
+\examples{
+\dontrun{
+library(vars)
+data(VDW)
+var1 <- VAR(VDW, p = 1, type = "const")
+resid <- resid(var1)
+goinit(resid, scale = TRUE)
+}
+}
+
+\keyword{models}
+\concept{GO-GARCH}
+\concept{SVD}
+\concept{Singular Value Decomposition}

Added: pkg/man/validGoinitObject.Rd
===================================================================
--- pkg/man/validGoinitObject.Rd	                        (rev 0)
+++ pkg/man/validGoinitObject.Rd	2009-01-25 13:17:42 UTC (rev 7)
@@ -0,0 +1,47 @@
+\name{validGoinitObject}
+
+\alias{validGoinitObject}
+
+\encoding{latin1}
+
+\title{
+  Validation function for objects of class Goinit
+}
+\description{
+  This function validates objects of class \code{Goinit}.
+}
+\usage{
+validGoinitObject(object)
+}
+
+\arguments{
+  \item{object}{Object of class \code{Goinit}.}
+}
+
+\details{
+  This function is utilized by \code{validObject()}. It is tested
+  whether \code{object at V}, \code{object at P}, \code{object at Dsqr} are
+  square matrices; \code{object at V} coincides with the singular value
+  decomposition. 
+%%  ~~ If necessary, more details than the description above ~~
+}
+\value{
+  \item{TRUE}{Logical, \code{TRUE} if the object passes the validation,
+  otherwise an informative error message is returned.}
+}
+
+\author{
+  Bernhard Pfaff
+}
+
+\seealso{
+  \code{\linkS4class{Goinit}}, \code{\link{goinit}} 
+}
+
+\examples{
+data(VDW)
+go <- goinit(VDW)
+validObject(go)
+}
+
+\keyword{utilities}



More information about the Gogarch-commits mailing list