Learn R Programming

cabootcrs (version 1.0)

sca: Correspondence analysis on a contingency table or similar

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

sca(X)

Arguments

X

A matrix of positive values, usually a contingency table.

Value

An object of class cabasicresults.

Details

Assumes that input matrix has rows >= columns.

See Also

'>cabasicresults

Examples

Run this code
# NOT RUN {
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)
  }
# }

Run the code above in your browser using DataLab