I’m trying to implement the Partial Least Squares Regression model in R using the pls
package. The following data frame represents my data, where I have two response variables and three explanatory variables.
library(pls)
df <- data.frame(x1 = rnorm(20),
x2 = rnorm(20),
x3 = rnorm(20),
y1 = rnorm(20),
y2 = rnorm(20))
model <- plsr(c(y1, y2) ~ x1+x2+x3, ncomp = 3, scale = TRUE, data = df)
However, when I run the model, I always get an error message.
Error in model.frame.default(formula = c(y1, y2) ~ x1 + x2 + x3, data = df) : variable lengths differ (found for 'x1')
I believe that the data frame is not correctly structured. Would anyone have any suggestions?