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

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Mon Oct 29 23:50:15 CET 2018


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 <bgunter.4567 using gmail.com> 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 <r-help using r-project.org> 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)
> 
> #######
> 
> ______________________________________________
> R-help using r-project.org 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.
> 




More information about the R-help mailing list