title: How to use principle components selected by PCR in further SVR analysis?
body: <p>I want to use principle component regression to find essential components and then extract those components to apply further SVR analysis, but I got some problems when doing this.</p>
  
  <p>First try, I follow the suggestions from: <a href="https://stackoverflow.com/questions/20505613/how-to-extract-components-after-performing-principal-component-regression-for-fu">How to extract components after performing principal component regression for further analysis in R caret package</a>
  And here is my code:</p>
  
  <pre><code>library(caret)
  library(tidyverse)
  library(pls)
  library(e1071)
  library(kernlab)
  
  # Load the data
  data("Boston", package = "MASS")
  # Split the data into training and test set
  set.seed(123)
  training.samples &lt;- Boston$medv %&gt;% createDataPartition(p = 0.8, list = FALSE)
  train.data  &lt;- Boston[training.samples, ]
  test.data &lt;- Boston[-training.samples, ]
  set.seed(1)
  sigDist &lt;- sigest(medv~., data = train.data, frac = 1)
  
  svrGrid &lt;- expand.grid(.sigma = sigDist, .C = 2^(-2:7))
  set.seed(2)
  svrPCR &lt;- train(medv~., data = train.data,
                  method = "svmLinear",
                  tuneGrid = svrGrid,                  
                  preProcess = c("center","scale","pcr"), # if center and scale needed
                  trControl=trainControl("LOOCV"))
  </code></pre>
  
  <p>Here is my error:</p>
  
  <pre><code>Error: The tuning parameter grid should have columns C
  </code></pre>
  
  <p>Second try, I simply extract <code>[[scores]]</code>from pcr results, then use them in svr:</p>
  
  <pre><code>pcr_model &lt;- pcr(medv~., data = train.data, scale =TRUE, validation = "LOO")
  engivaluepcr=as.data.frame(pcr_model[['scores']][,1:13])
  engivaluepcr=cbind(train.data$medv,engivaluepcr)
  setnames(engivaluepcr,"train.data$medv","medv")
  pcrsvr &lt;- svm(medv ~ ., engivaluepcr, validation = "LOO",kernel='linear')
  pred_test2 &lt;-predict(pcrsvr,test.data)
  </code></pre>
  
  <p>And here is my new error:</p>
  
  <pre><code>Error in eval(predvars, data, env) : object 'Comp 1' not found
  </code></pre>
  
  <p>Maybe those two ways above are both not good methods. Please give me some suggestions about how to use the result from pcr in further svr analysis, or maybe just help me to solve those errors above.</p>
  
  <p>Thanks,
  -C.T.</p>
  
  <p>Edit 1:
  I just figure out, when using <code>method = "svmLinear"</code> we don't need <code>.sigma</code> in <code>svrGrid</code>. After eliminating sigma, I can get my result successfully.
  Hope this can be helpful to others.
  -C.T.</p>