What is the difference between lm() function and caret::train() function when it comes to creating linear regression models : RSTUDIO

Viewed 13

When applying the lm function as follows (the assumptions were not considered. The purpose of this example is just to make my question clear) :

library(carData)

model1 = lm(data = carData::Salaries,salary~sex+yrs.service+yrs.since.phd)

and comparing it with the model created with the function caret::train() (method = "lm") :

library(caret)

mycontrol = trainControl(method = "CV",number=10,)

model2 = train(salary~sex+yrs.service+yrs.since.phd,
               data = Salaries,
               method = "lm",
               trControl=mycontrol)

The outcomes of the two models are the same. why ? and in that case what is the purpose of applying the cross validation method in order to create a linear regression model ?

summary(model1)
summary(model2)
0 Answers
Related