R/FindCNumRandom.R

Defines functions FindCNumRandom

## Bootstrap to determine the number of groups
FindCNumRandom <- function(x, n, kG, n.monteCarlo)
{  
    # x             --> data matrix
    # n             --> nrow(x)
    # kG            --> number of total clusters
    # n.monteCarlo --> simulation times

    # centralize x
    x <- scale(x, center=TRUE, scale=FALSE)

    W <- CalculateWAll(x, n, kG)

    WStar <- matrix(data=0, nrow=n.monteCarlo, ncol=kG)
    
    bound <- rbind(n, apply(x,2,range))

    for (i in 1:n.monteCarlo)
    {
        y <- apply(bound, 2, UniformSample)
        WStar[i,] <- CalculateWAll(y, n, kG)
    }

    CalculateGapK(W, WStar, kG, n.monteCarlo)
}

Try the AssocTests package in your browser

Any scripts or data that you put into this service are public.

AssocTests documentation built on Nov. 17, 2017, 4:28 a.m.