Distributions¶
Distributions
-
class
pygam.distributions.
BinomialDist
(levels=1)¶ Bases:
pygam.distributions.Distribution
Binomial Distribution
-
V
(mu)¶ glm Variance function
computes the variance of the distribution
Parameters: mu (array-like of length n) – expected values Returns: variance Return type: np.array of length n
-
deviance
(y, mu, scaled=True)¶ model deviance
for a bernoulli logistic model, this is equal to the twice the negative loglikelihod.
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- scaled (boolean, default: True) – whether to divide the deviance by the distribution scaled
Returns: deviances
Return type: np.array of length n
-
log_pdf
(y, mu, weights=None)¶ computes the log of the pdf or pmf of the values under the current distribution
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- weights (array-like shape (n,) or None, default: None) – sample weights if None, defaults to array of ones
Returns: pdf/pmf
Return type: np.array of length n
-
sample
(mu)¶ Return random samples from this Normal distribution.
Parameters: mu (array-like of shape n_samples or shape (n_simulations, n_samples)) – expected values Returns: random_samples Return type: np.array of same shape as mu
-
-
class
pygam.distributions.
Distribution
(name=None, scale=None)¶ Bases:
pygam.core.Core
-
phi
(y, mu, edof, weights)¶ GLM scale parameter. for Binomial and Poisson families this is unity for Normal family this is variance
Parameters: Returns: scale
Return type: estimated model scale
-
sample
(mu)¶ Return random samples from this distribution.
Parameters: mu (array-like of shape n_samples or shape (n_simulations, n_samples)) – expected values Returns: random_samples Return type: np.array of same shape as mu
-
-
class
pygam.distributions.
GammaDist
(scale=None)¶ Bases:
pygam.distributions.Distribution
Gamma Distribution
-
V
(mu)¶ glm Variance function
computes the variance of the distribution
Parameters: mu (array-like of length n) – expected values Returns: variance Return type: np.array of length n
-
deviance
(y, mu, scaled=True)¶ model deviance
for a bernoulli logistic model, this is equal to the twice the negative loglikelihod.
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- scaled (boolean, default: True) – whether to divide the deviance by the distribution scaled
Returns: deviances
Return type: np.array of length n
-
log_pdf
(y, mu, weights=None)¶ computes the log of the pdf or pmf of the values under the current distribution
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- weights (array-like shape (n,) or None, default: None) – containing sample weights if None, defaults to array of ones
Returns: pdf/pmf
Return type: np.array of length n
-
sample
(mu)¶ Return random samples from this Gamma distribution.
Parameters: mu (array-like of shape n_samples or shape (n_simulations, n_samples)) – expected values Returns: random_samples Return type: np.array of same shape as mu
-
-
class
pygam.distributions.
InvGaussDist
(scale=None)¶ Bases:
pygam.distributions.Distribution
Inverse Gaussian (Wald) Distribution
-
V
(mu)¶ glm Variance function
computes the variance of the distribution
Parameters: mu (array-like of length n) – expected values Returns: variance Return type: np.array of length n
-
deviance
(y, mu, scaled=True)¶ model deviance
for a bernoulli logistic model, this is equal to the twice the negative loglikelihod.
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- scaled (boolean, default: True) – whether to divide the deviance by the distribution scaled
Returns: deviances
Return type: np.array of length n
-
log_pdf
(y, mu, weights=None)¶ computes the log of the pdf or pmf of the values under the current distribution
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- weights (array-like shape (n,) or None, default: None) – containing sample weights if None, defaults to array of ones
Returns: pdf/pmf
Return type: np.array of length n
-
sample
(mu)¶ Return random samples from this Inverse Gaussian (Wald) distribution.
Parameters: mu (array-like of shape n_samples or shape (n_simulations, n_samples)) – expected values Returns: random_samples Return type: np.array of same shape as mu
-
-
class
pygam.distributions.
NormalDist
(scale=None)¶ Bases:
pygam.distributions.Distribution
Normal Distribution
-
V
(mu)¶ glm Variance function.
- if
- Y ~ ExpFam(theta, scale=phi)
- such that
- E[Y] = mu = b’(theta)
- and
- Var[Y] = b’‘(theta) * phi / w
- then we seek V(mu) such that we can represent Var[y] as a fn of mu:
- Var[Y] = V(mu) * phi
- ie
- V(mu) = b’‘(theta) / w
Parameters: mu (array-like of length n) – expected values Returns: V(mu) Return type: np.array of length n
-
deviance
(y, mu, scaled=True)¶ model deviance
for a gaussian linear model, this is equal to the SSE
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- scaled (boolean, default: True) – whether to divide the deviance by the distribution scaled
Returns: deviances
Return type: np.array of length n
-
log_pdf
(y, mu, weights=None)¶ computes the log of the pdf or pmf of the values under the current distribution
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- weights (array-like shape (n,) or None, default: None) – sample weights if None, defaults to array of ones
Returns: pdf/pmf
Return type: np.array of length n
-
sample
(mu)¶ Return random samples from this Normal distribution.
Samples are drawn independently from univariate normal distributions with means given by the values in mu and with standard deviations equal to the scale attribute if it exists otherwise 1.0.
Parameters: mu (array-like of shape n_samples or shape (n_simulations, n_samples)) – expected values Returns: random_samples Return type: np.array of same shape as mu
-
-
class
pygam.distributions.
PoissonDist
¶ Bases:
pygam.distributions.Distribution
Poisson Distribution
-
V
(mu)¶ glm Variance function
computes the variance of the distribution
Parameters: mu (array-like of length n) – expected values Returns: variance Return type: np.array of length n
-
deviance
(y, mu, scaled=True)¶ model deviance
for a bernoulli logistic model, this is equal to the twice the negative loglikelihod.
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- scaled (boolean, default: True) – whether to divide the deviance by the distribution scaled
Returns: deviances
Return type: np.array of length n
-
log_pdf
(y, mu, weights=None)¶ computes the log of the pdf or pmf of the values under the current distribution
Parameters: - y (array-like of length n) – target values
- mu (array-like of length n) – expected values
- weights (array-like shape (n,) or None, default: None) – containing sample weights if None, defaults to array of ones
Returns: pdf/pmf
Return type: np.array of length n
-
sample
(mu)¶ Return random samples from this Poisson distribution.
Parameters: mu (array-like of shape n_samples or shape (n_simulations, n_samples)) – expected values Returns: random_samples Return type: np.array of same shape as mu
-
-
pygam.distributions.
divide_weights
(V)¶
-
pygam.distributions.
multiply_weights
(deviance)¶