\name{ptn_model}
\alias{ptn_model}
\title{Accessor for the feature integration model slots of a \code{postNetData} object
}

\description{Retrieve the models resulting from both the stepwise linear regression and random forest implementations of \link[postNet]{featureIntegration} from a \code{postNetData} object.
}

\usage{
ptn_model(ptn, 
          analysis_type, 
          model, 
          comparison)
}

\arguments{
  \item{ptn}{A \linkS4class{postNetData} object.
}
  \item{analysis_type}{A string specifying the method of analysis used for \link[postNet]{featureIntegration} to retrieve the selected features from. The options are \code{"lm"} to retrieve features selected by forward stepwise linear regression, or \code{"rf"} for features selected using random forest-based analyses.
}
  \item{model}{A string specifying the model to retrieve. If \code{analysis_type = "lm"}, the options are: \code{"univariateModel"}, \code{"stepwiseModel"}, or \code{"finalModel"}. If \code{analysis_type = "rf"}, the options are: \code{"preModel"}, \code{"borutaModel"}, or \code{"finalModel"}. 
}
  \item{comparison}{An integer specifying which comparison to select the model from. For example, \code{1} would select the first comparison specified in the \code{comparisons} parameter of the \link[postNet]{featureIntegration} function.
}
}

\value{If \code{analysis_type = "lm"} and \code{model = "univariateModel"}, an object of class \code{postNetUnivariate} is returned with three slots containing the p-values, FDRs, and proportion of variance explained for each feature passing the significance threshold in univariate models. 

If \code{analysis_type = "lm"} and \code{model = "stepwiseModel"}, an object of class \code{postNetStepWise} is returned with two slots containing the linear models from each step of forward stepwise regression, and the F-value table storing the F-values for each feature at each step of forward stepwise regression.

If \code{analysis_type = "lm"} and \code{model = "finalModel"}, an object of class \code{postNetFinalModel} is returned with three slots containing the total variance explained by the final omnibus model, the final omnibus linear model, and a table summarizing the p-values and variance explained by each feature in the omnibus and adjusted models. 

If \code{analysis_type = "rf"} and \code{model = "preModel"}, an object of class \code{randomForest} is returned for the pre-model using all features. See \link[randomForest]{randomForest} for full description of the output object.

If \code{analysis_type = "rf"} and \code{model = "borutaModel"}, an object of class \code{Boruta} is returned with the results of feature selection. See \link[Boruta]{Boruta} for full description of the output object.

If \code{analysis_type = "rf"} and \code{model = "finalModel"}, an object of class \code{randomForest} is returned for the final model using the selected features. See \link[randomForest]{randomForest} for full description of the output object.
}

\references{
Liaw A, Wiener M (2002). “Classification and Regression by randomForest.” R News, 2(3), 18-22. https://CRAN.R-project.org/doc/Rnews/. 

Kursa MB., Witold R. Rudnicki (2010). “Feature Selection with the Boruta Package.” Journal of Statistical Software, 36(11), 1–13. https://doi.org/10.18637/jss.v036.i11.
}

\seealso{
\link[postNet]{featureIntegration} \cr
\link[Boruta]{Boruta} \cr
\link[randomForest]{randomForest}
}

\examples{
 tmp <- tempfile(fileext = ".pdf")

# load and create example data:
 data("postNetExample", package = "postNet")
 ptn <- postNetExample$ptn
 
# Prepare the list of pre-calculated features to be used in feature integration modelling 
 myFeatures <- postNetExample$features
 str(myFeatures)

# Run feature integration modelling using forward stepwise regression:
 ptn <- featureIntegration(ptn = ptn, 
                          features = myFeatures, 
                          pdfName = tmp, 
                          regOnly = TRUE, 
                          allFeat = FALSE,
                          analysis_type = "lm",
                          covarFilt = 20,
                          comparisons = list(c(1,2)),
                          NetModelSel = "omnibus")
                          
# Retrieve the omnibus model from forward stepwise regression analysis:
 finalModel <- ptn_model(ptn, analysis_type = "lm", model = "finalModel", comparison = 1) 
 str(finalModel)
}
