\name{stam.fit}
\alias{stam.fit}
\title{Fit StAM Model to Training Data}
\description{
  Using the whole expression data provided fit one StAM model 
  according to the chosen shrinkage level.
}
\usage{
stam.fit(cv, expression.matrix, collapse.scnodes = FALSE, 
         alpha = 0.5, delta = NULL, max.nodes = 100)
}
\arguments{
  \item{cv}{result stam.cv on the same data, must be of class \code{stamCV}}
  \item{expression.matrix}{holds the expression levels. It may be of
    class \code{exprSet} or \code{ExpressionSet}, or a
    plain numeric matrix. In the first case \code{exprs} is used to extract the 
    expression levels. The matrix is expected to hold one column per sample and one row
    per probeset.}
  \item{collapse.scnodes}{if set to TRUE replace single children nodes after shrinkage}
  \item{alpha}{root performance vs. mean redundancy weight. If set to NULL the root error
    rate is used exclusively to determine the best shrinkage level. If a numeric vector 
    is provided, all alternatives are computed and the user is given an interactive 
    choice. Values between 0 and 1 are valid, 0 meaning exclusive weight on redundancy 
    and 1 putting exclusive weight on performance.}
  \item{delta}{overrule alpha and set shrinkage level explicitely.}
  \item{max.nodes}{choose default shrinkage level such that no more than this number of 
    nodes remain after shrinkage. }
}
\details{
  In a first step \code{stam.fit} must choose a shrinkage level. In order to do so it 
  uses results stored in the cv. If the user provides a shrinkage level explicitly this 
  \code{delta} is used. If he specifies a single weighting factor \code{alpha} the 
  corresponding weighted score is used to determine the best shrinkage level. If 
  \code{alpha} is set to a vector of values, the corresponding scores are computed and a 
  default \code{delta} is suggested using the median value of the \code{alphas}. If this 
  shrinkage level leads to more than \code{max.nodes} nodes remaining the shrinkage level
  is increase until no more than \code{max.nodes} remain after shrinkage.

  Using the thus determined shrinkage level a weighting of nodes is computed using the 
  leaf node results from \code{cv}. Thereby, the whole dataset supplied is used.
}
\value{
  An object of class stamFit is returned. You may use the print and plot methods 
  to further investigate the returned value.
}
\author{Claudio Lottaz}
\seealso{\code{\link{stam.cv}}, \code{\link{stamFit-class}}, \code{\link{plot.stamFit}}, 
  \code{\link{stam.graph.plot}}, \code{\link{stam.writeHTML}}}
\examples{
# prepare data
library(golubEsets)
data(Golub_Merge)

# load and prepare some data
golubTrain <- Golub_Merge[,1:38]
data(golubTrain.cv)

# compute fit
golubTrain.fit <- stam.fit(golubTrain.cv, golubTrain, alpha=seq(0, 1, 0.1))

# investigate
print(golubTrain.fit)
plot(golubTrain.fit)

# show clickable web-page
\dontrun{
map <- stam.graph.plot(golubTrain.fit, outfile="golubTrain")
cat("<HTML><BODY><MAP NAME='graph_map'>", map, "</MAP>",
    "<IMG SRC='golubTrain_graph_plot.png' USEMAP='#graph_map'></BODY></HTML>\n", 
    file="graph_plot.html")
browseURL(paste("file://", getwd(), "/graph_plot.html", sep=""))
}}
\keyword{classif}
