R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("Matrix-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('Matrix') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "Cholesky-class" > > ### * Cholesky-class > > flush(stderr()); flush(stdout()) > > ### Name: Cholesky-class > ### Title: Cholesky and Bunch-Kaufman Decompositions > ### Aliases: Cholesky-class pCholesky-class BunchKaufman-class > ### pBunchKaufman-class > ### Keywords: classes algebra > > ### ** Examples > > (pm <- crossprod(Matrix(rnorm(18), nrow = 6, ncol = 3))) 3 x 3 Matrix of class "dpoMatrix" [,1] [,2] [,3] [1,] 4.4511090 -0.9597934 -1.8089651 [2,] -0.9597934 3.6449567 -0.9330699 [3,] -1.8089651 -0.9330699 7.4494130 > (ch <- chol(pm)) 3 x 3 Matrix of class "Cholesky" [,1] [,2] [,3] [1,] 2.109765 -0.454929 -0.8574249 [2,] 0.000000 1.854183 -0.7135957 [3,] 0.000000 0.000000 2.4909871 > if (toupper(ch@uplo) == "U") # which is TRUE + crossprod(ch) 3 x 3 Matrix of class "dpoMatrix" [,1] [,2] [,3] [1,] 4.4511090 -0.9597934 -1.8089651 [2,] -0.9597934 3.6449567 -0.9330699 [3,] -1.8089651 -0.9330699 7.4494130 > stopifnot(all.equal(as(crossprod(ch), "matrix"), + as(pm, "matrix"), tol=1e-14)) > > > > cleanEx(); ..nameEx <- "Hilbert" > > ### * Hilbert > > flush(stderr()); flush(stdout()) > > ### Name: Hilbert > ### Title: Generate a Hilbert matrix > ### Aliases: Hilbert > ### Keywords: array algebra > > ### ** Examples > > Hilbert(6) 6 x 6 Matrix of class "dpoMatrix" [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 [2,] 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 [3,] 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 [4,] 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 [5,] 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 [6,] 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 > > > > cleanEx(); ..nameEx <- "LU-class" > > ### * LU-class > > flush(stderr()); flush(stdout()) > > ### Name: LU-class > ### Title: LU Matrix Decompositions > ### Aliases: LU-class expand,LU-method > ### Keywords: classes algebra > > ### ** Examples > > mm <- Matrix(round(rnorm(9),2), nrow = 3, ncol = 3) > mm 3 x 3 Matrix of class "dgeMatrix" [,1] [,2] [,3] [1,] -0.63 1.60 0.49 [2,] 0.18 0.33 0.74 [3,] -0.84 -0.82 0.58 > str(lum <- lu(mm)) Formal class 'LU' [package "Matrix"] with 2 slots ..@ x : num [1:9] -0.840 0.750 -0.214 -0.820 2.215 ... ..@ perm: int [1:3] 3 3 3 > elu <- expand(lum) > elu $L 3 x 3 Matrix of class "dgeMatrix" [,1] [,2] [,3] [1,] 1.0000000 0.00000000 0 [2,] 0.7500000 1.00000000 0 [3,] -0.2142857 0.06965495 1 $U 3 x 3 Matrix of class "dgeMatrix" [,1] [,2] [,3] [1,] -0.84 -0.820 0.5800000 [2,] 0.00 2.215 0.0550000 [3,] 0.00 0.000 0.8604547 $P 3 x 3 Matrix of class "pMatrix" [,1] [,2] [,3] [1,] 0 1 0 [2,] 0 0 1 [3,] 1 0 0 > elu$L %*% elu$U 3 x 3 Matrix of class "dgeMatrix" [,1] [,2] [,3] [1,] -0.84 -0.82 0.58 [2,] -0.63 1.60 0.49 [3,] 0.18 0.33 0.74 > > > > cleanEx(); ..nameEx <- "Matrix" > > ### * Matrix > > flush(stderr()); flush(stdout()) > > ### Name: Matrix > ### Title: Construct a Classed Matrix > ### Aliases: Matrix > ### Keywords: array algebra > > ### ** Examples > > Matrix(0, 3, 2) # a 3 by 2 matrix of zeros 3 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] 0 0 [2,] 0 0 [3,] 0 0 > Matrix(1:6, 3, 2) # a 3 by 2 matrix 3 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 > Matrix(1:6, nrow=3) 3 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 > Matrix(1:6, ncol=2) 3 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 > Matrix(1:9, nrow=3, + dimnames = list(c("a", "b", "c"), c("A", "B", "C"))) 3 x 3 Matrix of class "dgeMatrix" A B C a 1 4 7 b 2 5 8 c 3 6 9 > > > > cleanEx(); ..nameEx <- "Schur" > > ### * Schur > > flush(stderr()); flush(stdout()) > > ### Name: Schur > ### Title: Schur Decomposition of a Matrix > ### Aliases: Schur Schur,dgeMatrix,logical-method > ### Schur,dgeMatrix,missing-method Schur,ddenseMatrix,logical-method > ### Schur,ddenseMatrix,missing-method > ### Keywords: algebra > > ### ** Examples > > Schur(Hilbert(9)) # Schur factorization (real eigenvalues) $WR [1] 1.725883e+00 3.216331e-01 3.103893e-02 1.978934e-03 8.758085e-05 [6] 2.673013e-06 5.385613e-08 6.460905e-10 3.499686e-12 $WI [1] 0 0 0 0 0 0 0 0 0 $T [,1] [,2] [,3] [,4] [,5] [1,] 1.725883 -8.838711e-17 -9.209102e-17 -3.691953e-17 8.715622e-18 [2,] 0.000000 3.216331e-01 6.201553e-17 4.849090e-17 1.140026e-17 [3,] 0.000000 0.000000e+00 3.103893e-02 3.623390e-18 -1.203632e-17 [4,] 0.000000 0.000000e+00 0.000000e+00 1.978934e-03 -4.821162e-18 [5,] 0.000000 0.000000e+00 0.000000e+00 0.000000e+00 8.758085e-05 [6,] 0.000000 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 [7,] 0.000000 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 [8,] 0.000000 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 [9,] 0.000000 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 [,6] [,7] [,8] [,9] [1,] -1.215402e-17 1.625908e-18 2.445276e-17 8.671224e-18 [2,] 7.053257e-18 -4.456591e-18 -1.780442e-17 -1.220396e-18 [3,] -1.849371e-17 -4.746535e-18 -6.077071e-18 4.933090e-18 [4,] -1.849532e-17 -2.227903e-18 7.826424e-19 3.723369e-18 [5,] -5.450015e-18 -6.872636e-19 -2.453266e-18 -5.719701e-20 [6,] 2.673013e-06 1.121956e-18 2.834097e-18 3.948825e-18 [7,] 0.000000e+00 5.385613e-08 -1.805502e-18 1.279404e-19 [8,] 0.000000e+00 0.000000e+00 6.460905e-10 -1.491291e-18 [9,] 0.000000e+00 0.000000e+00 0.000000e+00 3.499686e-12 $Z [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.7091817 0.63411890 0.29150563 0.09654587 0.02509744 0.005224405 [2,] 0.4290994 -0.09547484 -0.62126159 -0.56574091 -0.29718372 -0.107648322 [3,] 0.3179060 -0.25768723 -0.36113842 0.26290950 0.60646687 0.465721999 [4,] 0.2554416 -0.30295702 -0.10458213 0.43898728 0.08575865 -0.495332526 [5,] 0.2146560 -0.31134174 0.07804869 0.32718380 -0.32141465 -0.282373552 [6,] 0.1856468 -0.30599625 0.20198227 0.12522530 -0.39722099 0.216365380 [7,] 0.1638323 -0.29532381 0.28533408 -0.08708961 -0.22555349 0.424545808 [8,] 0.1467699 -0.28278221 0.34115205 -0.28063056 0.08749818 0.194400829 [9,] 0.1330265 -0.26989403 0.37816853 -0.44689612 0.46505176 -0.426091101 [,7] [,8] [,9] [1,] 0.0008620699 0.0001078102 -8.936307e-06 [2,] -0.0281988594 -0.0052559005 6.197802e-04 [3,] 0.2107961543 0.0612017719 -1.053480e-02 [4,] -0.5489968847 -0.2819875020 7.547180e-02 [5,] 0.3885427422 0.5768471862 -2.776472e-01 [6,] 0.3476433685 -0.4086211268 5.683289e-01 [7,] -0.2535560341 -0.2714694097 -6.540970e-01 [8,] -0.4521777108 0.5447688462 3.958146e-01 [9,] 0.3358493180 -0.2156782744 -9.795376e-02 > A <- Matrix(rnorm( 9*9, sd = 100), nrow = 9) > schur.A <- Schur(A) > #mod.eig <- Mod(schur.A$values) # eigenvalue modulus > #schur.A > > > > cleanEx(); ..nameEx <- "VarCorr" > > ### * VarCorr > > flush(stderr()); flush(stdout()) > > ### Name: VarCorr > ### Title: Extract variance and correlation components > ### Aliases: VarCorr > ### Keywords: models > > ### ** Examples > > (fm1 <- lmer(decrease ~ treatment + (1|rowpos) + (1|colpos), + OrchardSprays)) Linear mixed-effects model fit by REML Formula: decrease ~ treatment + (1 | rowpos) + (1 | colpos) Data: OrchardSprays AIC BIC logLik MLdeviance REMLdeviance 534.7596 558.5073 -256.3798 558.4304 512.7596 Random effects: Groups Name Variance Std.Dev. rowpos (Intercept) 37.5295 6.1261 colpos (Intercept) 2.5252 1.5891 Residual 380.8313 19.5149 # of obs: 64, groups: rowpos, 8; colpos, 8 Fixed effects: Estimate Std. Error DF t value Pr(>|t|) (Intercept) 4.6250 7.2533 56 0.6376 0.526308 treatmentB 3.0000 9.7574 56 0.3075 0.759636 treatmentC 20.6250 9.7574 56 2.1138 0.039002 * treatmentD 30.3750 9.7574 56 3.1130 0.002915 ** treatmentE 58.5000 9.7574 56 5.9954 1.546e-07 *** treatmentF 64.3750 9.7574 56 6.5975 1.597e-08 *** treatmentG 63.8750 9.7574 56 6.5463 1.939e-08 *** treatmentH 85.6250 9.7574 56 8.7753 4.170e-12 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > VarCorr(fm1) Groups Name Variance Std.Dev. rowpos (Intercept) 37.5295 6.1261 colpos (Intercept) 2.5252 1.5891 Residual 380.8313 19.5149 > > > > cleanEx(); ..nameEx <- "Xtrct-methods" > > ### * Xtrct-methods > > flush(stderr()); flush(stdout()) > > ### Name: [-methods > ### Title: Methods for "[": Extraction or Subsetting in Package 'Matrix'. > ### Aliases: [-methods [,dgTMatrix,missing,missing,ANY-method > ### [,dgTMatrix,missing,numeric,logical-method > ### [,dgTMatrix,missing,numeric,missing-method > ### [,dgTMatrix,numeric,missing,logical-method > ### [,dgTMatrix,numeric,missing,missing-method > ### [,dgTMatrix,numeric,numeric,logical-method > ### [,dgTMatrix,numeric,numeric,missing-method > ### [,dsparseMatrix,missing,missing,ANY-method > ### [,dsparseMatrix,missing,numeric,logical-method > ### [,dsparseMatrix,missing,numeric,missing-method > ### [,dsparseMatrix,numeric,missing,logical-method > ### [,dsparseMatrix,numeric,missing,missing-method > ### [,dsparseMatrix,numeric,numeric,logical-method > ### [,dsparseMatrix,numeric,numeric,missing-method > ### Keywords: methods array > > ### ** Examples > > str(m <- Matrix(round(rnorm(7*4),2), nrow = 7)) Formal class 'dgeMatrix' [package "Matrix"] with 5 slots ..@ rcond : num(0) ..@ factors : list() ..@ x : num [1:28] -0.63 0.18 -0.84 1.6 0.33 -0.82 0.49 0.74 0.58 -0.31 ... ..@ Dim : int [1:2] 7 4 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > ## wrongly looses class: m[]; error: m[1,1] > > ## Don't show: > if(FALSE) {## still all fail + ch[2,3] + ch[1,] + ch[,2] + pm[2,3] + pm[1,] + pm[,2] + } > ## End Don't show > > > > cleanEx(); ..nameEx <- "bCrosstab" > > ### * bCrosstab > > flush(stderr()); flush(stdout()) > > ### Name: bCrosstab > ### Title: Create pairwise crosstabulation > ### Aliases: bCrosstab > ### Keywords: manip algebra > > ### ** Examples > > str(esoph) `data.frame': 88 obs. of 5 variables: $ agegp : Ord.factor w/ 6 levels "25-34"<"35-44"<..: 1 1 1 1 1 1 1 1 1 1 ... $ alcgp : Ord.factor w/ 4 levels "0-39g/day"<"40-79"<..: 1 1 1 1 2 2 2 2 3 3 ... $ tobgp : Ord.factor w/ 4 levels "0-9g/day"<"10-19"<..: 1 2 3 4 1 2 3 4 1 2 ... $ ncases : num 0 0 0 0 0 0 0 0 0 0 ... $ ncontrols: num 40 10 6 5 27 7 4 7 2 1 ... > bCrosstab(with(esoph,list(agegp, alcgp))) $ ctab $"V1:V1" 6 x 6 sparse Matrix of class "dsCMatrix" [1,] 15 . . . . . [2,] . 15 . . . . [3,] . . 16 . . . [4,] . . . 16 . . [5,] . . . . 15 . [6,] . . . . . 11 $"V2:V1" 4 x 6 sparse Matrix of class "dgCMatrix" [1,] 4 4 4 4 4 3 [2,] 4 4 4 4 3 4 [3,] 3 4 4 4 4 2 [4,] 4 3 4 4 4 2 $"V2:V2" 4 x 4 sparse Matrix of class "dsCMatrix" [1,] 23 . . . [2,] . 23 . . [3,] . . 21 . [4,] . . . 21 > > grps <- with(esoph, list(age = agegp, alc = alcgp, tob = tobgp)) > bCn <- bCrosstab( grps, reorder = FALSE) > stopifnot(all.equal(bCn$flist, grps)) > str(bC <- bCrosstab(grps)) List of 2 $ flist:List of 3 ..$ age: Ord.factor w/ 6 levels "25-34"<"35-44"<..: 1 1 1 1 1 1 1 1 1 1 ... ..$ tob: Ord.factor w/ 4 levels "0-9g/day"<"10-19"<..: 1 2 3 4 1 2 3 4 1 2 ... ..$ alc: Ord.factor w/ 4 levels "0-39g/day"<"40-79"<..: 1 1 1 1 2 2 2 2 3 3 ... $ ctab :List of 6 ..$ age:age:Formal class 'dsCMatrix' [package "Matrix"] with 7 slots .. .. ..@ uplo : chr "U" .. .. ..@ i : int [1:6] 0 1 2 3 4 5 .. .. ..@ p : int [1:7] 0 1 2 3 4 5 6 .. .. ..@ factors : list() .. .. ..@ x : num [1:6] 15 15 16 16 15 11 .. .. ..@ Dim : Named int [1:2] 6 6 .. .. .. ..- attr(*, "names")= chr [1:2] "age" "age" .. .. ..@ Dimnames:List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : NULL ..$ tob:age:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots .. .. ..@ i : int [1:24] 0 1 2 3 0 1 2 3 0 1 ... .. .. ..@ p : int [1:7] 0 4 8 12 16 20 24 .. .. ..@ factors : list() .. .. ..@ x : num [1:24] 4 4 3 4 4 4 4 3 4 4 ... .. .. ..@ Dim : Named int [1:2] 4 6 .. .. .. ..- attr(*, "names")= chr [1:2] "tob" "age" .. .. ..@ Dimnames:List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : NULL ..$ tob:tob:Formal class 'dsCMatrix' [package "Matrix"] with 7 slots .. .. ..@ uplo : chr "U" .. .. ..@ i : int [1:4] 0 1 2 3 .. .. ..@ p : int [1:5] 0 1 2 3 4 .. .. ..@ factors : list() .. .. ..@ x : num [1:4] 24 24 20 20 .. .. ..@ Dim : Named int [1:2] 4 4 .. .. .. ..- attr(*, "names")= chr [1:2] "tob" "tob" .. .. ..@ Dimnames:List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : NULL ..$ alc:age:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots .. .. ..@ i : int [1:24] 0 1 2 3 0 1 2 3 0 1 ... .. .. ..@ p : int [1:7] 0 4 8 12 16 20 24 .. .. ..@ factors : list() .. .. ..@ x : num [1:24] 4 4 3 4 4 4 4 3 4 4 ... .. .. ..@ Dim : Named int [1:2] 4 6 .. .. .. ..- attr(*, "names")= chr [1:2] "alc" "age" .. .. ..@ Dimnames:List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : NULL ..$ alc:tob:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots .. .. ..@ i : int [1:16] 0 1 2 3 0 1 2 3 0 1 ... .. .. ..@ p : int [1:5] 0 4 8 12 16 .. .. ..@ factors : list() .. .. ..@ x : num [1:16] 6 6 6 6 6 6 6 6 5 6 ... .. .. ..@ Dim : Named int [1:2] 4 4 .. .. .. ..- attr(*, "names")= chr [1:2] "alc" "tob" .. .. ..@ Dimnames:List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : NULL ..$ alc:alc:Formal class 'dsCMatrix' [package "Matrix"] with 7 slots .. .. ..@ uplo : chr "U" .. .. ..@ i : int [1:4] 0 1 2 3 .. .. ..@ p : int [1:5] 0 1 2 3 4 .. .. ..@ factors : list() .. .. ..@ x : num [1:4] 23 23 21 21 .. .. ..@ Dim : Named int [1:2] 4 4 .. .. .. ..- attr(*, "names")= chr [1:2] "alc" "alc" .. .. ..@ Dimnames:List of 2 .. .. .. ..$ : NULL .. .. .. ..$ : NULL > bC$ctab$"alc:age" # generally 4 obs. per cell, but not always: 4 x 6 sparse Matrix of class "dgCMatrix" [1,] 4 4 4 4 4 3 [2,] 4 4 4 4 3 4 [3,] 3 4 4 4 4 2 [4,] 4 3 4 4 4 2 > aa.m <- as(bC$ctab$"alc:age", "matrix") > table(aa.m) # #(2,3,4) = (2, 4, 18) aa.m 2 3 4 2 4 18 > stopifnot(all.equal(as.vector(t(aa.m)), + as.vector(table(with(esoph, alcgp:agegp))), tol=0)) > > > > cleanEx(); ..nameEx <- "corrmatrix-class" > > ### * corrmatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: corrmatrix-class > ### Title: Class "corrmatrix" > ### Aliases: corrmatrix-class coerce,pdIdent,corrmatrix-method > ### coerce,pdMat,corrmatrix-method coerce,pdNatural,corrmatrix-method > ### coerce<-,pdNatural,corrmatrix-method > ### coerce,pdmatrix,corrmatrix-method > ### Keywords: classes > > ### ** Examples > > > > > cleanEx(); ..nameEx <- "dCholCMatrix-class" > > ### * dCholCMatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: dCholCMatrix-class > ### Title: Cholesky Decompositions of dsCMatrix Objects > ### Aliases: dCholCMatrix-class lCholCMatrix-class > ### solve,lCholCMatrix,missing-method solve,lCholCMatrix,lgCMatrix-method > ### t,lCholCMatrix-method > ### Keywords: classes algebra > > ### ** Examples > > data(mm) > xpx <- crossprod(mm) > str(xpx) Formal class 'dsCMatrix' [package "Matrix"] with 7 slots ..@ uplo : chr "L" ..@ i : int [1:4902] 0 257 261 280 419 421 426 427 431 449 ... ..@ p : int [1:713] 0 16 22 36 55 63 76 82 90 101 ... ..@ factors : list() ..@ x : num [1:4902] 1.0000 0.2774 0.1961 0.2774 0.0958 ... ..@ Dim : int [1:2] 712 712 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > str(ch <- chol(xpx)) Formal class 'dCholCMatrix' [package "Matrix"] with 11 slots ..@ perm : int [1:712] 579 39 38 578 583 46 80 599 48 585 ... ..@ Parent : int [1:712] 1 62 3 62 5 24 7 118 9 76 ... ..@ D : num [1:712] 1 1 1 1 1 ... ..@ uplo : chr "L" ..@ diag : chr "U" ..@ i : int [1:7809] 1 62 63 355 356 357 694 695 699 700 ... ..@ p : int [1:713] 0 16 31 42 52 61 69 76 82 89 ... ..@ factors : list() ..@ x : num [1:7809] -5.55e-11 -2.93e-01 -3.22e-01 -4.14e-01 1.92e-01 ... ..@ Dim : int [1:2] 712 712 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > > ## Visualize the sparseness: > image(xpx, main=paste("crossprod(mm) : Sparse",dQuote(class(xpx)))) > image(ch, main=paste("chol (crossprod(mm)) : Sparse", dQuote(class(ch)))) > > > > cleanEx(); ..nameEx <- "ddenseMatrix-class" > > ### * ddenseMatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: ddenseMatrix-class > ### Title: Virtual Class "ddenseMatrix" of Numeric Dense Matrices > ### Aliases: ddenseMatrix-class show,ddenseMatrix-method > ### coerce,ddenseMatrix,matrix-method > ### crossprod,ddenseMatrix,missing-method diag,ddenseMatrix-method > ### lu,ddenseMatrix-method norm,ddenseMatrix,missing-method > ### norm,ddenseMatrix,character-method rcond,ddenseMatrix,missing-method > ### rcond,ddenseMatrix,character-method solve,ddenseMatrix,missing-method > ### solve,ddenseMatrix,ANY-method t,ddenseMatrix-method > ### tcrossprod,ddenseMatrix-method > ### Keywords: classes > > ### ** Examples > > showClass("ddenseMatrix") Virtual Class Slots: Name: rcond factors x Dim Dimnames Class: numeric list numeric integer list Extends: Class "dMatrix", directly Class "Matrix", by class "dMatrix" Known Subclasses: Class "dgeMatrix", directly Class "dtpMatrix", directly Class "dspMatrix", directly Class "dtrMatrix", by class "dgeMatrix" Class "dsyMatrix", by class "dgeMatrix" > > > > cleanEx(); ..nameEx <- "dgCMatrix-class" > > ### * dgCMatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: dgCMatrix-class > ### Title: Compressed, sparse, column-oriented numeric matrices > ### Aliases: dgCMatrix-class \%*\%,dgCMatrix,dgeMatrix-method > ### \%*\%,dgCMatrix,matrix-method \%*\%,dgeMatrix,dgCMatrix-method > ### \%*\%,matrix,dgCMatrix-method coerce,matrix,dgCMatrix-method > ### coerce,dgeMatrix,dgCMatrix-method coerce,dgCMatrix,dgTMatrix-method > ### coerce,dgCMatrix,dgBCMatrix-method coerce,dgCMatrix,matrix-method > ### coerce,dgCMatrix,dgeMatrix-method crossprod,dgCMatrix,missing-method > ### crossprod,dgCMatrix,matrix-method > ### crossprod,dgCMatrix,dgeMatrix-method diag,dgCMatrix-method > ### dim,dgCMatrix-method image,dgCMatrix-method t,dgCMatrix-method > ### Keywords: classes algebra > > ### ** Examples > > m <- Matrix(1:12, nrow = 3) > (mC <- as(m, "dgCMatrix")) 3 x 4 sparse Matrix of class "dgCMatrix" [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12 > str(mC) Formal class 'dgCMatrix' [package "Matrix"] with 6 slots ..@ i : int [1:12] 0 1 2 0 1 2 0 1 2 0 ... ..@ p : int [1:5] 0 3 6 9 12 ..@ factors : list() ..@ x : num [1:12] 1 2 3 4 5 6 7 8 9 10 ... ..@ Dim : int [1:2] 3 4 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > mC[,1] [1] 1 2 3 > > > > cleanEx(); ..nameEx <- "dgTMatrix-class" > > ### * dgTMatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: dgTMatrix-class > ### Title: Sparse matrices in triplet form > ### Aliases: dgTMatrix-class +,dgTMatrix,dgTMatrix-method > ### coerce,dgTMatrix,dgCMatrix-method coerce,dgTMatrix,dgeMatrix-method > ### coerce,dgTMatrix,dsCMatrix-method coerce,dgTMatrix,matrix-method > ### coerce,dgeMatrix,dgTMatrix-method coerce,matrix,dgTMatrix-method > ### crossprod,dgTMatrix,missing-method crossprod,dgTMatrix,matrix-method > ### crossprod,dgTMatrix,numeric-method image,dgTMatrix-method > ### kronecker,dgTMatrix,dgTMatrix-method t,dgTMatrix-method > ### Keywords: classes algebra > > ### ** Examples > > m <- Matrix(1:28, nrow = 4) > (mT <- as(m, "dgTMatrix")) 4 x 7 sparse Matrix of class "dgTMatrix" [1,] 1 5 9 13 17 21 25 [2,] 2 6 10 14 18 22 26 [3,] 3 7 11 15 19 23 27 [4,] 4 8 12 16 20 24 28 > > mT[1,] [1] 1 5 9 13 17 21 25 > mT[4, drop = FALSE] 1 x 7 sparse Matrix of class "dgTMatrix" [1,] 4 8 12 16 20 24 28 > > > > cleanEx(); ..nameEx <- "dpoMatrix-class" > > ### * dpoMatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: dpoMatrix-class > ### Title: Positive semi-definite, dense, numeric matrices > ### Aliases: dpoMatrix-class dppMatrix-class > ### coerce,dpoMatrix,dppMatrix-method coerce,dppMatrix,dpoMatrix-method > ### rcond,dpoMatrix,character-method rcond,dppMatrix,character-method > ### rcond,dpoMatrix,missing-method rcond,dppMatrix,missing-method > ### chol,dpoMatrix-method chol,dppMatrix-method chol,dpoMatrix,ANY-method > ### chol,dppMatrix,ANY-method determinant,dpoMatrix,logical-method > ### determinant,dppMatrix,logical-method solve,dpoMatrix,dgeMatrix-method > ### solve,dppMatrix,dgeMatrix-method solve,dpoMatrix,matrix-method > ### solve,dppMatrix,matrix-method solve,dpoMatrix,missing-method > ### solve,dppMatrix,missing-method solve,dpoMatrix,numeric-method > ### solve,dppMatrix,numeric-method solve,dppMatrix,integer-method > ### Keywords: classes algebra > > ### ** Examples > > h6 <- Hilbert(6) > rcond(h6) [1] 3.439939e-08 > str(h6) Formal class 'dpoMatrix' [package "Matrix"] with 6 slots ..@ uplo : chr "U" ..@ rcond : Named num 3.44e-08 .. ..- attr(*, "names")= chr "O" ..@ factors :List of 1 .. ..$ Cholesky:Formal class 'Cholesky' [package "Matrix"] with 7 slots .. .. .. ..@ uplo : chr "U" .. .. .. ..@ diag : chr "N" .. .. .. ..@ rcond : num(0) .. .. .. ..@ factors : list() .. .. .. ..@ x : num [1:36] 1 0 0 0 0 ... .. .. .. ..@ Dim : int [1:2] 6 6 .. .. .. ..@ Dimnames:List of 2 .. .. .. .. ..$ : NULL .. .. .. .. ..$ : NULL ..@ x : num [1:36] 1.000 0.500 0.333 0.250 0.200 ... ..@ Dim : int [1:2] 6 6 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > solve(h6) 6 x 6 Matrix of class "dpoMatrix" [,1] [,2] [,3] [,4] [,5] [,6] [1,] 36 -630 3360 -7560 7560 -2772 [2,] -630 14700 -88200 211680 -220500 83160 [3,] 3360 -88200 564480 -1411200 1512000 -582120 [4,] -7560 211680 -1411200 3628800 -3969000 1552320 [5,] 7560 -220500 1512000 -3969000 4410000 -1746360 [6,] -2772 83160 -582120 1552320 -1746360 698544 > str(hp6 <- as(h6, "dppMatrix")) Formal class 'dppMatrix' [package "Matrix"] with 6 slots ..@ uplo : chr "U" ..@ rcond : Named num 3.44e-08 .. ..- attr(*, "names")= chr "O" ..@ factors :List of 1 .. ..$ pCholesky:Formal class 'pCholesky' [package "Matrix"] with 7 slots .. .. .. ..@ uplo : chr "U" .. .. .. ..@ diag : chr "N" .. .. .. ..@ rcond : num(0) .. .. .. ..@ factors : list() .. .. .. ..@ x : num [1:21] 1.000 0.500 0.289 0.333 0.289 ... .. .. .. ..@ Dim : int [1:2] 6 6 .. .. .. ..@ Dimnames:List of 2 .. .. .. .. ..$ : NULL .. .. .. .. ..$ : NULL ..@ x : num [1:21] 1.000 0.500 0.333 0.333 0.250 ... ..@ Dim : int [1:2] 6 6 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > > > > cleanEx(); ..nameEx <- "dsparseMatrix-class" > > ### * dsparseMatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: dsparseMatrix-class > ### Title: Virtual Class "dsparseMatrix" of Numeric Sparse Matrices > ### Aliases: dsparseMatrix-class > ### Keywords: classes > > ### ** Examples > > showClass("dsparseMatrix") Slots: Name: x Dim Dimnames Class: numeric integer list Extends: Class "dMatrix", directly Class "sparseMatrix", directly Class "Matrix", by class "dMatrix" Class "Matrix", by class "sparseMatrix" Known Subclasses: Class "dgTMatrix", directly Class "dgCMatrix", directly Class "dgRMatrix", directly Class "dtTMatrix", by class "dgTMatrix" Class "dsTMatrix", by class "dgTMatrix" Class "dtCMatrix", by class "dgCMatrix" Class "dsCMatrix", by class "dgCMatrix" > > > > cleanEx(); ..nameEx <- "dsyMatrix-class" > > ### * dsyMatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: dsyMatrix-class > ### Title: Symmetric, dense matrices > ### Aliases: \%*\%,dgeMatrix,dsyMatrix-method > ### \%*\%,dspMatrix,dgeMatrix-method \%*\%,dspMatrix,integer-method > ### \%*\%,dspMatrix,matrix-method \%*\%,dspMatrix,numeric-method > ### \%*\%,dsyMatrix,dgeMatrix-method coerce,dspMatrix,dgeMatrix-method > ### coerce,dspMatrix,dsyMatrix-method coerce,dspMatrix,matrix-method > ### coerce,dsyMatrix,dgeMatrix-method coerce,dsyMatrix,dspMatrix-method > ### coerce,dsyMatrix,matrix-method dspMatrix-class dsyMatrix-class > ### norm,dspMatrix,character-method norm,dspMatrix,missing-method > ### norm,dsyMatrix,character-method norm,dsyMatrix,missing-method > ### rcond,dspMatrix,character-method rcond,dspMatrix,missing-method > ### rcond,dsyMatrix,character-method rcond,dsyMatrix,missing-method > ### solve,dspMatrix,dgeMatrix-method solve,dspMatrix,integer-method > ### solve,dspMatrix,matrix-method solve,dspMatrix,missing-method > ### solve,dspMatrix,numeric-method solve,dsyMatrix,dgeMatrix-method > ### solve,dsyMatrix,matrix-method solve,dsyMatrix,missing-method > ### t,dspMatrix-method t,dsyMatrix-method unpack,dspMatrix-method > ### Keywords: classes > > ### ** Examples > > ## Only upper triangular part matters (when uplo == "U" as per default) > (sy2 <- new("dsyMatrix", Dim = as.integer(c(2,2)), x = c(14, NA,32,77))) 2 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] 14 32 [2,] 32 77 > (c2 <- chol(sy2)) 2 x 2 Matrix of class "Cholesky" [,1] [,2] [1,] 3.741657 8.552360 [2,] 0.000000 1.963961 > all.equal(c2, c2. <- chol(as(sy2, "dpoMatrix")))# equal, but not same class [1] TRUE > str(c2) Formal class 'Cholesky' [package "Matrix"] with 7 slots ..@ uplo : chr "U" ..@ diag : chr "N" ..@ rcond : num(0) ..@ factors : list() ..@ x : num [1:4] 3.74 0.00 8.55 1.96 ..@ Dim : int [1:2] 2 2 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > > ## An example where chol() can't work > (sy3 <- new("dsyMatrix", Dim = as.integer(c(2,2)), x = c(14, -1, 2, -7))) 2 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] 14 2 [2,] 2 -7 > > validObject(as(sy3, "dpoMatrix"), test=TRUE) # >> is not pos.def. [1] "dpoMatrix is not positive definite" > try(chol(sy3)) ## Error: not pos.def Error in chol(sy3) : Lapack routine dpotrf returned error code 2 > > > > cleanEx(); ..nameEx <- "expand" > > ### * expand > > flush(stderr()); flush(stdout()) > > ### Name: expand > ### Title: Expand a Decomposition into Factors > ### Aliases: expand > ### Keywords: algebra > > ### ** Examples > > (x <- Matrix(round(rnorm(9),2), 3, 3)) 3 x 3 Matrix of class "dgeMatrix" [,1] [,2] [,3] [1,] -0.63 1.60 0.49 [2,] 0.18 0.33 0.74 [3,] -0.84 -0.82 0.58 > (ex <- expand(lux <- lu(x))) $L 3 x 3 Matrix of class "dgeMatrix" [,1] [,2] [,3] [1,] 1.0000000 0.00000000 0 [2,] 0.7500000 1.00000000 0 [3,] -0.2142857 0.06965495 1 $U 3 x 3 Matrix of class "dgeMatrix" [,1] [,2] [,3] [1,] -0.84 -0.820 0.5800000 [2,] 0.00 2.215 0.0550000 [3,] 0.00 0.000 0.8604547 $P 3 x 3 Matrix of class "pMatrix" [,1] [,2] [,3] [1,] 0 1 0 [2,] 0 0 1 [3,] 1 0 0 > > > > cleanEx(); ..nameEx <- "expm" > > ### * expm > > flush(stderr()); flush(stdout()) > > ### Name: expm > ### Title: Matrix exponential > ### Aliases: expm expm,ddenseMatrix-method expm,dgeMatrix-method > ### Keywords: algebra math > > ### ** Examples > > (m1 <- Matrix(c(1,0,1,1), nc = 2)) 2 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] 1 1 [2,] 0 1 > (e1 <- expm(m1)) ; e <- exp(1) 2 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] 2.718282 2.718282 [2,] 0.000000 2.718282 > stopifnot(all.equal(e1@x, c(e,0,e,e), tol = 1e-15)) > (m2 <- Matrix(c(-49, -64, 24, 31), nc = 2)) 2 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] -49 24 [2,] -64 31 > (e2 <- expm(m2)) 2 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] -0.7357588 0.5518191 [2,] -1.4715176 1.1036382 > (m3 <- Matrix(cbind(0,rbind(6*diag(3),0)), nc = 4)) 4 x 4 Matrix of class "dgeMatrix" [,1] [,2] [,3] [,4] [1,] 0 6 0 0 [2,] 0 0 6 0 [3,] 0 0 0 6 [4,] 0 0 0 0 > (e3 <- expm(m3)) 4 x 4 Matrix of class "dgeMatrix" [,1] [,2] [,3] [,4] [1,] 1 6 18 36 [2,] 0 1 6 18 [3,] 0 0 1 6 [4,] 0 0 0 1 > > > > cleanEx(); ..nameEx <- "facmul" > > ### * facmul > > flush(stderr()); flush(stdout()) > > ### Name: facmul > ### Title: Multiplication by Decomposition Factors > ### Aliases: facmul facmul.default > ### Keywords: array algebra > > ### ** Examples > > library(Matrix) > x <- Matrix(rnorm(9), 3, 3) > ## Not run: > ##D qrx <- qr(x) # QR factorization of x > ##D y <- rnorm(3) > ##D facmul( qr(x), factor = "Q", y) # form Q y > ## End(Not run) > > > > cleanEx(); ..nameEx <- "fixef" > > ### * fixef > > flush(stderr()); flush(stdout()) > > ### Name: fixef > ### Title: Extract Fixed Effects > ### Aliases: fixef fixed.effects fixef,ANY-method fixef,mer-method > ### fixef,glmer-method > ### Keywords: models > > ### ** Examples > > fixef(lmer(decrease ~ treatment + (1|rowpos) + (1|colpos), + OrchardSprays)) (Intercept) treatmentB treatmentC treatmentD treatmentE treatmentF 4.625 3.000 20.625 30.375 58.500 64.375 treatmentG treatmentH 63.875 85.625 > > > > cleanEx(); ..nameEx <- "lmer" > > ### * lmer > > flush(stderr()); flush(stdout()) > > ### Name: lmer > ### Title: Fit (Generalized) Linear Mixed-Effects Models > ### Aliases: lmer lmer,formula-method > ### Keywords: models methods > > ### ** Examples > > (fm1 <- lmer(decrease ~ treatment + (1|rowpos) + (1|colpos), + OrchardSprays)) Linear mixed-effects model fit by REML Formula: decrease ~ treatment + (1 | rowpos) + (1 | colpos) Data: OrchardSprays AIC BIC logLik MLdeviance REMLdeviance 534.7596 558.5073 -256.3798 558.4304 512.7596 Random effects: Groups Name Variance Std.Dev. rowpos (Intercept) 37.5295 6.1261 colpos (Intercept) 2.5252 1.5891 Residual 380.8313 19.5149 # of obs: 64, groups: rowpos, 8; colpos, 8 Fixed effects: Estimate Std. Error DF t value Pr(>|t|) (Intercept) 4.6250 7.2533 56 0.6376 0.526308 treatmentB 3.0000 9.7574 56 0.3075 0.759636 treatmentC 20.6250 9.7574 56 2.1138 0.039002 * treatmentD 30.3750 9.7574 56 3.1130 0.002915 ** treatmentE 58.5000 9.7574 56 5.9954 1.546e-07 *** treatmentF 64.3750 9.7574 56 6.5975 1.597e-08 *** treatmentG 63.8750 9.7574 56 6.5463 1.939e-08 *** treatmentH 85.6250 9.7574 56 8.7753 4.170e-12 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > > > cleanEx(); ..nameEx <- "lu" > > ### * lu > > flush(stderr()); flush(stdout()) > > ### Name: lu > ### Title: Triangular Decomposition of a Square Matrix > ### Aliases: lu > ### Keywords: array algebra > > ### ** Examples > > x <- Matrix(rnorm(9), 3, 3) > lu(x) An object of class "LU" Slot "x": [1] -0.83562861 0.74967970 -0.21976668 -0.82046838 2.21036930 0.06749830 [7] 0.57578135 0.05577746 0.86109738 Slot "perm": [1] 3 3 3 > > > > cleanEx(); ..nameEx <- "mm" > > ### * mm > > flush(stderr()); flush(stdout()) > > ### Name: mm > ### Title: A sample sparse model matrix > ### Aliases: mm > ### Keywords: datasets > > ### ** Examples > > data(mm) > data(y) > class(mm) [1] "dgCMatrix" attr(,"package") [1] "Matrix" > dim(mm) [1] 1850 712 > str(mm) Formal class 'dgCMatrix' [package "Matrix"] with 6 slots ..@ i : int [1:8755] 0 2 25 27 163 165 1258 1261 1276 1278 ... ..@ p : int [1:713] 0 13 17 26 38 43 52 56 61 67 ... ..@ factors : list() ..@ x : num [1:8755] 0.277 0.277 0.277 0.277 0.277 ... ..@ Dim : int [1:2] 1850 712 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > str(y) num [1:1850] 64.07 5.88 64.03 5.96 76.41 ... > sparse.sol <- solve(crossprod(mm), crossprod(mm, y)) > str(sparse.sol) Formal class 'dgeMatrix' [package "Matrix"] with 5 slots ..@ rcond : num(0) ..@ factors : list() ..@ x : num [1:712] 823 340 473 349 188 ... ..@ Dim : int [1:2] 712 1 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > > > > cleanEx(); ..nameEx <- "norm" > > ### * norm > > flush(stderr()); flush(stdout()) > > ### Name: norm > ### Title: Norm of a Matrix > ### Aliases: norm > ### Keywords: algebra > > ### ** Examples > > x <- Hilbert(9) > norm(x, "1") [1] 2.828968 > norm(x, "I") [1] 2.828968 > norm(x, "F") [1] 1.755872 > norm(x, "M") [1] 1 > > > > cleanEx(); ..nameEx <- "pMatrix-class" > > ### * pMatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: pMatrix-class > ### Title: Permutation matrices > ### Aliases: pMatrix-class \%*\%,matrix,pMatrix-method > ### \%*\%,pMatrix,matrix-method \%*\%,pMatrix,pMatrix-method > ### \%*\%,dgeMatrix,pMatrix-method \%*\%,pMatrix,dgeMatrix-method > ### coerce,integer,pMatrix-method coerce,pMatrix,matrix-method > ### solve,pMatrix,missing-method t,pMatrix-method > ### Keywords: classes > > ### ** Examples > > (pm1 <- as(as.integer(c(2,3,1)), "pMatrix")) 3 x 3 Matrix of class "pMatrix" [,1] [,2] [,3] [1,] 0 1 0 [2,] 0 0 1 [3,] 1 0 0 > t(pm1) # is the same as 3 x 3 Matrix of class "pMatrix" [,1] [,2] [,3] [1,] 0 0 1 [2,] 1 0 0 [3,] 0 1 0 > solve(pm1) 3 x 3 Matrix of class "pMatrix" [,1] [,2] [,3] [1,] 0 0 1 [2,] 1 0 0 [3,] 0 1 0 > pm1 %*% t(pm1) # check that the transpose is the inverse 3 x 3 Matrix of class "pMatrix" [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 > stopifnot(identical(diag(3), as(pm1 %*% t(pm1), "matrix"))) > (mm <- round(array(rnorm(3 * 3), c(3, 3)), 2)) [,1] [,2] [,3] [1,] -0.63 1.60 0.49 [2,] 0.18 0.33 0.74 [3,] -0.84 -0.82 0.58 > mm %*% pm1 [,1] [,2] [,3] [1,] 1.60 0.49 -0.63 [2,] 0.33 0.74 0.18 [3,] -0.82 0.58 -0.84 > pm1 %*% mm [,1] [,2] [,3] [1,] 0.18 0.33 0.74 [2,] -0.84 -0.82 0.58 [3,] -0.63 1.60 0.49 > try(as(as.integer(c(3,3,1)), "pMatrix"))# Error: not a permutation Error in validObject(.Object) : invalid class "pMatrix" object: 'perm' slot is not a valid permutation > > > > cleanEx(); ..nameEx <- "ranef" > > ### * ranef > > flush(stderr()); flush(stdout()) > > ### Name: ranef > ### Title: Extract Random Effects > ### Aliases: ranef random.effects ranef-methods ranef,ANY-method > ### ranef,lmer-method > ### Keywords: models methods > > ### ** Examples > > ranef(lmer(decrease ~ treatment + (1|rowpos) + (1|colpos), + OrchardSprays)) $rowpos (Intercept) 1 7.5836801 2 3.1202607 3 2.5692213 4 -3.1615887 5 -3.7126281 6 -3.3820045 7 -2.5554453 8 -0.4614955 $colpos (Intercept) 1 0.406933949 2 0.520277254 3 -0.292016432 4 -0.008658169 5 -0.323500683 6 -0.298313282 7 -0.298313282 8 0.293590644 attr(,"varFac") attr(,"varFac")$rowpos , , 1 [,1] [1,] 0.05526038 , , 2 [,1] [1,] 0.05526038 , , 3 [,1] [1,] 0.05526038 , , 4 [,1] [1,] 0.05526038 , , 5 [,1] [1,] 0.05526038 , , 6 [,1] [1,] 0.05526038 , , 7 [,1] [1,] 0.05526038 , , 8 [,1] [1,] 0.05526038 attr(,"varFac")$colpos , , 1 [,1] [1,] 0.006314726 , , 2 [,1] [1,] 0.006314726 , , 3 [,1] [1,] 0.006314726 , , 4 [,1] [1,] 0.006314726 , , 5 [,1] [1,] 0.006314726 , , 6 [,1] [1,] 0.006314726 , , 7 [,1] [1,] 0.006314726 , , 8 [,1] [1,] 0.006314726 attr(,"stdErr") [1] 19.5149 attr(,"class") [1] "lmer.ranef" attr(,"class")attr(,"package") [1] "Matrix" > > > > cleanEx(); ..nameEx <- "rcond" > > ### * rcond > > flush(stderr()); flush(stdout()) > > ### Name: rcond > ### Title: Estimate the Reciprocal Condition Number > ### Aliases: rcond > ### Keywords: array algebra > > ### ** Examples > > x <- Matrix(rnorm(9), 3, 3) > rcond(x) [1] 0.1803670 > rcond(Hilbert(9)) # should be about 9.1e-13 [1] 9.093775e-13 > > > > cleanEx(); ..nameEx <- "sparseMatrix-class" > > ### * sparseMatrix-class > > flush(stderr()); flush(stdout()) > > ### Name: sparseMatrix-class > ### Title: Virtual Class "sparseMatrix" - Mother of Sparse Matrices > ### Aliases: sparseMatrix-class show,sparseMatrix-method > ### \%*\%,sparseMatrix,ddenseMatrix-method > ### \%*\%,ddenseMatrix,sparseMatrix-method > ### crossprod,sparseMatrix,ddenseMatrix-method > ### crossprod,ddenseMatrix,sparseMatrix-method > ### Keywords: classes > > ### ** Examples > > showClass("sparseMatrix") ## and look at the help() of its subclasses Slots: Name: Dim Dimnames Class: integer list Extends: "Matrix" Known Subclasses: "dsparseMatrix", "lsparseMatrix" > > > > cleanEx(); ..nameEx <- "tcrossprod" > > ### * tcrossprod > > flush(stderr()); flush(stdout()) > > ### Name: tcrossprod > ### Title: Cross-product of transpose > ### Aliases: tcrossprod-methods tcrossprod,dgCMatrix-method > ### tcrossprod,dgTMatrix-method tcrossprod > ### Keywords: methods algebra > > ### ** Examples > > ## A random sparce "incidence" matrix : > m <- matrix(0, 400, 500) > set.seed(12) > m[runif(314, 0, length(m))] <- 1 > mm <- as(m, "dgCMatrix") > object.size(m) / object.size(mm) # smaller by a factor of 242.88 [1] 242.8840 > > ## tcrossprod() is very fast: > system.time(tCmm <- tcrossprod(mm))# "0" practically [1] 0 0 0 0 0 > system.time(cm <- crossprod(t(m))) # [1] 0.17 0.01 0.19 0.00 0.00 > > stopifnot(identical(cm, as(tCmm, "matrix"))) > > ## show "sparse" (sub) matrix > tc <- cm[1:16, 1:30] > storage.mode(tc) <- "character" ; tc[tc == "0"] <- "." > dimnames(tc)[[2]] <- rep("", ncol(tc)) > noquote(tc) [1,] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [2,] . 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . [3,] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [4,] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [5,] . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . [6,] . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . [7,] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [8,] . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . [9,] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [10,] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [11,] . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . [12,] . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . [13,] . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . [14,] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [15,] . . . . . . . . . . . . . . 3 . . . . . . . . . . . . . . . [16,] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . > > > > cleanEx(); ..nameEx <- "unpack" > > ### * unpack > > flush(stderr()); flush(stdout()) > > ### Name: unpack > ### Title: Full Storage Representation of Packed Matrices > ### Aliases: unpack > ### Keywords: array algebra > > ### ** Examples > > showMethods("unpack") Function "unpack": x = "dspMatrix" x = "dtpMatrix" > (cp4 <- chol(Hilbert(4))) # is triangular 4 x 4 Matrix of class "Cholesky" [,1] [,2] [,3] [,4] [1,] 1 0.5000000 0.3333333 0.25000000 [2,] 0 0.2886751 0.2886751 0.25980762 [3,] 0 0.0000000 0.0745356 0.11180340 [4,] 0 0.0000000 0.0000000 0.01889822 > tp4 <- as(cp4,"dtpMatrix")# [t]riangular [p]acked > str(tp4) Formal class 'dtpMatrix' [package "Matrix"] with 7 slots ..@ uplo : chr "U" ..@ diag : chr "N" ..@ rcond : num(0) ..@ factors : list() ..@ x : num [1:10] 1.000 0.500 0.289 0.333 0.289 ... ..@ Dim : int [1:2] 4 4 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL > (unpack(tp4)) 4 x 4 Matrix of class "dgeMatrix" [,1] [,2] [,3] [,4] [1,] 1 0.5000000 0.3333333 0.25000000 [2,] 0 0.2886751 0.2886751 0.25980762 [3,] 0 0.0000000 0.0745356 0.11180340 [4,] 0 0.0000000 0.0000000 0.01889822 > > ## Not run: > ##D ## once we have Diagonal() : > ##D unpack(Diagonal( 1:3)) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "y" > > ### * y > > flush(stderr()); flush(stdout()) > > ### Name: y > ### Title: A sample response vector > ### Aliases: y > ### Keywords: datasets > > ### ** Examples > > data(y) > > > > ### *