Changing the Y axis of default plot.gam graphs

家住魔仙堡 提交于 2019-12-19 04:50:44

问题


I have run a GAM in R using the mgcv package with the following form:

shark.gamFINAL <- gam(ln.raw.CPUE...0.1 ~ Year + Month + 
                      s(Mean.Temp, bs = "cr") + s(Mean.Chl.a, bs = "cr") + 
                      s(Mean.Front.density, bs = "cr"), data=r, family=gaussian)

After running this model and calculating the percentage deviance explained by each variable I would like to plot the effect of each variable against the response

However when I use the plot.gam function in R my graphs come out with a y axis that is "s(predictor variable, edf)"

I am not sure what this scale of the y axis represents?

Is there a way that I could change the y axis range to that which represents the response, as has been done in this paper: Walsh and Kleiber (2001), 'Generalized additive model and regression tree analyses of blue shark (Prionace glauca) catch rates by the Hawaii-based commercial longline fishery' in FIGURE 3.

I would have posted some examples of the plots I am describing but as this is my first post I do not have at least 10 reputation, so it won't let me do it!

I have searched many sites and forums to try and find an answer for this, but to no avail, any help would therefore be hugely appreciated!


回答1:


The axis is the value taken by the centred smooth. It is the contribution (at a value of the covariate) made to the fitted value for that smooth function.

It is easy to change the y axis label - supply the one you want to the ylab argument. This of course means you have to plot each smooth separately if you want a separate y-axis label for each plot. In that case also use the select argument to plot specific smooth functions, for example:

layout(matrix(1:4, ncol = 2, byrow = TRUE)
plot(shark.gamFINAL, select = 1, ylab = "foo")
plot(shark.gamFINAL, select = 2, ylab = "bar")
plot(shark.gamFINAL, select = 3, ylab = "foobar")
layout(1)

The only way I know to change the scale of the y-axis is to build the plot by hand. Those plots are without the contribution from the model constant term, plus the other parametric terms. If your model only had an intercept and one smooth, you could generate new data over the range of that covariate and then predict from the model for these new data values but use type = "terms" to get the contribution for the smooth. You then plot the value returned from predict plus the value of the "constant" attribute returned by predict.

In your case, you need to control for the other variables when predicting. One way to do that is to set all the other covariates to their means or typical value but allow the covariate of interest to vary over its range, as before. You then sum up the values in each row of the matrix returned by predict(shark.gamFINAL, newdata = NEW, type = "terms") (where NEW is the new data frame to predict at, varying one covariate but holding the rest at some typical value), again adding on the constant. You have to redo this for each covariate in turn (i.e. once per plot) as you need to keep the other covariates held at the typical value.

All this does is shift the scale on the axis though - none of the smooths in your model interact with other smooths or terms in the model so perhaps it might be easier to think of the y-axis as the effect on the response for each smooth?



来源:https://stackoverflow.com/questions/15764810/changing-the-y-axis-of-default-plot-gam-graphs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!