You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using a Gamma GLM with LogLink. I am interested in estimating the coefficients as well as the scale parameter so that, for a given input vector x, I can reconstruct the whole Gamma distribution and not just the mean.
The example below illustrates my current attempt. I get reasonable estimates, but the shape and scale parameters seem to be swapped (see the last line). I've been banging my head on this for a while - any ideas where I'm going wrong?
Cheers
using GLM
# True parameter values: shape=5, scale=2. Aim is to estimate these from data
d =Gamma(5.0, 2.0)
# Data
y =rand(d, 1000)
X =fill(1.0, 1000, 1)
# Model
dist =Gamma()
lnk =LogLink()
model =glm(y, X, dist, lnk)
# Estimate mean and variance at x=1
b =coef(model)
lp = b[1] # linear_predictor = intercept
mu = GLM.linkinv(lnk, lp)
v = GLM.dispersion(model) * GLM.glmvar(dist, mu)
# From the mean and variance, extract shape and scale for the Gamma distribution at x=1dist_params(d::Gamma, mu, v) = (shape = mu*mu/v, scale = v/mu)
dist_params(dist, mu, v) # Approx (shape=2, scale=5) instead of (shape=5, scale=2)
The text was updated successfully, but these errors were encountered:
Hi there,
I am using a Gamma GLM with LogLink. I am interested in estimating the coefficients as well as the scale parameter so that, for a given input vector
x
, I can reconstruct the whole Gamma distribution and not just the mean.The example below illustrates my current attempt. I get reasonable estimates, but the shape and scale parameters seem to be swapped (see the last line). I've been banging my head on this for a while - any ideas where I'm going wrong?
Cheers
The text was updated successfully, but these errors were encountered: