Message-ID: <96346275.28234122.1540845992354@mail.yahoo.com>
Date: 2018-10-29T20:46:32Z
From: varin sacha
Subject: MSE Cross-validation with factor interactions terms MARS regression
Dear R-experts,
I am having trouble while doing crossvalidation with a MARS regression including an interaction term between a factor variable (education) and 1 continuous variable (age). How could I solve my problem ?
Here below my reproducible example.
#######
install.packages("ISLR")
library(ISLR)
install.packages("earth")
library(earth)
a<-as.factor(Wage$education)
# Create a list to store the results
lst<-list()
# This statement does the repetitions (looping)
for(i in 1?:200) {
n=dim(Wage)[1]
p=0.667
sam=sample(1?:n,floor(p*n),replace=FALSE)
Training =Wage [sam,]
Testing = Wage [-sam,]
mars5<-earth(wage~age+education+year+age*a, data=Wage)
ypred=predict(mars5,newdata=Testing)
y=Testing$wage
y=Wage[-sam,]$wage
MSE = mean(y-ypred)^2
MSE
lst[i]<-MSE
}
mean(unlist(lst))
summary(mars5)
#######