pbreheny / visreg

Visualization of regression functions
http://pbreheny.github.io/visreg/
61 stars 18 forks source link

support for rms objects #83

Closed dylanbeaudette closed 4 years ago

dylanbeaudette commented 4 years ago

The rms package has several fine methods for depiction of partial effects. The visreg package offers additional options and over-all, a simpler interface to the creation complex figures such as the outcome of a multi-nominal logistic regression.

image

Thanks!

Here is a tiny example.

library(rms)

x.1 <- rnorm(20)
x.2 <- rnorm(20)
x.3 <- rnorm(20)
y <- x.1 + x.2 + x.3 + x.1 * x.2 + rnorm(20)

fit <- ols(y ~ x.1 + x.2 + x.3)

## please?
# visreg::visreg(fit)
pbreheny commented 4 years ago

I don't understand what you're asking for. The code

visreg::visreg(fit)

works just fine for your example above. Does it not work for you?

dylanbeaudette commented 4 years ago

Wow! I was using my own examples to test and something strange must have happened. Sorry about that!

For the record the following works as expected:

library(rms)
library(visreg)

x.1 <- rnorm(20)
x.2 <- rnorm(20)
x.3 <- rnorm(20)
y <- x.1 + x.2 + x.3 + x.1 * x.2 + rnorm(20)

fit1 <- ols(y ~ x.1 + x.2 + x.3)
fit2 <- ols(y ~ rcs(x.1, 3) + x.2 + x.3)

par(mfrow=c(2,3))

# works
visreg(fit1)
visreg(fit2)
dylanbeaudette commented 4 years ago

I did notice one small issue: the y-axis labels do not follow the standard convention for lm and other model objects. The graphic output from visreg(ols.model) uses f(varname) as the y-axis label.

Is this by design? Attempting to alter via arguments visreg(ols.model, ylab='MAST', main='Title') resulted in an error:

Error in model.frame.default(Terms, newdata, na.action = na.action, ...) : 
  variable lengths differ (found for '(main)')

This looks like an error emitted by predict.ols.

Any ideas?

Thanks again, this package is going to make my life much simpler.

pbreheny commented 4 years ago

In general, when you pass an option to visreg(), that option is passed along to the relevant predict() function as well. Sometimes this results in a plotting option being passed to predict(); usually this doesn't cause a problem, but that seems not to be the case with predict.ols(). I suppose I could give some thought as to whether this behavior could be improved, but as visreg is currently designed, you'll have to split up your call to visreg() and plot():

v <- visreg(fit, 'x.1')
plot(v, main='main')
dylanbeaudette commented 4 years ago

Thanks for the suggestions!

I was able to get the desired output using:

p <- visreg( fit, plot=FALSE)
plot(p, main='main', ylab='ylab', ...)