

FlashChat  Actuarial Discussion  Preliminary Exams  CAS/SOA Exams  Cyberchat  Around the World  Suggestions 


Thread Tools  Search this Thread  Display Modes 
#1




Graphing GLMs in R
Hi  I'm using R to fit GLMs to client data, which is working quite well (using the RevoAnalytics package). I'd like to put some code together to produce some of the usual graphical output that a proprietary package like Emblem can spit out. Things like:
* Plots of linear predictor/predicted value vs variable level (1 variable at a time) * Residual plots Rather than reinventing the wheel, I'm wondering if anyone reading this has any prewritten code to do this kind of thing  something they might be prepared to share? (cheeky request) Thanks! 
#2




Quote:
Most common graphing package that I know of is ggplot2. I didn't quite understand your example of [* Plots of linear predictor/predicted value vs variable level (1 variable at a time)]  are you saying you have a factor with different levels, and you want to see the distribution by each level? Like sidebyside boxplots? Or are you just looking to plot one predictor variable against target variable in a scatter / fitted plot? Might want to look into partial dependence plots for that. Boxplots: ggplot(data = yourdf, mapping = aes(x = factorvariable, y = responsevariable)) + geom_boxplot() should get something basiccan tune or clean up, add labels, etc. as desired. Note that it's as easy as changing geom_boxplot() to geom_point() or geom_histogram() or whatever you want to plot, and you can change your x and y variables accordingly. There's a lot of customization and freedom, so I won't pretend to try to guess exactly what you want, but maybe you can clarify and we can get closer 
#3




Thank you.
The rxGlm() function within the RevoAnalytics package produces its own peculiar model objects which aren't the same as the objects produced by glm(). However there is a useful as.glm() function within the RevoAnalytics package which performs a conversion to the standard glm object. On your question about the graphs...I've uploaded an example (I think) of the sort of graph I'm thinking of. So it's for a single predictor variable, showing the linear predictor from the GLM fit on the vertical axis and the levels of the predictor variable on the horizontal axis and also 2 standard errors either side (ie rough 95% CI type illustration). I had to construct this manually in Excel though, by copying and pasting from R and then creating the graph. Very tiresome! Also shows exposure on a secondary axis. [Also I've included a smoothed GLM fit in this graph (the green data series) although that's not essential. This is the result of a second, simplified GLM fit.] 
Thread Tools  Search this Thread 
Display Modes  

