Search code examples
rvariancegam

Variance estimation of the dependent variable in a Gaussian GAM (MGCV package)?


Consider the code below:

library(mgcv)

set.seed(123)
X = runif(300, 0, 1)
set.seed(123)
Y = X^3 + 2*X^2 + 1 + rnorm(300)

model = gam(Y~s(X), family= gaussian)

So model is a Gaussian generalized additive model (GAM). How can I find the estimated variance of the dependent variable (Y) in model?

UPDATE: In generalized additive models, when the family is Gaussian, the scale parameter is equal to the variance of Y. So I think I can use summary(model)$scale which gives the scale parameter estimation in fact, but can also be taken equal to the variance estimation of Y.


Solution

  • You can get this directly from the model object via the sig2 component of the fitted model:

    > summary(model)$scale
    [1] 0.9006256
    > model$sig2
    [1] 0.9006256
    

    The scale.estimated component also tells you if this was estimated by the model or supplied:

    > model$scale.estimated
    [1] TRUE