Skip to main content
added 1 character in body
Source Link
Gavin Simpson
  • 50.4k
  • 8
  • 136
  • 185

I see where your comment about negative EDF came from! That's just floating point precision for you. You can treat that s(period) as being irrelevant given the other terms in the model and ignore the p value. You might also consider sending this as a bug report to Simon Wood, mgcv's maintainer as a negative EDF doesn't make sense (and here it isn't really negative it's just so small that floating point issues have cropped up and made the number that is numerically 0 [or very close to it] less than 0.)

Anyway, the bigger problem and the cause of your issues is that you are including the period means twice:

  1. through the period parametric term, and also
  2. through the s(period, bs = "re") random effect term.

Those two terms are nonot uniquely identifiable from the data. What you are seeing a numerical differences putting more (or less) weight on one of those two things that likely depend on the data used in the model; with discrete = TRUE the predictor data is slightly different - it has been discretized slightly and that could easily see the weight shift from the parametric version to the random effect version of the group mean effects you included in the model.

Basically, use one or the other, not both. You don't need to include the group means via a parametric effect if you fit a factor by; you just need to account for the group means in the model and you can do that either by a parametric term, a random effect term, or some other term that also includes the group means (and "fs" or a "sz" smooth will include the group means for example)

I see where your comment about negative EDF came from! That's just floating point precision for you. You can treat that s(period) as being irrelevant given the other terms in the model and ignore the p value. You might also consider sending this as a bug report to Simon Wood, mgcv's maintainer as a negative EDF doesn't make sense (and here it isn't really negative it's just so small that floating point issues have cropped up and made the number that is numerically 0 [or very close to it] less than 0.)

Anyway, the bigger problem and the cause of your issues is that you are including the period means twice:

  1. through the period parametric term, and also
  2. through the s(period, bs = "re") random effect term.

Those two terms are no uniquely identifiable from the data. What you are seeing a numerical differences putting more (or less) weight on one of those two things that likely depend on the data used in the model; with discrete = TRUE the predictor data is slightly different - it has been discretized slightly and that could easily see the weight shift from the parametric version to the random effect version of the group mean effects you included in the model.

Basically, use one or the other, not both. You don't need to include the group means via a parametric effect if you fit a factor by; you just need to account for the group means in the model and you can do that either by a parametric term, a random effect term, or some other term that also includes the group means (and "fs" or a "sz" smooth will include the group means for example)

I see where your comment about negative EDF came from! That's just floating point precision for you. You can treat that s(period) as being irrelevant given the other terms in the model and ignore the p value. You might also consider sending this as a bug report to Simon Wood, mgcv's maintainer as a negative EDF doesn't make sense (and here it isn't really negative it's just so small that floating point issues have cropped up and made the number that is numerically 0 [or very close to it] less than 0.)

Anyway, the bigger problem and the cause of your issues is that you are including the period means twice:

  1. through the period parametric term, and also
  2. through the s(period, bs = "re") random effect term.

Those two terms are not uniquely identifiable from the data. What you are seeing a numerical differences putting more (or less) weight on one of those two things that likely depend on the data used in the model; with discrete = TRUE the predictor data is slightly different - it has been discretized slightly and that could easily see the weight shift from the parametric version to the random effect version of the group mean effects you included in the model.

Basically, use one or the other, not both. You don't need to include the group means via a parametric effect if you fit a factor by; you just need to account for the group means in the model and you can do that either by a parametric term, a random effect term, or some other term that also includes the group means (and "fs" or a "sz" smooth will include the group means for example)

Source Link
Gavin Simpson
  • 50.4k
  • 8
  • 136
  • 185

I see where your comment about negative EDF came from! That's just floating point precision for you. You can treat that s(period) as being irrelevant given the other terms in the model and ignore the p value. You might also consider sending this as a bug report to Simon Wood, mgcv's maintainer as a negative EDF doesn't make sense (and here it isn't really negative it's just so small that floating point issues have cropped up and made the number that is numerically 0 [or very close to it] less than 0.)

Anyway, the bigger problem and the cause of your issues is that you are including the period means twice:

  1. through the period parametric term, and also
  2. through the s(period, bs = "re") random effect term.

Those two terms are no uniquely identifiable from the data. What you are seeing a numerical differences putting more (or less) weight on one of those two things that likely depend on the data used in the model; with discrete = TRUE the predictor data is slightly different - it has been discretized slightly and that could easily see the weight shift from the parametric version to the random effect version of the group mean effects you included in the model.

Basically, use one or the other, not both. You don't need to include the group means via a parametric effect if you fit a factor by; you just need to account for the group means in the model and you can do that either by a parametric term, a random effect term, or some other term that also includes the group means (and "fs" or a "sz" smooth will include the group means for example)