Rev 1876 | Rev 1997 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
.onLoad <- function(lib, pkg) {if(is.null(getOption("max.print")))options(max.print = 10000)#-> show() of large matrices}## ------------- Virtual Classes ----------------------------------------## Mother class of all Matrix objectssetClass("Matrix",representation(Dim = "integer", Dimnames = "list", factors = "list","VIRTUAL"),prototype = prototype(Dim = integer(2), Dimnames = list(NULL,NULL)),validity = function(object) {Dim <- object@Dimif (length(Dim) != 2)return("Dim slot must be of length 2")if (any(Dim < 0))return("Dim slot must contain non-negative values")Dn <- object@Dimnamesif (!is.list(Dn) || length(Dn) != 2)return("'Dimnames' slot must be list of length 2")## 'else' ok :TRUE})setClass("symmetricMatrix",representation(uplo = "character", "VIRTUAL"),contains = "Matrix")setClass("triangularMatrix",representation(uplo = "character", diag = "character","VIRTUAL"), contains = "Matrix")## Virtual class of numeric matricessetClass("dMatrix",representation(x = "numeric", "VIRTUAL"), contains = "Matrix")## Virtual class of integer matricessetClass("iMatrix",representation(x = "integer", "VIRTUAL"), contains = "Matrix")## Virtual class of logical matricessetClass("lMatrix", representation("VIRTUAL"), contains = "Matrix")## Note that logical sparse matrices do not need an x slot so the x## slot is part of the ldenseMatrix class## Virtual class of complex matricessetClass("zMatrix", # letter 'z' is as in the names of Lapack subroutinesrepresentation(x = "complex", "VIRTUAL"), contains = "Matrix")## Virtual class of dense matricessetClass("denseMatrix", representation("VIRTUAL"),contains = "Matrix")## Virtual class of dense, numeric matricessetClass("ddenseMatrix", representation(rcond = "numeric", "VIRTUAL"),contains = c("dMatrix", "denseMatrix"))## Virtual class of dense, logical matricessetClass("ldenseMatrix", representation(x = "logical", "VIRTUAL"),contains = c("lMatrix", "denseMatrix"))## virtual SPARSE ------------setClass("sparseMatrix", representation("VIRTUAL"), contains = "Matrix")## sparse matrices in Triplet representation (dgT, lgT, ..):setClass("TsparseMatrix", representation(i = "integer", j = "integer", "VIRTUAL"),contains = "sparseMatrix")setClass("CsparseMatrix", representation(i = "integer", p = "integer", "VIRTUAL"),contains = "sparseMatrix")setClass("RsparseMatrix", representation(p = "integer", j = "integer", "VIRTUAL"),contains = "sparseMatrix")setClass("dsparseMatrix", representation("VIRTUAL"),contains = c("dMatrix", "sparseMatrix"))setClass("lsparseMatrix", representation("VIRTUAL"),contains = c("lMatrix", "sparseMatrix"))## ------------------ Proper (non-virtual) Classes ----------------------------##---------------------- DENSE -----------------------------------------## numeric, dense, general matricessetClass("dgeMatrix", contains = "ddenseMatrix",## checks that length( @ x) == prod( @ Dim):validity = function(object) .Call("dgeMatrix_validate", object))## i.e. "dgeMatrix" cannot be packed, but "ddenseMatrix" can ..## numeric, dense, non-packed, triangular matricessetClass("dtrMatrix",## FIXME?##> 'ddense*' before 'dge*' so it can use d* or ddense* methods##> WITHOUT a coerce to dge* (losing triangularity)##> gives error from callNextMethod() in crossprod() dispatch {R bug?}##> contains = c("ddenseMatrix", "dgeMatrix", "triangularMatrix"),contains = c("dgeMatrix", "triangularMatrix"),prototype = prototype(uplo = "U", diag = "N"),validity = function(object) .Call("dtrMatrix_validate", object))## numeric, dense, packed, triangular matricessetClass("dtpMatrix",contains = c("ddenseMatrix", "triangularMatrix"),prototype = prototype(uplo = "U", diag = "N"),validity = function(object) .Call("dtpMatrix_validate", object))## numeric, dense, non-packed symmetric matricessetClass("dsyMatrix",## FIXME?##> 'ddense*' before 'dge*' so it can use d* or ddense* methods##> WITHOUT a coerce to dge* (losing triangularity)##> gives error in crossprod() dispatch##> contains = c("ddenseMatrix", "dgeMatrix", "symmetricMatrix"),contains = c("dgeMatrix", "symmetricMatrix"),prototype = prototype(uplo = "U"),validity = function(object) .Call("dsyMatrix_validate", object))## numeric, dense, packed symmetric matricessetClass("dspMatrix",prototype = prototype(uplo = "U"),contains = c("ddenseMatrix", "symmetricMatrix"),validity = function(object) .Call("dspMatrix_validate", object))## numeric, dense, non-packed, positive-definite, symmetric matricessetClass("dpoMatrix", contains = "dsyMatrix",validity = function(object) .Call("dpoMatrix_validate", object))## numeric, dense, packed, positive-definite, symmetric matricessetClass("dppMatrix", contains = "dspMatrix",validity = function(object) .Call("dppMatrix_validate", object))##----- logical dense Matrices -- e.g. as result of <ddenseMatrix> COMPARISON## numeric, dense, general matricessetClass("lgeMatrix", contains = "ldenseMatrix",## checks that length( @ x) == prod( @ Dim):validity = function(object) stopifnot(length(object@x) == prod(object@Dim)))## i.e. "lgeMatrix" cannot be packed, but "ldenseMatrix" can ..## numeric, dense, non-packed, triangular matricessetClass("ltrMatrix",contains = c("lgeMatrix", "triangularMatrix"),prototype = prototype(uplo = "U", diag = "N"))## numeric, dense, packed, triangular matricessetClass("ltpMatrix",contains = c("ldenseMatrix", "triangularMatrix"),prototype = prototype(uplo = "U", diag = "N")## validity: ldense*, triangular* should suffice)## numeric, dense, non-packed symmetric matricessetClass("lsyMatrix",contains = c("lgeMatrix", "symmetricMatrix"),prototype = prototype(uplo = "U")##, validity = function(object) .Call("lsyMatrix_validate", object))## numeric, dense, packed symmetric matricessetClass("lspMatrix",prototype = prototype(uplo = "U"),contains = c("ldenseMatrix", "symmetricMatrix"),validity = function(object) .Call("dspMatrix_validate", object)## "dsp" and "lsp" have the same validate)##-------------------- S P A R S E (non-virtual) --------------------------##---------- numeric sparse matrix classes --------------------------------## numeric, sparse, triplet general matricessetClass("dgTMatrix",contains = c("TsparseMatrix", "dsparseMatrix"),validity = function(object) .Call("dgTMatrix_validate", object))## Should not have dtTMatrix inherit from dgTMatrix because a dtTMatrix could## be less than fully stored if diag = "U". Methods for the dgTMatrix## class would not produce correct results even though all the slots## are present.## numeric, sparse, triplet triangular matricessetClass("dtTMatrix",contains = c("TsparseMatrix", "dsparseMatrix", "triangularMatrix"),prototype = prototype(uplo = "U", diag = "N"),validity = function(object) .Call("dtTMatrix_validate", object))## Should not have dsTMatrix inherit from dgTMatrix because a dsTMatrix## is not fully stored. Methods for the dgTMatrix class would not## produce correct results even though all the slots are present.## numeric, sparse, triplet symmetric matricessetClass("dsTMatrix",contains = c("TsparseMatrix", "dsparseMatrix", "symmetricMatrix"),prototype = prototype(uplo = "U"),validity = function(object) .Call("dsTMatrix_validate", object))## numeric, sparse, sorted compressed sparse column-oriented general matricessetClass("dgCMatrix",contains = c("CsparseMatrix", "dsparseMatrix"),prototype = prototype(p = 0:0),# to be validvalidity = function(object) .Call("dgCMatrix_validate", object))## see comments for dtTMatrix above## numeric, sparse, sorted compressed sparse column-oriented triangular matricessetClass("dtCMatrix",contains = c("CsparseMatrix", "dsparseMatrix", "triangularMatrix"),prototype = prototype(p = 0:0, uplo = "U", diag = "N"),# to be validvalidity = function(object) .Call("tsc_validate", object))## see comments for dsTMatrix above## numeric, sparse, sorted compressed sparse column-oriented symmetric matricessetClass("dsCMatrix",contains = c("CsparseMatrix", "dsparseMatrix", "symmetricMatrix"),prototype = prototype(p = 0:0, uplo = "U"),# to be validvalidity = function(object) .Call("dsCMatrix_validate", object))## numeric, sparse, sorted compressed sparse row-oriented general matricessetClass("dgRMatrix",representation(j = "integer", p = "integer"),contains = "dsparseMatrix",##TODO: validity = function(object) .Call("dgRMatrix_validate", object))## numeric, sparse, sorted compressed sparse row-oriented triangular matricessetClass("dtRMatrix",contains = c("dgRMatrix", "triangularMatrix"),##TODO: validity = function(object) .Call("dtRMatrix_validate", object))## numeric, sparse, sorted compressed sparse row-oriented symmetric matricessetClass("dsRMatrix",contains = c("dgRMatrix", "symmetricMatrix"),##TODO: validity = function(object) .Call("dsRMatrix_validate", object))##---------- logical sparse matrix classes --------------------------------## these classes are used in symbolic analysis to determine the## locations of non-zero entries## logical, sparse, triplet general matricessetClass("lgTMatrix",contains = c("TsparseMatrix", "lsparseMatrix"),validity = function(object) .Call("lgTMatrix_validate", object))## logical, sparse, triplet triangular matricessetClass("ltTMatrix",contains = c("TsparseMatrix", "lsparseMatrix", "triangularMatrix"),validity = function(object) .Call("ltTMatrix_validate", object))## logical, sparse, triplet symmetric matricessetClass("lsTMatrix",contains = c("TsparseMatrix", "lsparseMatrix", "symmetricMatrix"),validity = function(object) .Call("lsTMatrix_validate", object))## logical, sparse, sorted compressed sparse column-oriented general matricessetClass("lgCMatrix",contains = c("lsparseMatrix", "CsparseMatrix"),prototype = prototype(p = 0:0),# to be validvalidity = function(object) .Call("lgCMatrix_validate", object))## logical, sparse, sorted compressed sparse column-oriented triangular matricessetClass("ltCMatrix",contains = c("lsparseMatrix", "CsparseMatrix", "triangularMatrix"),prototype = prototype(p = 0:0, uplo = "U", diag = "N"),# to be validvalidity = function(object) .Call("ltCMatrix_validate", object))## logical, sparse, sorted compressed sparse column-oriented symmetric matricessetClass("lsCMatrix",contains = c("lsparseMatrix", "CsparseMatrix", "symmetricMatrix"),prototype = prototype(p = 0:0, uplo = "U"),# to be validvalidity = function(object) .Call("lsCMatrix_validate", object))## logical, sparse, sorted compressed sparse row-oriented general matricessetClass("lgRMatrix",representation(j = "integer", p = "integer"),contains = "lsparseMatrix",validity = function(object) .Call("lgRMatrix_validate", object))## logical, sparse, sorted compressed sparse row-oriented triangular matricessetClass("ltRMatrix",contains = c("lgRMatrix", "triangularMatrix"),validity = function(object) .Call("ltRMatrix_validate", object))## logical, sparse, sorted compressed sparse row-oriented symmetric matricessetClass("lsRMatrix",contains = c("lgRMatrix", "symmetricMatrix"),validity = function(object) .Call("lsRMatrix_validate", object))## Compressed sparse column matrix in blockssetClass("dgBCMatrix",representation(p = "integer", i = "integer", x = "array"))## Factorization classessetClass("Cholesky", contains = "dtrMatrix")setClass("pCholesky", contains = "dtpMatrix")setClass("BunchKaufman", representation(perm = "integer"), contains = "dtrMatrix",validity = function(object) .Call("BunchKaufman_validate", object));setClass("pBunchKaufman", representation(perm = "integer"), contains = "dtpMatrix",validity = function(object) .Call("pBunchKaufman_validate", object));setClass("dCholCMatrix",representation(perm = "integer", Parent = "integer", D = "numeric"),contains = "dtCMatrix",validity = function(object) .Call("dCholCMatrix_validate", object))setClass("lCholCMatrix",representation(perm = "integer", Parent = "integer"),contains = "ltCMatrix",validity = function(object) .Call("lCholCMatrix_validate", object))##-------------------- permutation ----------------------------------------setClass("pMatrix", representation(perm = "integer"),contains = "sparseMatrix",validity = function(object) {d <- object@Dimif (d[2] != (n <- d[1])) return("pMatrix must be square")perm <- object@permif (length(perm) != n)return(paste("length of 'perm' slot must be", n))if(n > 0 &&!(all(range(perm) == c(1, n)) && length(unique(perm)) == n))return("'perm' slot is not a valid permutation")TRUE})### Class Union : no inheritance, but is(*, <class>) :setClassUnion("packedMatrix",members = c("dspMatrix", "dppMatrix", "dtpMatrix","lspMatrix", "ltpMatrix"))## --------------------- non-"Matrix" Classes --------------------------------## --- "General" (not Matrix at all) ----## for 'i' in x[i] or A[i,] :setClassUnion("index", members = c("numeric", "logical", "character"))## --- Matrix - related ----setClass("determinant",representation(modulus = "numeric",logarithm = "logical",sign = "integer",call = "call"))setClass("LU", representation(x = "numeric",perm = "integer"),validity = function(object) .Call("LU_validate", object))## Deprecated:## positive-definite symmetric matrices as matricessetClass("pdmatrix", contains = "matrix")## # factors of positive-definite symmetric matrices## setClass("pdfactor", representation("matrix", logDet = "numeric"))## correlation matrices and standard deviationssetClass("corrmatrix", representation("matrix", stdDev = "numeric"))## -------------------- lmer-related Classes --------------------------------setOldClass("data.frame")setOldClass("family")setOldClass("logLik")setOldClass("terms")setClass("VarCorr",representation(scale = "numeric",reSumry = "list",useScale = "logical"),prototype = list(scale = 1.0, useScale = TRUE))## mixed effects representationsetClass("mer",representation(flist = "list", # list of grouping factorsperm = "list", # list of permutations of levels (0-based)Parent = "list",# list of Parent arrays for ZZpOD = "list", # list of diagonal factors (upper triangle)bVar = "list", # list of conditional variance factors (upper triangle)L = "list", # list of blocks of LZZpO = "list", # list of diagonal blocks of Z'Z+OmegaOmega = "list", # list of relative precision matricesmethod = "character", # parameter estimation methodRXX = "matrix", # Augmented RXX component or its inverseRZX = "matrix", # Augmented RZX component or its inverseXtX = "matrix", # Original X'X matrixZtZ = "list", # list of blocks of Z'ZZtX = "matrix", # Original Z'X matrixcnames = "list",# column names of model matricesdevComp = "numeric", # Components of deviancedeviance = "numeric", # Current deviance (ML and REML)nc = "integer", # number of columns in (augmented)## model matrices and number of observationsGp = "integer", # Pointers to groups of rows in RZXstatus = "logical"),validity = function(object) {.Call("lmer_validate", object, PACKAGE = "Matrix")})setClass("mer2",representation(flist = "list", # list of grouping factorsL = "list", # lower Cholesky factor of Z'Z + OmegaRXX = "dtrMatrix", # RXX componentRZX = "dgeMatrix", # RZX componentXtX = "dpoMatrix", # Original X'X matrixZtZ = "dsCMatrix", # Original Z'ZZtX = "dgeMatrix", # Original Z'X matrixZty = "numeric", # Original Z'y vectorXty = "numeric", # Original X'y vectorrZy = "numeric",rXy = "numeric",Omega = "list", # list of relative precision matricesmethod = "character", # parameter estimation methodcnames = "list",# column names of model matricesdevComp = "numeric", # Components of deviancedeviance = "numeric", # Current deviance (ML and REML)nc = "integer", # number of columns in (augmented)# model matrices and number of observationsGp = "integer", # Pointers to groups of rows in RZXstatus = "logical"))## Representation of a linear or generalized linear mixed effects modelsetClass("lmer",representation(assign = "integer", call = "call",family = "family", fitted = "numeric",fixed = "numeric", frame = "data.frame",logLik = "logLik", residuals = "numeric",terms = "terms"),contains = "mer")## Representation of a generalized linear mixed effects model##setClass("glmer",## representation(family = "family", glmmll = "numeric", fixed = "numeric"),## contains = "lmer")setClass("summary.lmer",representation(useScale = "logical",showCorrelation = "logical"),contains = "lmer")setClass("lmer.ranef",representation(varFac = "list", stdErr = "numeric"),contains = "list")setClass("lmer.ranef.confint", contains = "list")setClass("lmer.coef",representation(varFac = "list", stdErr = "numeric"),contains = "list")