0

I want to fit a Tweedie GlM to a response variable but with a dispersion parameter (phi) set to 1 for all the records in my data. So all the parameters get estimated using Maximum Likelihood Estimator except for phi.

Thank you.

Sara
  • 3
  • 2

1 Answers1

0

You can do this by using the map argument in glmmTMB.

Example setup:

library(glmmTMB)
library(tweedie)
nobs <- 2000; mu <- 4; phi <- 2; p <- 1.7
set.seed(101)
y <- rtweedie(nobs, mu=mu, phi=phi, power=p)

Fit the unconstrained model:

twm <- glmmTMB(y ~ 1, family=tweedie(), data = NULL)
sigma(twm)  ## 2.0188, close to the true value of 2

(sigma() is the general accessor method for the dispersion parameter; its definition varies by family, see ?sigma.glmmTMB)

Constrained:

twm2 <- update(twm,
    map = list(betad=factor(NA)),
    start = list(betad = 0))
sigma(twm2) ## 1

Explanation:

  • map specifies sets of parameters to be held fixed to their starting values (if NA), or sets of parameters to be constrained to be equal to each other (i.e. sharing a factor level): see glmmTMB. In this case the dispersion parameter is a single value (it could have length > 1 if dispformula was specified), so we make it a factor of length 1 containing NA.
  • start specifies starting values (which are the values that map uses for fixed parameters). The dispersion parameter is fitted on a log scale, so we set the starting value to 0 (exp(0) = 1). In this case we don't really need to specify the value, since the default is 0 anyway, but it's clearer this way.
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453