pbreheny / visreg

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

Three way interactions #11

Closed pbreheny closed 8 years ago

pbreheny commented 8 years ago

Jens Oldeland (University of Hamburg) writes:

...I run a model with an 3way interaction and have to visualize it somehow...

pbreheny commented 8 years ago

As far as how to visualize higher-order (3+) interactions, there is no explicit functionality in visreg to accomplish this, but you can piece together what I would consider an acceptable model visualization with a few separate calls to visreg using different 'cond' arguments.

For example, suppose we fit the model

fit <- lm(Ozone ~ Solar.R*Wind*Temp, data=airquality)

We can then construct two separate plots:

visreg(fit, 'Wind', by='Temp', cond=list(Solar.R=100), layout=c(3,1))
visreg(fit, 'Wind', by='Temp', cond=list(Solar.R=300), layout=c(3,1))

The first plot represents what the Wind x Temp interaction looks like for a solar radiation level of 100, the second depicts what the Wind x Temp interaction looks like for a solar radiation level of 300.

I'll be the first to admit that, for a variety of reasons, this is not as good as having visreg automatically handle higher-order interactions. Improving support for higher-order interactions is on my to-do list as far as future improvements for visreg, but I've been busy with other, non-visreg things lately.

oldi commented 8 years ago

Hi that pretty much is a perfect work around! many many thanks!