更改默认plot.gam图的Y轴 [英] Changing the Y axis of default plot.gam graphs

查看:204
本文介绍了更改默认plot.gam图的Y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用mgcv软件包以以下形式在R中运行GAM:

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

但是,当我在R中使用plot.gam函数时,我的图形的y轴为"s(predictor variable, edf)"

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

我不确定y轴的这个比例代表什么?

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

有没有一种方法可以将y轴范围更改为代表响应的范围,如本文所述:Walsh和Kleiber(2001),蓝鲨的广义加性模型和回归树分析(Prionace glauca)在图3中位于夏威夷的商业延绳钓渔业的捕捞率.

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.

我会发布一些我要描述的情节的例子,但是由于这是我的第一篇文章,我没有至少10个声誉,所以它不会让我这么做!

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!

推荐答案

轴是居中平滑线所取的值.它是该平滑函数对拟合值的贡献(以协变量的值表示).

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.

更改y轴标签很容易-将所需的标签提供给ylab参数.当然,这意味着如果要为每个图分配单独的y轴标签,则必须分别绘制每个平滑图.在这种情况下,还可以使用select参数绘制特定的平滑函数,例如:

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)

我知道更改y轴比例的唯一方法是手动创建绘图.这些图没有模型常数项和其他参数项的贡献.如果您的模型只有一个截距和一个平滑,则可以在该协变量范围内生成新数据,然后从模型中为这些新数据值生成predict,但使用type = "terms"可以得到平滑的贡献.然后,您可以绘制predict返回的值加上predict返回的"constant" 属性的值.

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.

在您的情况下,预测时需要控制其他变量.一种实现方法是,将所有其他协变量设置为均值或典型值,但允许感兴趣的协变量在其范围内变化,就像以前一样.然后,您对predict(shark.gamFINAL, newdata = NEW, type = "terms")返回的矩阵的每一行中的值求和(其中NEW是要预测的新数据帧,改变一个协变量,但将其余变量保持在某个典型值),并再次添加常数.您必须依次对每个协变量重做一次(即每个图一次),因为您需要将其他协变量保持在典型值.

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.

所有这些操作都是通过移动轴上的比例尺来实现的-模型中的所有平滑都不与模型中的其他平滑或项交互,因此也许更容易将y轴视为对响应的影响每顺利?

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?

这篇关于更改默认plot.gam图的Y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆