\HeaderA{RtreemixModel-class}{Class "RtreemixModel"}{RtreemixModel.Rdash.class}
\aliasA{CompleteMat}{RtreemixModel-class}{CompleteMat}
\aliasA{CompleteMat,RtreemixModel-method}{RtreemixModel-class}{CompleteMat,RtreemixModel.Rdash.method}
\aliasA{getData,RtreemixModel}{RtreemixModel-class}{getData,RtreemixModel}
\aliasA{getData,RtreemixModel-method}{RtreemixModel-class}{getData,RtreemixModel.Rdash.method}
\aliasA{getTree}{RtreemixModel-class}{getTree}
\aliasA{getTree,RtreemixModel,numeric-method}{RtreemixModel-class}{getTree,RtreemixModel,numeric.Rdash.method}
\aliasA{initialize,RtreemixModel-method}{RtreemixModel-class}{initialize,RtreemixModel.Rdash.method}
\aliasA{numTrees}{RtreemixModel-class}{numTrees}
\aliasA{numTrees,RtreemixModel-method}{RtreemixModel-class}{numTrees,RtreemixModel.Rdash.method}
\aliasA{plot,RtreemixModel-method, missing-method}{RtreemixModel-class}{plot,RtreemixModel.Rdash.method, missing.Rdash.method}
\aliasA{print,RtreemixModel-method}{RtreemixModel-class}{print,RtreemixModel.Rdash.method}
\aliasA{Resp}{RtreemixModel-class}{Resp}
\aliasA{Resp,RtreemixModel-method}{RtreemixModel-class}{Resp,RtreemixModel.Rdash.method}
\aliasA{show,RtreemixModel-method}{RtreemixModel-class}{show,RtreemixModel.Rdash.method}
\aliasA{Star}{RtreemixModel-class}{Star}
\aliasA{Star,RtreemixModel-method}{RtreemixModel-class}{Star,RtreemixModel.Rdash.method}
\aliasA{Trees}{RtreemixModel-class}{Trees}
\aliasA{Trees,RtreemixModel-method}{RtreemixModel-class}{Trees,RtreemixModel.Rdash.method}
\aliasA{Weights}{RtreemixModel-class}{Weights}
\aliasA{Weights,RtreemixModel-method}{RtreemixModel-class}{Weights,RtreemixModel.Rdash.method}
\aliasA{Weights<\Rdash}{RtreemixModel-class}{Weights<.Rdash.}
\aliasA{Weights<-,RtreemixModel-method}{RtreemixModel-class}{Weights<.Rdash.,RtreemixModel.Rdash.method}
\aliasA{WeightsCI}{RtreemixModel-class}{WeightsCI}
\aliasA{WeightsCI,RtreemixModel-method}{RtreemixModel-class}{WeightsCI,RtreemixModel.Rdash.method}
\keyword{classes}{RtreemixModel-class}
\begin{Description}\relax
This class contains all the data needed for characterizing the mutagenetic
trees mixture model (mixture parameters, mixture components, ...).
The tree components of the model are given as a list of directed \code{graphNEL} objects.
\end{Description}
\begin{Section}{Objects from the Class}
Objects can be created by calls of the form \code{new("RtreemixModel",
    ParentData, Weights, WeightsCI, Resp, CompleteMat, Star, Trees)}.
The \code{RtreemixModel} class extends the \code{RtreemixData} class
and specifies the mutagenetic trees mixture model. If the model is not
randomly generated the parent class gives the \code{RtreemixData}
used for learning the mixture model. The directed trees that build up
the model are represented as a list of directed \code{graphNEL}
objects, and their weights (the mixture parameters) are given as a
numeric vector. This class can also contain other useful information
connected with the mixture model like confidence intervals for the
mixture parameters and the edge weights (resulting from a bootstrap
analysis), an indicator for the presence of the star component, etc.
They are all listed in the text below with brief descriptions.

The \code{ParentData} is an \code{RtreemixData} object that specifies the
data used for estimating the mutagenetic trees mixture model. It is
not specified for random mixture models, since they are not estimated
from a given dataset but generated randomly.

The \code{Weights} is a numeric \code{vector} that contains the mixture
parameters of the model. Its length equals the length of the
\code{list} of tree components \code{Trees}.

The \code{WeightsCI} is a named \code{list} with length equal to the
length of the \code{Weights}. Each list element is a numeric
\code{vector} of length two specifying the lower and upper bound of
the confidence interval for the corresponding mixture parametar. The
confidence intervals are derived using the bootstrap method.

The \code{Resp} is a numeric \code{matrix} that specifies the responsibility
of each tree component to generate each of the patterns in the
\code{ParentData}. The number of rows in \code{Resp} is equal
to the number of trees in the mixture (the length of the list
\code{Trees}) and the number of columns equals the number of patients
in \code{ParentData}. For random mixture models it is an empty matrix,
since they are not estimated from a given dataset.

The \code{CompleteMat} is a binary \code{matrix} that specifies the complete
data in case some measurements for some patients are missing in
the data used for learning the model (the \code{ParentData}). It has
the same size as the matrix specifying the data in \code{ParentData}.
The missing data are estimated in the EM-algorithm used for fitting
the mixture model. When there are no missing data in
\code{ParentData}, or the model is randomly generated the \code{CompleteMat} is an
empty matrix. 

The \code{Star} is an indicator of the presence of a noise (star) component
and is mostly relevant for models with a single tree component, since it is assumed that 
mixture models with at least two components always have the noise
as a first component. It is of type \code{logical}.

The \code{Trees} is a \code{list} of directed \code{graphNEL}
objects, each for every tree component in the mixture model. The
genetic events are represented as nodes in the graphs. The
\code{edgeData} of each tree can have two attributes: \code{"weight"}
and \code{"ci"}. Please see the help page on \code{graph-class} and
\code{graphNEL-class} in the package \code{graph}. The \code{"weight"} attribute is for edge weight,
i.e. the conditional probability that the child event of the edge occured given
that the parent event already occured. The \code{"ci"} attribute is
for the bootstrap confidence intervals for the edge weight (a numeric vector
with length two).
\end{Section}
\begin{Section}{Slots}
\describe{
\item[\code{Weights}:] Object of class \code{"numeric"}. The length
of the \code{Weights} must be equal to the length of \code{Trees}. 
\item[\code{WeightsCI}:] Object of class \code{"list"}. The length
of the \code{WeightsCI} must be equal to the length of \code{Weights}.  
\item[\code{Resp}:] Object of class \code{"matrix"}. The number of
rows of \code{Resp} must be identical to the length of
\code{Trees}, and its number of columns to the number of patients
in the dataset used for estimating the mixture model (\code{ParentData}).
\item[\code{CompleteMat}:] Object of class \code{"matrix"}. When
specified (when there are missing data) the size of the
\code{CompleteMat} must be equal to the size of the matrix used to
estimate the model.
\item[\code{Star}:] Object of class \code{"logical"}. 
\item[\code{Trees}:] Object of class \code{"list"}. The length of
\code{Trees} equals the length of \code{Weights}.
}
\end{Section}
\begin{Section}{Extends}
Class \code{"RtreemixData"}, directly.
\end{Section}
\begin{Section}{Methods}
\describe{
\item[CompleteMat] \code{signature(object = "RtreemixModel")}: A
method used for obtaining the complete dataset, in case there were
any missing measurements for some patients in the dataset used to
learn the mixture model.
\item[Resp] \code{signature(object = "RtreemixModel")}: A method for
obtaining the matrix of responsibilities for the trees to generate
each of the samples in the dataset used for learning the model (\code{ParentData}).    
\item[Star] \code{signature(object = "RtreemixModel")}: A method for
checking the presence of a noise component in the mixture model
(informative only for models with one tree component).   
\item[Trees] \code{signature(object = "RtreemixModel")}: A method
for obtaining the tree components of the mixture model as a list
of directed \code{graphNEL} objects. 
\item[Weights] \code{signature(object = "RtreemixModel")}: A method
for obtaining the mixture parameters (the weights of the trees in
the model).
\item[Weights<-] \code{signature(object = "RtreemixModel")}: A
method for replacing the value of the slot \code{Weights} with a
specified \code{numeric} vector. The components of this vector
have to sum up to one.
\item[WeightsCI] \code{signature(object = "RtreemixModel")}: A method
for obtaining the weights of the mixture parameters. 
\item[getData] \code{signature(object = "RtreemixModel")}: A method
for obtaining the \code{ParentData} of the mixture model, i.e. the
data used for learning the model. 
\item[getTree] \code{signature(object = "RtreemixModel", k =
    "numeric")}: A method for obtaining the k-th tree component of the
mixture model as a directed \code{graphNEL} object.
\item[numTrees] \code{signature(object = "RtreemixModel")}: A method
for obtaining the number of tree components building up the mixture model.
}
\end{Section}
\begin{Author}\relax
Jasmina Bogojeska
\end{Author}
\begin{References}\relax
Learning multiple evolutionary pathways from cross-sectional
data, N. Beerenwinkel et al.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{RtreemixGPS-class}{RtreemixGPS.Rdash.class}}, \code{\LinkA{RtreemixStats-class}{RtreemixStats.Rdash.class}},
\code{\LinkA{RtreemixData-class}{RtreemixData.Rdash.class}}, \code{\LinkA{RtreemixSim-class}{RtreemixSim.Rdash.class}},
\code{\LinkA{fit-methods}{fit.Rdash.methods}}, \code{\LinkA{bootstrap-methods}{bootstrap.Rdash.methods}},
\code{\LinkA{generate-methods}{generate.Rdash.methods}}, \code{\LinkA{comp.models}{comp.models}}, \code{\LinkA{comp.trees}{comp.trees}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## Generate a random RtreemixModel object with 2 components.
rand.mod <- generate(K = 2, no.events = 9, noise.tree = TRUE, prob = c(0.2, 0.8))
show(rand.mod)
plot(rand.mod) ## plot the tree components of the model
plot(rand.mod, k = 2) ## plot the second component of the model

## Draw data from a specified mixture model.
draws <- sim(model = rand.mod, no.draws = 200)
show(draws)

## Create an RtreemixModel object by fitting model to the drawn data.
mod <- fit(data = draws, K = 2, equal.edgeweights = TRUE, noise = TRUE)
show(mod)

## See the values of the slots of the RtreemixModel object.
Weights(mod)
Resp(mod)
CompleteMat(mod)
Star(mod)
Trees(mod)
## See data used for learning the model.
getData(mod)
## See the number of tree components in the mixture model.
numTrees(mod)
## See a specific tree component k.
getTree(object = mod, k = 2)
## See the conditional probabilities assigned to edges of the second tree component.
edgeData(getTree(object = mod, k = 2), attr = "weight")
## See the probability distribution encoded by the model on the set of all possible patterns.
distr <- distribution(model = mod)
distr
## Get the probabilities.
distr$probability
## See the probability distribution encoded by the model on the set of all possible patterns
## calculated for given sampling mode, and input and output parameters.
distr1 <- distribution(model = mod, sampling.mode = "exponential", sampling.param = 1, output.param = 1)
distr1

## Create a RtreemixModel and analyze its variance with the bootstrap method.
mod.boot <- bootstrap(data = draws, K = 2, equal.edgeweights = TRUE, B = 100)

## See the confidence intervals for the mixture parameters (the weights).
WeightsCI(mod.boot)
## See the confidence intervals of the conditional probabilities assigned to the edges.
edgeData(getTree(mod.boot, 2), attr = "ci")
\end{ExampleCode}
\end{Examples}

