[R] MSE Cross-validation with factor interactions terms MARS regression

varin sacha v@rin@@ch@ @ending from y@hoo@fr
Mon Oct 29 21:46:32 CET 2018


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)

#######



More information about the R-help mailing list