# MSE Cross-validation with factor interactions terms MARS regression

5 messages
Open this post in threaded view
|

## 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) ####### ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: MSE Cross-validation with factor interactions terms MARS regression

 I did no analysis of your code or thought process, but noticed that you had the following two successive lines in your code: y=Testing\$wage y=Wage[-sam,]\$wage This obviously makes no sense, so maybe you should fix this first and then proceed. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Oct 29, 2018 at 1:46 PM varin sacha via R-help <[hidden email]> wrote: > > 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) > > ####### > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: MSE Cross-validation with factor interactions terms MARS regression

 Hi Bert, Many thanks, I have fixed it but it still don't work... . Best, Le lundi 29 octobre 2018 à 22:07:26 UTC+1, Bert Gunter <[hidden email]> a écrit : I did no analysis of your code or thought process, but noticed that you had the following two successive lines in your code: y=Testing\$wage y=Wage[-sam,]\$wage This obviously makes no sense, so maybe you should fix this first and then proceed. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Oct 29, 2018 at 1:46 PM varin sacha via R-help <[hidden email]> wrote: > > 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) > > ####### > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: MSE Cross-validation with factor interactions terms MARS regression

Open this post in threaded view
|