title: How to do the CV test to examine the classification error of LDA in R
body: <p>Please give me a simple example. I am in worry! I have tried the errorest function and do it as the example as it give for 10-fold cv of LDA. But when I used my own data, it just said the predict is not numeric. I don't know why! Thank you!
  The R code is like this. I want to do the binary LDA so I generate the data:</p>
  
  <pre><code>library(MASS)
  n=500
  #generate x1 and x2. 
  Sigma=matrix(c(2,0,0,1),nrow=2,ncol=2)
  #Logistic model with parameter{1,4,-2}
  beta.star=c(1,4,-2)
  Xtilde=mvrnorm(n=n,mu=c(0.5,2),Sigma=Sigma)
  X=cbind(1,Xtilde)
  z=X%*%beta.star
  #pass througn an inv-logit function
  pr=exp(z)/(1+exp(z))
  #Simulate binary response
  # The "probability of respoonse is a vector"
  y=rbinom(n,1,pr)
  </code></pre>
  
  <p>Then I use the LDA to get the model:</p>
  
  <pre><code>library(MASS)
  df.cv=data.frame(V1=Xtilde[,1],V2=Xtilde[,2])
  exper1&lt;-lda(y~V1+V2,data=df.d)
  plda&lt;-predict(exper1,newdata=df.cv)
  </code></pre>
  
  <p>Finally I want to use the CV with th original data and see the error. I do this which is wrong:</p>
  
  <pre><code>mypredict.lda &lt;- function(object, newdata)
    predict(object, newdata = newdata)$class
  errorest(y ~ ., data=data.frame(da), model=lda,estimator ="cv", predict= as.numeric(mypredict.lda))
  </code></pre>
  
  <p>What should I do to get the error with CV?</p>