Changing the Y axis of default plot.gam graphs

后端 未结 1 1013
不思量自难忘°
不思量自难忘° 2021-01-07 05:32

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(Me         


        
1条回答
  •  隐瞒了意图╮
    2021-01-07 06:10

    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?

    0 讨论(0)
提交回复
热议问题