[R] mgcv : 3-way interaction and 3D-plots ?

David Winsemius dwin@emiu@ @ending from comc@@t@net
Tue Jan 8 01:59:00 CET 2019


On 1/7/19 3:35 PM, varin sacha via R-help wrote:
> Dear R-experts,
>
> I have fitted a model with 2-way and 3-way interactions.
> I would like, for the 3-way interaction (year,age,by=education), to obtain 3D-plots. How could I do that ?

Forget ggplot2. It has ignored this sort of visualization effort. Use 
lattice or base plotting methods.


In order to plot a 2way interaction one needs a pseudo-3way plot 
(`wireframe`) or a single `levelplot`. For display of a 3way interaction 
in lattice (given the human minds inability to "see" in 4 dimensions) 
you will need to specify levels for one of the variables to display 
slices perhaps using multiple displays of 2way "sub-interactions" 
calculated ad meaningul levels of the variable you choose to slive 
with.  I'm not sure what the "native" plotting method for pkg:mgcv might 
be. I suspect it was base graphics,; if so, look at ?persp and ?contour.

-- 

David

>
> Many thanks for your response.
>
> Here is the reproducible example:
>
> #############
> install.packages("ISLR")
>
> library(ISLR)
>
> install.packages("mgcv")
>
> library(mgcv)
>
> mod1<-gam(wage ~education+s(age,bs="ps")+year+te(age,year,bs="ps")+s(year,bs="ps",by=education,m=1)+te(year,age,by=education,bs=rep("ps",2)),data=Wage)
>
> plot(mod1)
> #############
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list