I wanted to understand more about whether my implementation of the multivariate adaptive regression splines is correct. I have crop yield data from multiple locations and year and I want to predict yield as a function of location, year and some climate variables.

Before running mars (from earth package), I converted location and year as factors in R

dat$year <- as.factor(dat$year)
dat$location.id <- as.factor(dat$location.id) 

I also converted yield values into log to avoid negative prediction

 dat$log.yld <- log(dat$yld)

And then fitted my model:

earth(x = dat[,index of predictors that include climate + loc + year],
      y = dat[,65], # position of my log yield values
      degree =2, 
      pmethod = "cv",
      nfold = 10,
      ncross = 3)

Is my implementation above is correct? How does earth handle categorical predictors like I have with location and year?

Thank you

  • $\begingroup$ General comment: It's always good to determine the sample size required for a method to yield reliable results. MARS requires a much greater sample size than a parametric model if the parametric model is known not to need many interaction terms. $\endgroup$ Aug 26, 2023 at 11:32

1 Answer 1


The factors are expanded (into dummy variables ) before being fed to the algorithm http://www.milbo.org/doc/earth-notes.pdf

  • 3
    $\begingroup$ please add full reference for your link and summarize why it supports your answer $\endgroup$
    – Antoine
    Nov 5, 2020 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.