title: PLSR in R with "pls" package
body: <p>I'm trying to fit PLSR model, but I'm doing something wrong. Below, you can see how I created data frame and its structure.</p>
  
  <pre><code>reflektance &lt;- read_excel("data/reflektance.xlsx", na = "NA")
  reflektance &lt;- dput(reflektance)
  pH &lt;- read_excel("data/rijen2016.xls", na = "NA")
  pH &lt;- na.omit(pH)
  pH &lt;- dput(pH)
  
  reflektance&lt;-aggregate(reflektance[, 2:753], list(reflektance$Vzorek), mean)
  colnames(reflektance)[colnames(reflektance)=='Group.1']&lt;-'Vzorek'
  datapH &lt;- merge(pH, reflektance, by="Vzorek")
  datasetpH &lt;- data.frame(pH=datapH[,2], ref=I(as.matrix(datapH[, 3:754], 22, 752)))
  </code></pre>
  
  <p>Problem is with using "plsr", because result is this error:</p>
  
  <pre><code>ph1&lt;-plsr(pH ~ ref, ncomp = 5, data=datasetpH)
  Error in pls::mvr(ref ~ pH, ncomp = 5, data = datasetpH, method = "kernelpls") : 
  Invalid number of components, ncomp
  </code></pre>
  
  <p>dput(reflectance):
  <a href="https://jpst.it/RyyS" rel="nofollow noreferrer">https://jpst.it/RyyS</a></p>
  
  <p>Here you can see structure of table datapH:</p>
  
  <pre><code>'data.frame':   22 obs. of  754 variables:
   $ Vzorek: chr  "5 - P01" "5 - P02" "5 - P03" "5 - R1 - A1" ...
   $ pH/H2O: num  6.96 6.62 7.02 5.62 5.97 6.12 5.64 5.81 5.61 5.47 ...
   $ 325   : num  0.017 0.0266 0.0191 0.0241 0.016 ...
   $ 326   : num  0.021 0.0263 0.0154 0.0264 0.0179 ...
   $ 327   : num  0.0223 0.0238 0.0147 0.028 0.0198 ...
   ...
  </code></pre>
  
  <p>And here structure of table datasetpH:</p>
  
  <pre><code>'data.frame':   22 obs. of  2 variables:
   $ pH : num  6.96 6.62 7.02 5.62 5.97 6.12 5.64 5.81 5.61 5.47 ...
   $ ref: AsIs [1:22, 1:752] 0.016983.... 0.026556.... 0.019059.... 0.024097.... 0.016000.... ...
    ..- attr(*, "dimnames")=List of 2
    .. ..$ : NULL
    .. ..$ : chr  "325" "326" "327" "328" ...
  </code></pre>
  
  <p>Do you have any advice and solution? Thank you</p>