When I use GLMs I can use the option family="Gamma"
for analysing data consisting of positive real numbers. Also package gbm
provides a large number of distributions to choose from, but there's none that matches the gamma distribution. Which distribution should I choose?
-
1$\begingroup$ take the log of your data and use least squares (=logNormal) ? $\endgroup$– Ben BolkerMay 20, 2014 at 12:28
1 Answer
The distribution gamma
are available in both gbm
(only for the github version https://github.com/gbm-developers/gbm , not in the CRAN version) and mboost
package.
For the package gbm
, simply specify distribution = 'gamma'
in the parameters of gbm
function.
For the package mboost
, use gamma distribution specifying family = GammaReg()
in the options of the function mboost
as shown in the toy example below :
library(mboost)
n.obs <- 1000
n.iter <- 100
x1 <- rgamma(n.obs, shape = 1, scale = 1)
x2 <- rgamma(n.obs, shape = 2, scale = 1)
y <- x1 + x2
model <- mboost(formula = y ~ x1 + x2, data = data.frame(y, x1, x2),
baselearner = "btree", family = GammaReg(),
control = boost_control(mstop = n.iter))
-
2$\begingroup$ It's not too hard to add distributions to
gbm
. We addedgamma
at work, and committed it: github.com/harrysouthworth/gbm/blob/master/src/gamma.cpp $\endgroup$ Aug 27, 2016 at 20:03 -
$\begingroup$ Thank you for this precision. I have just edited my answer accordingly. $\endgroup$ Sep 19, 2016 at 13:36
-
$\begingroup$ gamma is also available in the xgboost package. $\endgroup$– filups21Mar 12, 2021 at 19:47