# NOT RUN {
set.seed(7,kind="Mersenne-Twister")
dataset <- matrix(rnorm(1000),nrow=100,ncol=10)
m <- minForest(dataset,stat="BIC")
#######################################################################
# Example with continuous variables
data(dsCont)
# m1 <- minForest(dataset,homog=TRUE,forbEdges=NULL,stat="LR")
# 1. in this case, there is no use for homog
# 2. no forbidden edges
# 3. the measure used is the LR (the result is a tree)
m1 <- minForest(dsCont,homog=TRUE,forbEdges=NULL,stat="LR")
plot(m1,numIter=1000)
#######################################################################
# Example with discrete variables
data(dsDiscr)
# m1 <- minForest(dataset,homog=TRUE,forbEdges=NULL,stat="LR")
# 1. in this case, there is no use for homog
# 2. no forbidden edges
# 3. the measure used is the LR (the result is a tree)
m1 <- minForest(dsDiscr,homog=TRUE,forbEdges=NULL,stat="LR")
plot(m1,numIter=1000)
#######################################################################
# Example with mixed variables
data(dsMixed)
# m1 <- minForest(dataset,homog=TRUE,forbEdges=NULL,stat="LR")
# 1. it is to be considered homogeneous
# 2. no forbidden edges
# 3. the measure used is the LR (the result is a tree)
m1 <- minForest(dsMixed,homog=TRUE,forbEdges=NULL,stat="LR")
plot(m1,numIter=1000)
#######################################################################
# Example using a user defined function
# The function userFun calculates the same edges weigths as the
# option stat="LR". It means that the final result, using either
# option, is the same.
userFun <- function(newEdge,numCat,dataset)
{
sigma <- var(dataset[,newEdge])
v <- nrow(dataset)*log(prod(diag(sigma))/det(sigma))
return(c(v,1))
}
data(dsCont)
m <- minForest(dsCont,stat="LR")
m1 <- minForest(dsCont,stat=userFun)
identical(m@edges,m1@edges)
#######################################################################
# Example with mandatory edges (the so-called conditional Chow-Liu
# algorithm). The edges (1,2), (1,3) and (2,3) are specified as
# mandatory. The algorithm returns the optimal graph containing the
# mandatory edges such that only cycles with mandatory edges are
# allowed.
data(dsCont)
m1 <- minForest(dsCont,cond=list(1:3))
# }
# NOT RUN {
plot(m1)
# }
Run the code above in your browser using DataLab