简体   繁体   English

如何在R中的mgcv中声明gam()中的指数分布

[英]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.我有一个来自实验的小数据集,我想拟合一个 gam 模型,该模型规定 Y 的分布以 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.我尝试了不同的方式将分布类型传递给 gam 函数,但我总是遇到异常。 Eg,例如,

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

I don't think gam() supports this type of family.我不认为 gam() 支持这种类型的家庭。

You may want to consider gamlss() from the gamlss package instead in conjunction with the EXP distribution from the gamlss.dist package:您可能需要考虑 gamlss 包中的 gamlss() 而不是结合 gamlss.dist 包中的 EXP 分发:

https://www.rdocumentation.org/packages/gamlss/versions/5.0-6/topics/gamlss 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 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.请注意,EXP 分布有一个均值参数,而不是比率参数。

See http://www.gamlss.com for details on the gamlss package.有关 gamlss 包的详细信息,请参阅http://www.gamlss.com

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.此外,对于如此小的数据集,我怀疑您是否可以在您的模型中容纳交互项 - 即使拟合两个主要效应也可能有点牵强。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM