allvarscovs: Extract variances and covariances

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/defineclassesandfunctions.R

Description

Extract a data frame containing all variances and covariances of either the row or the column points.

Usage

1
allvarscovs(x, thing = "rows")

Arguments

x

object of class cabootcrsresults.

thing

"rows" - all rows.
"columns" - all columns.

Details

Shows all variances and covariances as a data frame for ease of viewing. To obtain a covariance matrix itself use covmat instead.

Value

Data frame.

Author(s)

T.J. Ringrose

See Also

covmat , cabootcrsresults

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
dreamdata <- t(matrix(c(7,4,3,7,10,15,11,13,23,9,11,7,28,9,12,10,32,5,4,3),4,5))
bd <- cabootcrs(dreamdata)
allvarscovs(bd)
allvarscovs(bd, thing="columns")


## The function is currently defined as
function (x, thing = "rows") 
{
    getcovs <- function(allC, n, ncovs) {
        V <- matrix(0, n, ncovs)
        for (i in 1:n) {
            y <- allC[i, , ]
            V[i, ] <- y[upper.tri(y)]
        }
        invisible(V)
    }
    if (!(class(x) == "cabootcrsresults")) 
        stop(paste("Must be of type cabootcrsresults\n\n"))
    if (!any(thing == c("rows", "columns"))) 
        stop(paste("Must be rows or columns\n\n"))
    ncovs <- x@axisvariances * (x@axisvariances - 1)/2
    vcnames <- character(length = x@axisvariances + ncovs)
    k <- 1
    for (i in 1:x@axisvariances) {
        vcnames[i] <- paste(" Var Axis", i)
        if (i < x@axisvariances) {
            for (j in (i + 1):x@axisvariances) {
                vcnames[x@axisvariances + k] <- paste(" Cov axes", 
                  i, j)
                k <- k + 1
            }
        }
    }
    if (thing == "rows") {
        Covs <- getcovs(x@RowCov, x@rows, ncovs)
        allV <- data.frame(cbind(x@RowVar, Covs), row.names = x@rowlabels)
    }
    else {
        Covs <- getcovs(x@ColCov, x@columns, ncovs)
        allV <- data.frame(cbind(x@ColVar, Covs), row.names = x@collabels)
    }
    names(allV) <- vcnames
    allV
  }

cabootcrs documentation built on May 30, 2017, 8:18 a.m.