title: Using caret to optimize for deviance with binary classification
body: <p>(example borrowed from <a href="https://stackoverflow.com/questions/21095477/fatal-error-with-train-in-caret-on-windows-7-r-3-0-2-caret-6-0-21">Fatal error with train() in caret on Windows 7, R 3.0.2, caret 6.0-21</a>)</p>
  
  <p>I have this example:</p>
  
  <pre><code>library("AppliedPredictiveModeling")
  library("caret")
  
  data("AlzheimerDisease")
  data &lt;- data.frame(predictors, diagnosis)
  
  tuneGrid &lt;- expand.grid(interaction.depth = 1:2, n.trees = 100, shrinkage = 0.1)
  trainControl &lt;- trainControl(method = "cv", number = 5, verboseIter = TRUE)
  
  gbmFit &lt;- train(diagnosis ~ ., data = data, method = "gbm", trControl = trainControl, tuneGrid = tuneGrid)
  </code></pre>
  
  <p>But let's say I want to optimize with regards to deviance (which is what I believe gbm returns by default) instead of accuracy. I know that trainControl offers a summaryFunction argument. How do I write a summaryFunction that will optimize for deviance?</p>