简体   繁体   中英

Changing the units in a contour plot from vis.gam in mgcv

I'm fitting a model using the log of a variable, and I'd like to present my results in terms of that variable transformed. Here is a simple example:

library(mgcv)
N = seq(from=1,to=10,by=.01)
a = N^2
b = 1/N
y = log(a*b*runif(length(N)))
mod = gam(y~te(a,b))
vis.gam(mod, plot.type="contour")

I'd like to produce the same graph, but based on exp(y) instead of y.

Any ideas how to do this? Thanks in advance.

As often happens, the solution occurred to me immediately after asking the question.

Just type vis.gam and get the function. Copy/paste it into the script file. It is a long function. Somewhere midway:

fv <- predict.gam(x, newdata = newd, se.fit = TRUE, type = type)
fv$fit = exp(fv$fit)   #INSERT THIS LINE HERE WITH WHATEVER FUNCTION YOU WANT TO MODIFY THE FITTED VALUES BY
z <- fv$fit

Then change the function name to "mod.vis.gam" or something, and use it like any function. Works great. Note that SE's aren't affected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM