Search code examples
rexponentialgammgcv

How to declare the exponential distribution in gam() in mgcv in R


I have a small dataset derived from an experiment and I want to fit a gam model prescribing the distribution of Y to be exponential with rate 0.5.

My data is:

x1              x2      y
-1.000000   -1.000000   40
1.000000    -1.000000   5
-1.000000   1.000000    14
1.000000    1.000000    10
-1.414214   0.000000    35
1.414214    0.000000    7
0.000000    -1.414214   18
0.000000    1.414214    9
0.000000    0.000000    7
0.000000    0.000000    4
0.000000    0.000000    0
0.000000    0.000000    2

I have tried different way to pass to the gam function the type of the distribution but I always run into an exception. E.g.,

model.gam = gam(y ~ x1 * x2, family = exponential(rate=0.5), data = df)
Error in gam(y ~ x1 * x2, family = exponential(rate = 0.5), data = df): family not recognized

model.gam = gam(y ~ x1 * x2, family = exponential(), data = df)
Error in check_dims(rate, target_dim = dim): argument "rate" is missing, with no default

model.gam = gam(y ~ x1 * x2, family = exponential(), data = df, rate = 0.5)
Error in check_dims(rate, target_dim = dim): argument "rate" is missing, with no default

Solution

  • I don't think gam() supports this type of family.

    You may want to consider gamlss() from the gamlss package instead in conjunction with the EXP distribution from the gamlss.dist package:

    https://www.rdocumentation.org/packages/gamlss/versions/5.0-6/topics/gamlss

    https://www.rdocumentation.org/packages/gamlss.dist/versions/5.0-4/topics/EXP

    Note that the EXP distribution has a mean, rather than rate, parameter.

    See http://www.gamlss.com for details on the gamlss package.

    Also, for such a small data set, I doubt that you can accommodate an interaction term in your model - even fitting two main effects might be a bit of a stretch.