title: Subscript out of bounds error while computing accuracy at different cutoffs
body: <p>I have constructed a logistic regression and now I want to calculate the predictive accuracy for various cutoff values ranging from 0 to 1. This is the for loop I have been using. But I am getting </p>
  
  <blockquote>
    <p>subscript out of bounds</p>
  </blockquote>
  
  <p>Here predtrain contains 300 predicted output probabilities each ranging from 0 to 1. Each value is compared to cutoff <code>eff</code>. Finally a table/confusion matrix has to be generated comparing the original values (train$CAN) with f1. Some thing like this:</p>
  
  <pre><code>tab
  # pred2
  #     0   1
  # 0   1  93
  # 1   0 206
  </code></pre>
  
  <p>code I have written is this: </p>
  
  <pre><code>predtrain &lt;- predict(logreg1, newdata = train, type = 'response')
  eff&lt;-seq(0,1,by = 0.05)
  for (i in 1:length(eff) {          
    f1 &lt;- ifelse(predtrain &gt; eff[i], 1, 0)
    t1 &lt;- table(train$CAN, f1)
    effy &lt;- (t1[1,1]+t1[2,2])/(t1[1,1]+t1[1,2]+t1[2,2]+t1[2,1])
    eff[[i]] &lt;-effy 
  }
  </code></pre>