This post is a sequel to my wildly popular – ok, not wildly popular, but very useful for me – post documenting my function to create a forest plot. Recently, I made models using cross-validation via R’s caret package. The train() function does the heavy lifting, but the problem is that its output is a of the train class, which I presume was created for caret. This is a problem because my function assumes it is receiving a generic model, so it fails.
The new function, pasted at the end of this post, makes two modifications. The main modification is to take the coefficients from model$finalModel$coefficients. You of course could pass those directly to the model argument in forestPlot, but that would require more typing, and I am lazy. The second update, which is not because of train, it to add na.rm=TRUE to min() and max(). Those arguments should have been in the original function, oh well. The third change is simply to change the x-axis label, which is hard coded. That should probably be an argument to pass to the function; oh well.
In response to demand from Alex Hughes, I have included an example of the output. Initial results suggest that violence, small groups, children, and seeing more individuals protest correlates with larger protests in the future, while the presence of police and large groups correlates with smaller protests.
This formula has been updated to handle results of train class, from caret package.
The purpose of this script is to define an R function that makes pretty forest plots based on regression results.
NB: This plotting works best when the coefficients have similar values, i.e. consider standardizing your variables.