# eliminating outliers in MARS regression

I using the regression method called MARS, in R is it called earth and is located in the package earth, in order to find the best regression model for my datat.

I know that this method is suitable for large data-sets, can handle NA and also decides which variables will be used and which not into the regression.

What I'm doing

After the regression is estimated, I detect the outliers using boxplot and then I eliminate from the data the observations which are extreme values and compute the model again.

I do this until maximum of grsq and rsq are found.

CODE

model <- earth(log(price) ~ ., data = data, weights = weights)
max_grsq <- round(model$grsq, digits = 4) max_rsq <- round(model$rsq, digits = 4)
min_diff <- abs(max_grsq - max_rsq)

while(!done) {
residuals_abs <- abs(model$residuals) boxplot <- boxplot(residuals_abs, plot=F) indexes_to_remove <- c(which((residuals_abs > boxplot$stats[4]) == T), which((residuals_abs < boxplot$stats[2]) == T)) if (length(indexes_to_remove) > 0) { data <- data[-indexes_to_remove, ] distances <- distances[-indexes_to_remove] weights <- (1/distances)/(sum(1/distances)) } tempModel <- earth(log(price) ~ ., data = data, weights = weights) temp_grsq <- round(tempModel$grsq, digits = 4)