title: confusionMatrix for logistic regression in R
body: <p>I want to calculate two confusion matrix for my logistic regression using my training data and my testing data:</p>
  
  <pre><code>logitMod &lt;- glm(LoanStatus_B ~ ., data=train, family=binomial(link="logit"))
  </code></pre>
  
  <p>i set the threshold of predicted probability at 0.5:</p>
  
  <pre><code>confusionMatrix(table(predict(logitMod, type="response") &gt;= 0.5,
                        train$LoanStatus_B == 1))
  </code></pre>
  
  <p>And the the code below works well for my training set.
  However, when i use the test set:</p>
  
  <pre><code>confusionMatrix(table(predict(logitMod, type="response") &gt;= 0.5,
                        test$LoanStatus_B == 1))
  </code></pre>
  
  <p>it gave me an error of </p>
  
  <pre><code>Error in table(predict(logitMod, type = "response") &gt;= 0.5, test$LoanStatus_B == : all arguments must have the same length
  </code></pre>
  
  <p>Why is this? How can I fix this? Thank you!</p>