yat/regression/NegativeBinomial.h

Code
Comments
Other
Rev Date Author Line
3614 06 Feb 17 peter 1 #ifndef theplu_yat_regression_negative_binomial
3614 06 Feb 17 peter 2 #define theplu_yat_regression_negative_binomial
3614 06 Feb 17 peter 3
3614 06 Feb 17 peter 4 // $Id$
3614 06 Feb 17 peter 5
3614 06 Feb 17 peter 6 /*
4207 26 Aug 22 peter 7   Copyright (C) 2017, 2020, 2022 Peter Johansson
3614 06 Feb 17 peter 8
3614 06 Feb 17 peter 9   This file is part of the yat library, http://dev.thep.lu.se/yat
3614 06 Feb 17 peter 10
3614 06 Feb 17 peter 11   The yat library is free software; you can redistribute it and/or
3614 06 Feb 17 peter 12   modify it under the terms of the GNU General Public License as
3614 06 Feb 17 peter 13   published by the Free Software Foundation; either version 3 of the
3614 06 Feb 17 peter 14   License, or (at your option) any later version.
3614 06 Feb 17 peter 15
3614 06 Feb 17 peter 16   The yat library is distributed in the hope that it will be useful,
3614 06 Feb 17 peter 17   but WITHOUT ANY WARRANTY; without even the implied warranty of
3614 06 Feb 17 peter 18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3614 06 Feb 17 peter 19   General Public License for more details.
3614 06 Feb 17 peter 20
3614 06 Feb 17 peter 21   You should have received a copy of the GNU General Public License
3614 06 Feb 17 peter 22   along with yat. If not, see <http://www.gnu.org/licenses/>.
3614 06 Feb 17 peter 23 */
3614 06 Feb 17 peter 24
3980 24 Aug 20 peter 25 #include "Multivariate.h"
3980 24 Aug 20 peter 26
3614 06 Feb 17 peter 27 #include <yat/utility/Matrix.h>
3614 06 Feb 17 peter 28 #include <yat/utility/Vector.h>
3614 06 Feb 17 peter 29
3614 06 Feb 17 peter 30 namespace theplu {
3614 06 Feb 17 peter 31 namespace yat {
3614 06 Feb 17 peter 32 namespace regression {
3614 06 Feb 17 peter 33
3614 06 Feb 17 peter 34   /**
3664 21 Jul 17 peter 35      Negative Binomial regression models count data from a negative
3664 21 Jul 17 peter 36      binomial distribution, \f$ y \in NB(r;p) \f$, for which the mean
3664 21 Jul 17 peter 37      is \f$ \mu = \frac{pr}{1-p} \f$ is modeled as \f$ log(\mu) = \beta_0
3664 21 Jul 17 peter 38      + \beta_1 x_1 + ... + \beta_p x_p \f$ and the variance \f$ V =
3664 21 Jul 17 peter 39      \frac{pr}{(1-p)^2} = \alpha m(x) \f$ where \f$ \alpha \f$ is the
3664 21 Jul 17 peter 40      dispersion parameter \f$( \ge 1 )\f$ describing how wider the
3664 21 Jul 17 peter 41      distribution is compared to Poisson; for \f$ \alpha = 1 \f$ the
3664 21 Jul 17 peter 42      models equals Poisson regression.
3614 06 Feb 17 peter 43
3614 06 Feb 17 peter 44      \since new in yat 0.15
3614 06 Feb 17 peter 45    */
3980 24 Aug 20 peter 46   class NegativeBinomial : public Multivariate
3614 06 Feb 17 peter 47   {
3614 06 Feb 17 peter 48   public:
3614 06 Feb 17 peter 49     /**
3663 20 Jul 17 peter 50        \brief alpha parameter
3663 20 Jul 17 peter 51
4149 01 Mar 22 peter 52        The alpha parameter describes the dispersion of the
3663 20 Jul 17 peter 53        data. Greater alpha implies greater dispersion and unity alpha
3664 21 Jul 17 peter 54        means the model is same as Poisson regression.
3663 20 Jul 17 peter 55      */
3663 20 Jul 17 peter 56     double alpha(void) const;
3663 20 Jul 17 peter 57
3663 20 Jul 17 peter 58     /**
3663 20 Jul 17 peter 59        \brief Covariance of parameters
3664 21 Jul 17 peter 60
3664 21 Jul 17 peter 61        Covariance matrix is inferred as \f$ \alpha \left( X' W X
3664 21 Jul 17 peter 62        \right)^{-1} \f$ where \f$ W \f$ is a diagonal matrix with
3664 21 Jul 17 peter 63        element \f$ W_{ii} = \mu_i \f$
3663 20 Jul 17 peter 64     */
3663 20 Jul 17 peter 65     const utility::Matrix& covariance(void) const;
3663 20 Jul 17 peter 66
3663 20 Jul 17 peter 67     /**
3614 06 Feb 17 peter 68        \brief fit model parameters
3664 21 Jul 17 peter 69
3664 21 Jul 17 peter 70        The parameters are tuned to minimise deviation between data and model
3664 21 Jul 17 peter 71        \f$ 2 \sum_i y_i \ln (y_i / \mu_i) \f$
3982 26 Aug 20 peter 72
3982 26 Aug 20 peter 73        Each row in \c x represents a sample.
4130 20 Jan 22 peter 74
4130 20 Jan 22 peter 75        \since New in yat 0.20
3614 06 Feb 17 peter 76      */
4130 20 Jan 22 peter 77     void fit2(const utility::MatrixBase& x, const utility::VectorBase& y);
3614 06 Feb 17 peter 78
3614 06 Feb 17 peter 79     /**
4130 20 Jan 22 peter 80        Just kept for back compatibility with yat 0.19. Exactly the
4130 20 Jan 22 peter 81        same behaviour as for fit2.
4130 20 Jan 22 peter 82      */
4130 20 Jan 22 peter 83     void fit(const utility::Matrix& X, const utility::VectorBase& y);
4130 20 Jan 22 peter 84
4130 20 Jan 22 peter 85     /**
3614 06 Feb 17 peter 86        \return model parameters
3614 06 Feb 17 peter 87      */
3614 06 Feb 17 peter 88     const utility::Vector& fit_parameters(void) const;
3614 06 Feb 17 peter 89
3614 06 Feb 17 peter 90     /**
3663 20 Jul 17 peter 91        Predicted value given \a x. The prediction is calculated as
3614 06 Feb 17 peter 92        \f$ \exp{\beta_0 + \beta_1 x_1 +...+\beta_p x_p} \f$
3614 06 Feb 17 peter 93      */
3614 06 Feb 17 peter 94     double predict(const utility::VectorBase& x) const;
3659 13 Jul 17 peter 95
3659 13 Jul 17 peter 96   private:
3659 13 Jul 17 peter 97     double alpha_;
3659 13 Jul 17 peter 98     utility::Vector beta_;
3663 20 Jul 17 peter 99     utility::Matrix covariance_;
3614 06 Feb 17 peter 100   };
3614 06 Feb 17 peter 101
3614 06 Feb 17 peter 102 }}}
3614 06 Feb 17 peter 103
3614 06 Feb 17 peter 104 #endif