Skip to content

Instantly share code, notes, and snippets.

@BenHeubl
Created February 13, 2020 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenHeubl/652fba89132ee4b4a94e3c2ab2d46867 to your computer and use it in GitHub Desktop.
Save BenHeubl/652fba89132ee4b4a94e3c2ab2d46867 to your computer and use it in GitHub Desktop.
tut13
install.packages("relaimpo")
library(relaimpo)
#fit linear model:
Ozone_model <- lm(ozone_reading ~ . , data = Ozone)
#Get relative importance:
Relative_importance <- calc.relimp(lmMod, type = "lmg", rela = TRUE)
# Relative importance scaled to 100 and plot:
plot_RI <- as.data.frame(sort(relImportance$lmg, decreasing=TRUE))
colnames(plot_RI)[1] = 'value'
plot_RI$ID <- seq.int(nrow(plot_RI))
ggplot(plot_RI, aes(ID, value)) +
geom_point(col = 'blue') +
geom_text(label = rownames(plot_RI), nudge_y = 0.042) +
ylim(c(0,0.3)) +
coord_flip() +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment