sca: Correspondence analysis on a contingency table or similar

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

View source: R/sca.R

Description

Performs the usual simple (2-d) correspondence analysis calculations on an input data matrix, producing an object that contains the fundamental results but nothing more.

Usage

1
sca(X)

Arguments

X

A matrix of positive values, usually a contingency table.

Details

Assumes that input matrix has rows >= columns.

Value

An object of class cabasicresults.

Note

Internal routine, not intended for direct call by users, although it can be.

Author(s)

T.J. Ringrose

See Also

cabasicresults

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
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))
cad <- sca(dreamdata)


## The function is currently defined as
function (X) 
{
    X <- X/sum(X)
    rmax <- min(dim(X)) - 1
    rsums <- as.vector(rowSums(X))
    csums <- as.vector(colSums(X))
    drm1 <- diag(1/(rsums + (rsums == 0)) * (1 - (rsums == 0)))
    dcm1 <- diag(1/(csums + (csums == 0)) * (1 - (csums == 0)))
    drmh <- sqrt(drm1)
    dcmh <- sqrt(dcm1)
    Z <- drmh %*% (X - rsums %*% t(csums)) %*% dcmh
    Y <- svd(Z)
    mu <- Y$d[1:rmax]
    r <- sum(mu > 1e-15)
    R <- drm1 %*% X
    Rweights <- dcmh
    Raxes = Y$v[, 1:rmax]
    C <- dcm1 %*% t(X)
    Cweights <- drmh
    Caxes = Y$u[, 1:rmax]
    if (r < rmax) {
        mu[(r + 1):rmax] <- 0
        Raxes[, (r + 1):rmax] <- 0
        Caxes[, (r + 1):rmax] <- 0
    }
    sca <- new("cabasicresults", Rprofile = R, Cprofile = C, 
        Rweights = Rweights, Cweights = Cweights, Raxes = Raxes, 
        Caxes = Caxes, r = r, mu = mu)
  }

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