Correct level setting of factor outcome for training a dataset with train function of caret R package i would like to ask a specific question about machine learning implementation procedures in R, and especially about caret R package and randomForests:
if i want to use the function train from the caret package regarding a binary outcome of a categorical variable, then i have to set the level of the factor i want to predict as the first level ? i.e if "cancer" is the status i want to predict from a categorical variable "Disease"(control and cancer the levels), i have to set it as the first level ?
Moreover, this also is the case instead for using the function randomForests ? Or for the second function it is irelevant and it is not important ?
Please excuse me for my naive questions, but im new in machine learning !!
Thank you,
Efstathios
 A: In most cases, including caret, it doesn't really matter. 
The outcome data and predictions are handled by factors so they understand that there are two possible values. When using train for prediction, you get all the class probabilities. 
For the predictors (it's hard to tell from your question what variable you are talking about), it doesn't really matter either. If you use the formula method to train it will use the first level of the factor as the reference cell and give you indicates for the other levels. For example:
> levels(iris$Species)
[1] "setosa"     "versicolor" "virginica" 
> colnames(model.matrix(~., data = iris))
[1] "(Intercept)"       "Sepal.Length"      "Sepal.Width"      
[4] "Petal.Length"      "Petal.Width"       "Speciesversicolor"
[7] "Speciesvirginica" 

However, with trees and some other models, they don't have to use dummy variables since they can make splits such as if Species in {versicolor, virginica}.  With train, you should use the non-formula method if you want to avoid automatic creation of dummy variables. 
With many of the underlying tree models (e.g. randomForest, C5.0, bagging, etc), the formula method does not generate dummy variables. This completely makes sense for those models but is different from how most model functions work with formulas and can cause confusion. 
Max
