This is a set of functions that I use somewhat regularly. These are currently to do with decision trees and plotting multiple imputation.
My general workflow in R is to make a function after I copy and paste some code more than once. Sometimes I find myself using these functions more than once, across different papers. So I decided to make an R package with a few of these functions, called “neato”. I called it this in the hope that one day someone will find one of these functions and say: “neato!”, because hey, it’s pretty neat!
I hope that the more I write into this package, the better I’ll get at writing R packages and the more I can contribute to the R community. I’d also like to thank people like Hadley Wickham and Hilary Parker for writing materials that inspire me and help me contribute to R.
The below functions all work (mostly!) for objects of class rpart
, gbm.step
, and randomForest
, and train
(from the caret
package...these are still under development).
importance_table
Create a tidy dataframe of importance values
library(rpart) kyphosis_rpart <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis) library(neato) # before neato kyphosis_rpart$variable.importance # after neato importance_table(kyphosis_rpart) library(randomForest) set.seed(71) iris_rf <- randomForest(Sepal.Width ~ ., data=iris) # before neato iris_rf$importance # after neato importance_table(iris_rf)
importance_plot
Plot importance values
importance_plot(kyphosis_rpart) # importance_plot(iris_rf) # currently broken...
Obtain the residual sums of squares
only for gbm.step
Create a ggplot of a given list of variables for an imputed object of class "mids" from the mice
package.
Does not work for gbm, only gbm.step. Get the source code for gbm.step here
Partial dependence only works for gbm.step
. Would like to generalize to rpart
, randomForest
, and train
.
recently importance_plot
is broked for .randomForest. Looking into fixing this before March
I have a great desire to make the decision tree specific functions work for all decision tree packages, as I feel like there are certain things that you want to do when you're looking at decision trees, and that is:
And the plots often provided with the packages give you what you need, but they aren't immediately of publishable quality. And I'd like to change that by making them output ggplot objects.
In the future this work will be expanded to include other decision trees, and might even be made into a seperate decision tree tool package. I don't know what I would call it, but probably some sort of tree-related pun, like secateurs
or something. Although that is hard to spell, so maybe something else like topiary
or clippers
. I am open to suggestions!
Possible suggestions:
topiary
topiRy
bonsai
ikebana
secatur
treezy
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.