Description Usage Arguments Details Value Author(s) References Examples
Fits a log-link Tweedie GLM model using maximum likelihood for all parameters, if wanted. The dispersion and power parameters (phi and p) can be set if required.
1 2 3 4 |
mean.form |
an object of class "formula" (or one that can be coerced to that class). This is a symbolic representation of the model for the mean of the observations. Offset terms can be included in this formula. |
data |
a data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. |
wts |
relative contribution to the log-likelihood contributions. Must be the same length as the number of observations. |
phi |
a positive scalar whose presence indicates that a profile likelihood should be used for estimating all parameters except the dispersion phi (set to the supllied value). |
p |
a value in the interval [1,2] whose presence indicates that a profile likelihood should be used for estimating all parameters except the power parameter p (set to the supplied value). |
inits |
(tglm) numeric vector containing the starting values for the coefficient estimates. The ordering of the vector is:coefficients for mean.form, phi and p. Defaults to zero for each the mean coefficients, 1 for phi, and 1.6 for p. (tglm.fit) numeric vector that must be specified (no default). It has length equal to the number of covariates plus 2. |
vcov |
boolean indicating if the variance-covariance matrix of the coefficient estimates should be calculated or not. Default is TRUE indicating that it will be calculated. |
residuals |
boolean indicating if the quantile residuals should be calculated. Default is TRUE indicating residuals are to be calculated. |
trace |
non-negative integer value indicating how often during estimation the updated coefficients should be calculated. Default is 1, indicating printing at every iteration. A value of 0 indicates that no printing will occur. |
iter.max |
the maximum number of iterations allowed. |
x, y, offset |
x is a design matrix, y is the vector of outcomes and offset are the offset values. None of these values are checked. The design matrix has dimension pXn where p is the number of covariates and n is the number of observations. |
The means of each of the unobserved random variables are modelled using a log-link and the formula given in mean.form. This function implements the model described in Smyth (1996) and Dunn and Smyth (2005) but does so by maximising the complete likelihood (ala Dunn and Smyth, 2005). The model specification is restricted to the log link.
The residuals are quantile residuals, described in general by Dunn and Smyth (1996).
tglm.fit is the workhorse function: it is not normally called directly but can be more efficient where the response vector and design matrix have already been calculated. Completely analgous to the function glm.fit.
tglm returns an object of class "tglm", a list with the following elements
coef |
the estiamted coefficients from the fitting process. |
logl |
the maximum log likelihood (found at the estimates). |
score |
the score of the log-likelihood (at the estimates). |
vcov |
the variance-covariance matrix of the estimates. If vcov is FALSE then this will be NULL. |
conv |
the convergence message from the call to nlminb. |
message |
the convergence message from nlminb. |
niter |
the number of iterations taken to obtain convergence. |
evals |
the number of times the log-likelihood and its derivative were evaluated. |
call |
the call used to invoke the function. |
fitted |
matrix with one column containing the modelled mean. |
residuals |
the vector of quantile residuals. |
Scott D. Foster
Smyth, G. K. (1996) Regression analysis of quantity data with exact zeros. Proceedings of the Second Australia–Japan Workshop on Stochastic Models in Engineering, Technology and Management. Technology Management Centre, University of Queensland, pp. 572-580.
Dunn P. K and Smyth G. K (1996) Randomized Quantile Residuals. Journal of Computational and Graphical Statistics 5: 236-244.
Dunn P. K. and Smyth G. K. (2005) Series evaluation of Tweedie exponential dispersion model densities. Statistics and Computing 15: 267-280.
Foster, S.D. and Bravington, M.V. (2013) A Poisson-Gamma Model for Analysis of Ecological Non-Negative Continuous Data. Journal of Environmental and Ecological Statistics 20: 533-552
1 2 3 4 5 6 7 8 9 | print( "Data generated using Poisson-sum-of-gammas model and fitted using a Tweedie GLM.")
print( "A great fit is not expected -- especially for the first covariate")
my.coef <- c(0.6, 1.2, 0, -0.3, 0, -0.5, 0.85)
sim.dat <- simReg( n=250, lambda.tau=my.coef[1:3], mu.Z.tau=my.coef[4:6], alpha=my.coef[7])
fm <- tglm( mean.form=y~1+x1+x2, data=sim.dat)
tmp <- matrix( c( my.coef[1:3] + my.coef[4:6], NA, (2+0.85)/(1+0.85), fm$coef), ncol=2)
colnames( tmp) <- c("actual","estimated")
rownames( tmp) <- c( names( fm$coef)[1:3], "phi", "p")
print( tmp)
|
[1] "Data generated using Poisson-sum-of-gammas model and fitted using a Tweedie GLM."
[1] "A great fit is not expected -- especially for the first covariate"
[1] "Obtaining initial mean values from log-linear Poisson model -- this might be stupid"
[1] "Obtaining initial dispersion from the smaller of the Pearson or Deviance estimator (or 25)"
[1] "Estimating parameters"
iter: -logl (Intercept) x1 x2 phi p
0: 465.85398: 0.268496 1.21257 -0.473974 1.71116 1.60000
1: 453.52029: 0.269689 1.21276 -0.473281 1.71371 1.52663
2: 448.31241: 0.271814 1.21261 -0.472100 1.71133 1.45328
3: 446.25047: 0.296792 1.20258 -0.459670 1.57334 1.41270
4: 446.10254: 0.295991 1.20020 -0.461075 1.55748 1.43082
5: 445.90294: 0.290521 1.19717 -0.466444 1.54238 1.41373
6: 445.68148: 0.283017 1.21524 -0.476755 1.50028 1.42328
7: 445.52995: 0.279745 1.20432 -0.463643 1.48654 1.40597
8: 445.48576: 0.288580 1.19035 -0.457458 1.46944 1.41963
9: 445.39062: 0.312161 1.19611 -0.461902 1.46357 1.40750
10: 445.32595: 0.289723 1.19251 -0.467500 1.44803 1.40638
11: 445.29804: 0.294074 1.19771 -0.466172 1.44259 1.41032
12: 445.28624: 0.294632 1.19803 -0.465485 1.44055 1.40617
13: 445.27755: 0.295271 1.19817 -0.464709 1.43649 1.40836
14: 445.26739: 0.296068 1.19614 -0.460149 1.42982 1.40400
15: 445.25794: 0.300647 1.19325 -0.465699 1.42489 1.40615
16: 445.25036: 0.296109 1.19914 -0.463307 1.42023 1.40363
17: 445.24820: 0.296053 1.19859 -0.463420 1.41915 1.40521
18: 445.24690: 0.296139 1.19797 -0.463566 1.41778 1.40391
19: 445.24598: 0.297968 1.19565 -0.464679 1.41567 1.40510
20: 445.24373: 0.296493 1.19745 -0.462942 1.41303 1.40440
21: 445.24336: 0.296686 1.19746 -0.463217 1.41261 1.40368
22: 445.24311: 0.296840 1.19740 -0.463437 1.41192 1.40420
23: 445.24260: 0.296292 1.19757 -0.464000 1.41039 1.40372
24: 445.24234: 0.297128 1.19743 -0.463462 1.40901 1.40315
25: 445.24220: 0.297290 1.19686 -0.463317 1.40862 1.40352
26: 445.24215: 0.297075 1.19732 -0.463608 1.40804 1.40351
27: 445.24211: 0.296961 1.19718 -0.463622 1.40730 1.40322
28: 445.24210: 0.297270 1.19707 -0.463626 1.40723 1.40323
29: 445.24209: 0.297249 1.19708 -0.463569 1.40712 1.40329
30: 445.24209: 0.297255 1.19707 -0.463590 1.40715 1.40328
31: 445.24209: 0.297256 1.19707 -0.463588 1.40715 1.40328
[1] "Calculating variance matrix of estimates"
[1] "Calculating means"
[1] "Calculating quantile residuals"
[1] "Done"
actual estimated
(Intercept) 0.300000 0.2972556
x1 1.200000 1.1970718
x2 -0.500000 -0.4635884
phi NA 1.4071500
p 1.540541 1.4032775
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.