R/createBinaryData.R

Defines functions createBinaryData

createBinaryData <- function(clusterSizes, n, seed=101) {

# generate binary data for each cluster and combine the matrices

  set.seed(seed)

  kclust<-length(clusterSizes)

  for(ii in 1:kclust){

    oneclustsize<-clusterSizes[ii]

    binarycluster<-matrix(0,nrow=oneclustsize,ncol=n)
    binarytest<-matrix(0,nrow=oneclustsize,ncol=n)

    for(kk in 1:n){ # build data for this cluster
      beta<-runif(1)
      binarycluster[,kk]<-sample.int(2,oneclustsize,replace=TRUE,prob=c(beta,1-beta))-1
    }

    if(ii==1){ # combine the clusters
      binaryclusterdata<-binarycluster
    } else {
      binaryclusterdata<-rbind(binaryclusterdata,binarycluster)
    }

  }

  return(binaryclusterdata)
}

Try the clustNet package in your browser

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

clustNet documentation built on May 29, 2024, 12:13 p.m.