mw.buildlattice {ldsa}R Documentation

~~function to do ... ~~

Description

~~ A concise (1-5 lines) description of what the function does. ~~

Usage

mw.buildlattice(D)

Arguments

D ~~Describe D here~~

Details

~~ If necessary, more details than the description above ~~

Value

~Describe the value returned If it is a LIST, use

comp1 Description of 'comp1'
comp2 Description of 'comp2'

...

Warning

....

Note

~~further notes~~

~Make other sections like Warning with section{Warning }{....} ~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--    or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(D){
  #Create functions to calculate binary values
  bv<-function(x)
    sum(2^(1:length(x)-1)*x)
  bn<-function(x){
    v<-rep(0,NROW(D))
    for(i in 1:NROW(D)){
      v[i]<-x%%2
      x<-x%/%2
    }
    v
  }
  lattice<-vector()
  #Walk through the cartesian product of microbelief states
  for(i in 0:bv(rep(1,NROW(D)))){
    mb<-bn(i)            #Create the binary vector associated with i
    tm<-!((1-mb)%*%D)    #Create the macrobelief string
    mbv<-bv(tm)          #Find the binary value of the macrobelief string
    if(!is.null(dim(lattice))){             #Check for uniqueness
      m<-match(mbv,lattice[NCOL(D)+2])
      if(is.na(m))
        lattice<-rbind(lattice,c(tm,1,mbv))
      else
        lattice[m,NCOL(D)+1]<-lattice[m,NCOL(D)+1]+1
    }else if(length(lattice)>0){
      if(lattice[NCOL(D)+2]==mbv)
        lattice[NCOL(D)+1]<-lattice[NCOL(D)+1]+1
      else
        lattice<-rbind(lattice,c(tm,1,mbv))
    }else
      lattice<-c(tm,1,mbv)
  }
  #Provide a normalized frequency distribution
  lattice<-cbind(lattice,lattice[,NCOL(D)+1]/sum(lattice[,NCOL(D)+1]))
  #Return the result
  lattice
  }

[Package ldsa version 0.1-2 Index]