Search code examples
non-linear-regressiongammgcvrandom-effects

GAMM with scaled t-distribution: Why do my residuals and fitted values not add up to the observed values?


Edit: I have by now figured out that this issue - if it is one - has to do with the fact that I have chosen a scaled t-distribution for my model. Running the model with the Gaussian distribuation doesn't result in the same problem.

Nonetheless, I am wondering why this happens. Is it normal for models using a different distribution that fitted + residuals != dependent variable?

Using mgcv's gam() I've fitted a nonlinear model including a random factor smooth.

Below is the original question:

######################################################################

I've extracted the fitted values using fitted(model) and the residuals using resid(model).

When I added them to my data frame, I noticed that the residuals and the fitted values do not add up to the observed values. At first I thought that maybe the functions fitted() and resid() don't preserve the original order of the values. That is wrong, however. I tried it with other models (including other gam models).

Now, the model I am working on has had some issues. Most notably, the significance levels of different smooths (including the random factor smooth) vary strongly depending on the k-values one sets.

What could be the cause of this issue? Is this some sort of stability problem? How can one deal with such issues? I'd be thankful for any pointers in the right direction.


Solution

  • The residuals you are extracting are deviance residuals and only (IIRC) for the Gaussian do these correspond to the response residuals you were expecting.

    You can get response residuals using residuals(model, type = 'response') and the redo your computation using those. See ?residuals.gam for more.