简体   繁体   English

更改默认plot.gam图的Y轴

[英]Changing the Y axis of default plot.gam graphs

I have run a GAM in R using the mgcv package with the following form: 我使用mgcv包在R中运行GAM,格式如下:

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 ay axis that is "s(predictor variable, edf)" 但是,当我在R中使用plot.gam函数时,我的图形出现了一个"s(predictor variable, edf)""s(predictor variable, edf)"

I am not sure what this scale of the y axis represents? 我不确定y轴的这个比例代表什么?

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. 有没有办法可以将y轴范围更改为代表响应的范围,如本文所述:Walsh和Kleiber(2001),'蓝鲨(Prionace glauca)捕获的广义加性模型和回归树分析图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! 我会发布一些我正在描述的情节的例子,但由于这是我的第一篇文章,我没有至少10个声望,所以它不会让我这样做!

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. 它是对该平滑函数的拟合值的贡献(在协变量的值处)。

It is easy to change the y axis label - supply the one you want to the ylab argument. 更改y轴标签很容易 - 提供您想要的ylab参数。 This of course means you have to plot each smooth separately if you want a separate y-axis label for each plot. 这当然意味着如果您想为每个绘图分别设置y轴标签,则必须单独绘制每个平滑图。 In that case also use the select argument to plot specific smooth functions, for example: 在这种情况下,还可以使用select参数绘制特定的平滑函数,例如:

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. 我知道更改y轴刻度的唯一方法是手动构建绘图。 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. 如果您的模型只有一个截距和一个平滑,您可以在该协变量范围内生成新数据,然后从模型中predict这些新数据值,但使用type = "terms"来获得平滑的贡献。 You then plot the value returned from predict plus the value of the "constant" attribute returned by predict . 然后,绘制从返回的值predict加上价值"constant"通过返回的属性 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. 然后,你总结了由predict(shark.gamFINAL, newdata = NEW, type = "terms")返回的矩阵的每一行中的值predict(shark.gamFINAL, newdata = NEW, type = "terms") (其中NEW是要预测的新数据帧,改变一个协变量,但保留其余的一些典型值),再加上常数。 You have to redo this for each covariate in turn (ie 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? 所有这一切都是在轴上移动比例 - 模型中没有任何平滑与模型中的其他平滑或项相互作用,因此可能更容易将y轴视为对每个平滑的响应的影响?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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