user3277394
user3277394

Reputation: 41

Swapping axes for a 2-predictor GAM in r

I apologize for such a simple question, but have not been able to find the answer yet perusing the site. I am trying to plot a series of GAM models of invertebrate capture data in R. One of the predictors is always a smoothed term for the day of year number (DOY). This should always occupy the space of the x-axis. The y-axis should be either a linear or smoothed weather variable predictor. With the vis.gam() function, I can produce a surface contour plot with a color gradient representing predicted values of the response for any x-y pair. When the second predictor is nonlinear, as in:

totbest=gam(Totallog10pl1~s(DOY)+s(SRVarDetrendDerived),data=poolREplotGAM)

then the figure looks as it should (apologies for not being able to post images, but here is the plotting command):

vis.gam(totbest, type="response",plot.type="contour",n.grid=50)

But when the predictor is linear:

totbest1=gam(Totallog10pl1~s(DOY)+SRVarDetrendDerived,data=poolREplotGAM)

the axes switch:

vis.gam(totbest1, type="response",plot.type="contour",n.grid=50)

If you have a means of returning the time-related variable to the x-axis, that would be very much appreciated. Thanks in advance for any help.

Mike

Upvotes: 2

Views: 223

Answers (1)

RichAtMango
RichAtMango

Reputation: 386

This would seem to be due to the order in which the var.summary element of the gam object is returned. Try totbest$var.summary vs totbest1$var.summary.

A "fix" would be to do this:

totbest1$var.summary <- totbest1$var.summary[2:1]
vis.gam(totbest1, type="response",plot.type="contour",n.grid=50)

Caveat: I haven't read enough about the gam object to understand whether the reverse order of var.summary is by design.

hope this helps! Rich.

Upvotes: 0

Related Questions