title: R function error, "no applicable method for 'predict' applied to an object of class "NULL"
body: <p>I am trying to use a function to generate a series of KS test's p values. In my case, I wish to choose different first M[i] rows from my aaa dataset and after a few steps process to generate the predict glm regression values dd, and finally compare every two datasets to get a KS test's p values. But my code didn't work well. I attached my code in the following using simulated data:</p>
  
  <pre><code>set.seed(1)
  aaa &lt;- matrix(runif(8000*950), 8000, 950)
  ph = sample(rep(0:1,l=950))
  kst &lt;- function(M){
    N = length(M)
    aa = list()
    bb = list()
    cc = list()
    dd = list()
    ee = list()
    p = 0
    for (i in 2:N){
      aa[[i]] = aaa[1:M[i],] ## class(aaa) is matrix 
      bb[[i]] = rbind(ph, aa[[i]])
      cc[[i]] = as.data.frame(t(bb[[i]]))
      dd[[i]] = glm(data = cc[[i]], formula = ph~., family = binomial)
      ee[[i]] = ks.test(predict(dd[[i-1]]), predict(dd[[i]]))
      p[i] = ee[[i]]$p.value
    }
    return(p)
  }
  kst(M = seq(50,950,by=50))
  </code></pre>
  
  <p>but R said: </p>
  
  <pre><code>&gt; kst(M = seq(50,950,by=50))
  Error in UseMethod("predict") : 
    no applicable method for 'predict' applied to an object of class "NULL"
  </code></pre>
  
  <p>I think my ks.test loop also has error in it, but I did not know how to fix it.
  Could anyone help me about this? Thanks in advance. </p>