"randInit.MBnetwork" <- function(x,sub=TRUE,prob=NULL,exclude=TRUE,prop=.5) { isValid <- validObject(x) if(!is.logical(sub) || !(length(sub) %in% c(1,x@N))) stop("Invalid subset") if(!is.null(prob) && (!is.numeric(prob) || (length(prob) != x@N) || (any(prob < 0,na.rm=TRUE)) || (any(prob > 1,na.rm=TRUE)))) stop("Invalid prob vector") if(is.null(prop) || is.na(prop) || !(prop>=0) || !(prop<=1)) stop("prop must be between 0 and 1") if(exclude) to.use <- !is.na(x@Cpds[1,]) else to.use <- TRUE to.use <- to.use & sub if(is.null(prob)) prob <- rep(prop,sum(to.use)) else { prob <- prob[to.use] prob[is.na(prob)] <- prop } x@States[to.use] <- as.integer(rbinom(sum(to.use),1,prob)) x@States[!to.use] <- as.integer(NA) return(x) }