Coder Social home page Coder Social logo

pedometrics_5.2_importance_reg's Introduction

Title Authors
Importance - Regression
Fernandes-Filho, Elpídio Inácio; Moquedace, Cássio Marques; Pereira, Luís Flávio; Veloso, Gustavo Vieira; Carvalho Junior, Waldir

Loading packages

pkg <- c("dplyr", "ggplot2", "stringr", "tidyr", "RColorBrewer", "data.table")
sapply(pkg, require, character.only = T)

Cleaning the environment (removing objects and previously loaded packages)

rm(list = ls())  
gc()

Loading importance data

df_imp <- list.files(path = "./regression", pattern = ".csv$", full.names = T, recursive = T) %>% 
  grep(pattern = "imp_pred_TOTAL", value = T) %>% 
  read.csv2()

Categorical predictors

varfact <- c("geology", "drainage", "landforms_tpi_based",
             "surface_specific_points", "lulc",
             "terrain_surface_classification_iwahashi", "soil", "slope_idx",
             "valley_idx") %>% sort()

for (h in seq_along(varfact)) {
  
  df_imp <- df_imp %>% 
    mutate(predictor = str_replace(predictor, paste0(".*", varfact[h], ".*"),
                                   varfact[h]))
  
}

Calculating average importance of categorical variables

df_imp <- df_imp %>% 
  group_by(rep, predictor) %>% 
  summarise(importance = mean(importance))

Loading a dataframe with final name of variables and function for counting repetitions

n_cova <- read.csv2("./data/name_cova.csv")

print(n_cova)

dfg_imp <- left_join(df_imp, n_cova, by = c("predictor" = "name_abr")) 

n_fun <- function(x) {
  return(data.frame(y = 3.5 * 30,
                    label = length(x)))
}

Plotting boxplots

imp_pred <- ggplot(dfg_imp, aes(x = importance,
                                y = reorder(name_comp, importance,
                                            decreasing = T))) +
  stat_boxplot(geom = "errorbar", size = 0.5) +
  geom_boxplot(color = "black", fill = "grey40") +
  scale_y_discrete(limits = rev) +
  labs(y = "Predictor", fill = "Depth (cm)",
       x = "Relative importance (%)", y = NULL) +
  scale_x_continuous(expand = c(0.01, 0, 0.05, 0)) +
  theme(axis.ticks = element_line(color = "black"),
        panel.background = element_blank(),
        panel.border = element_rect(fill = NA, inherit.blank = T),
        panel.grid = element_line(colour = "grey90"),
        axis.text = element_text(color = "black", size = 15),
        axis.title = element_text(color = "black", size = 15)) +
  stat_summary(fun.data = n_fun, geom = "text", col = "red", size = 4,
               hjust = 0.5, position = position_dodge(0.6),
               fontface = "bold") +
  stat_summary(fun = mean, geom = "point", col = "red", shape = 15, size = 1.5,
               position = position_dodge(0.75)) ; imp_pred

pedometrics_5.2_importance_reg's People

Contributors

moquedace avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.