the pgam package - welcome to the university of...

43
The pgam Package April 18, 2007 Version 0.4.7 Date 2007-04-17 Author Washington Junger <[email protected]> and Antonio Ponce de Leon <[email protected]> Maintainer Washington Junger <[email protected]> Depends R (>= 1.9.0) Title Poisson-Gamma Additive Models. Description This work is an extension of the state space model for Poisson count data, Poisson-Gamma model, towards a semiparametric specification. Just like the generalized additive models (GAM), cubic splines are used for covariate smoothing. The semiparametric models are fitted by an iterative process that combines maximization of likelihood and backfitting algorithm. License GPL version 2 or later R topics documented: AIC.pgam .......................................... 2 aihrio ............................................ 3 backfitting .......................................... 5 bkfsmooth .......................................... 6 coef.pgam .......................................... 7 deviance.pgam ....................................... 9 elapsedtime ......................................... 10 envelope ........................................... 11 envelope.pgam ....................................... 11 f ............................................... 13 fitted.pgam ......................................... 13 fnz .............................................. 15 formparser .......................................... 15 framebuilder ......................................... 17 g ............................................... 18 1

Upload: nguyenbao

Post on 22-May-2018

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

The pgam PackageApril 18, 2007

Version 0.4.7

Date 2007-04-17

Author Washington Junger <[email protected]> and Antonio Ponce de Leon<[email protected]>

Maintainer Washington Junger <[email protected]>

Depends R (>= 1.9.0)

Title Poisson-Gamma Additive Models.

Description This work is an extension of the state space model for Poisson count data,Poisson-Gamma model, towards a semiparametric specification. Just like the generalizedadditive models (GAM), cubic splines are used for covariate smoothing. The semiparametricmodels are fitted by an iterative process that combines maximization of likelihood andbackfitting algorithm.

License GPL version 2 or later

R topics documented:AIC.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2aihrio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3backfitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5bkfsmooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6coef.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7deviance.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9elapsedtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10envelope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11envelope.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13fitted.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13fnz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15formparser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15framebuilder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

1

Page 2: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

2 AIC.pgam

intensity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20logLik.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21lpnorm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22periodogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24pgam.filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26pgam.fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27pgam.hes2se . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29pgam.likelihood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29pgam.par2psi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31pgam.psi2par . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31plot.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32predict.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33print.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35print.summary.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36residuals.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37summary.pgam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38tbl2tex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Index 42

AIC.pgam AIC extraction

Description

Method for approximate Akaike Information Criterion extraction.

Usage

## S3 method for class 'pgam':AIC(object, k = 2, ...)

Arguments

object object of class pgam holding the fitted model

k default is 2 for AIC. If k = log (n) then an approximation for BIC is obtained.Important to note that these are merely approximations.

... further arguments passed to method

Details

An approximate measure of parsimony of the Poisson-Gama Additive Models can be achieved bythe expression

AIC = (D (y; µ) + 2gle) / (n − τ)

where gle is the number of degrees of freedom of the fitted model and τ is the index of the firstnon-zero observation.

Page 3: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

aihrio 3

Value

The approximate AIC value of the fitted model.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

Hastie, T. J., Tibshirani, R. J.(1990) Generalized Additive Models. Chapman and Hall, London

See Also

pgam, deviance.pgam, logLik.pgam

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

AIC(m)

aihrio Sample dataset

Description

This is a dataset for Poisson-Gamma Additive Models functions testing.

Usage

data(aihrio)

Page 4: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

4 aihrio

Format

A data frame with 365 observations on the following 33 variables.

DATE a factor with levels

TIME a numeric vector

ITRESP65 a numeric vector

ITCIRC65 a numeric vector

ITDPOC65 a numeric vector

ITPNM65 a numeric vector

ITAVC65 a numeric vector

ITIAM65 a numeric vector

ITDIC65 a numeric vector

ITTCA65 a numeric vector

ITRESP5 a numeric vector

ITPNEU5 a numeric vector

ITDPC5 a numeric vector

WEEK a numeric vector

MON a numeric vector

TUE a numeric vector

WED a numeric vector

THU a numeric vector

FRI a numeric vector

SAT a numeric vector

SUN a numeric vector

HOLIDAYS a numeric vector

MONTH a numeric vector

warm.season a numeric vector

tmpmed a numeric vector

tmpmin a numeric vector

tmpmax a numeric vector

wet a numeric vector

rain a numeric vector

rainy a numeric vector

PM a numeric vector

SO2 a numeric vector

CO a numeric vector

Page 5: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

backfitting 5

Details

This is a reduced dataset of those used to estimate possible effects of air pollution on hospitaladmissions outcomes in Universidade do Estado do Rio de Janeiro, Rio de Janeiro, Brasil.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

Source

Secretaria de Meio Ambiente da Cidade do Rio de Janeiro, MinistÃl’rio de AeronÃautica and Data-sus.

backfitting Backfitting algorithm

Description

Fit the nonparametric part of the model via backfitting algorithm.

Usage

backfitting(y, x, df, smoother = "spline", w = rep(1, length(y)), eps = 0.001, maxit = 100, info = TRUE)

Arguments

y dependent variable for fitting. In semiparametric models, this is the partial resid-uals of parametric fit

x matrix of covariates

df equivalent degrees of freedom. If NULL the smoothing parameter is selected bycross-validation

smoother string with the name of the smoother to be used

w vector with the diagonal elements of the weight matrix. Default is a vector of 1with the same length of y

eps convergence control criterion

maxit convergence control iterations

info if FALSE only fitted values are returned. It it is faster during iterations

Details

Backfitting algorithm estimates the approximating regression surface, working around the "curse ofdimentionality".

More details soon enough.

Page 6: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

6 bkfsmooth

Value

Fitted smooth curves and partial residuals.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: aroughness penalty approach. Chapman and Hall, London

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’trico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

Hastie, T. J., Tibshirani, R. J.(1990) Generalized Additive Models. Chapman and Hall, London

See Also

pgam, predict.pgam, bkfsmooth

bkfsmooth Smoothing of nonparametric terms

Description

Interface for smoothing functions

Usage

bkfsmooth(y, x, df, smoother = "spline", w = rep(1, length(y)))

Arguments

y dependent variable for fitting. In semiparametric models, this is the partial resid-uals of parametric fit

x independent variable. Univariate fit only

df equivalent degrees of freedom. If NULL the smoothing parameter is selected bycross-validation

smoother string with the name of the smoother to be used

w vector with the diagonal elements of the weight matrix. Default is a vector of 1with the same length of y

Page 7: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

coef.pgam 7

Details

Although several smoothers can be used in semiparametric regression models, only natural cubicsplines is intended to be used in Poisson-Gamma Additive Models due to its interesting mathemat-ical properties.

Nowadays, this function interfaces the smooth.spline in stats library. It will become notdependent soon enough.

Value

fitted smoothed values

lev diagonal of the influence matrix

df degrees of freedom

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: aroughness penalty approach. Chapman and Hall, London

Hastie, T. J., Tibshirani, R. J.(1990) Generalized Additive Models. Chapman and Hall, London

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’trico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

See Also

pgam, predict.pgam

coef.pgam Coefficients extraction

Description

Method for parametric coefficients extraction.

Usage

## S3 method for class 'pgam':coef(object, ...)

Page 8: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

8 coef.pgam

Arguments

object object of class pgam holding the fitted model

... further arguments passed to method

Details

This function only retrieves the estimated coefficients from the model object returned by pgam.

Value

Vector of coefficients estimates of the model fitted.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

See Also

pgam, pgam.fit, predict.pgam

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

coef(m)

Page 9: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

deviance.pgam 9

deviance.pgam Deviance extraction

Description

Method for total deviance value extraction.

Usage

## S3 method for class 'pgam':deviance(object, ...)

Arguments

object object of class pgam holding the fitted model

... further arguments passed to method

Details

See predict.pgam for further information on deviance extration in Poisson-Gamma models.

Value

The sum of deviance components.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

See Also

pgam, pgam.fit, pgam.likelihood

Page 10: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

10 elapsedtime

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

deviance(m)

elapsedtime Utility function

Description

Gadget to compute the elapsed time of a process

Usage

elapsedtime(st, et)

Arguments

st start time

et end time

Details

Start and end times can be obtained with proc.time.

Value

String with the elapsed time in hh:mm:ss format.

Author(s)

Washington Leite Junger 〈[email protected]

See Also

pgam

Page 11: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

envelope 11

envelope Generic function for simulated envelope generation.

Description

A normal plot with simulated envelope of the residual is produced.

Usage

envelope(object, ...)

Arguments

object object holding the fitted model

... further arguments to passed to methods

Value

An object of class envelope holding the information needed to plot the envelope.

Author(s)

Washington Leite Junger 〈[email protected]

References

Atkinson, A. C. (1985) Plots, transformations and regression : an introduction to graphical methodsof diagnostic regression analysis. Oxford Science Publications, Oxford.

envelope.pgam Normal plot with simulated envelope of the residuals.

Description

A normal plot with simulated envelope of the residual is produced.

Usage

## S3 method for class 'pgam':envelope(object, type = "deviance", size = 0.95, rep = 19, optim.method = NULL,epsilon = 0.001, maxit = 100, plot = TRUE, title="Simulated Envelope of Residuals", verbose = FALSE, ...)

Page 12: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

12 envelope.pgam

Arguments

object object of class pgam holding the fitted model

type type of residuals to be extracted. Default is deviance. Options are describedin residuals.pgam

size value giving the size of the envelope. Default is .95 which is equivalent to a95% band

rep number of replications for envelope construction. Default is 19

optim.method optimization method to be passed to pgam and therefore to optim

epsilon convergence control to be passed to pgam

maxit convergence control to be passed to pgam

plot if TRUE a plot of the envelope is produced

title title for the plot

verbose if TRUE a sort of information is printed during the running time

... further arguments to plot function

Details

Method for the generic function envelope.

Sometimes the usual Q-Q plot shows an unsatisfactory pattern of the residuals of a model fitted andwe are led to think that the model is badly specificated. The normal plot with simulated envelopeindicates that under the distribution of the response variable the model is OK if only a few pointsfall off the envelope.

If object is of class pgam the envelope is estimated and optionally plotted, else if is of classenvelope then it is only plotted.

Value

An object of class envelope holding the information needed to plot the envelope.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Atkinson, A. C. (1985) Plots, transformations and regression : an introduction to graphical methodsof diagnostic regression analysis. Oxford Science Publications, Oxford.

See Also

pgam, predict.pgam, residuals.pgam

Page 13: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

f 13

f Utility function

Description

Generate the partition of design matrix regarded to the seasonal factor in its argument. Used in themodel formula.

Usage

f(factorvar)

Arguments

factorvar variable with the seasonal levels

Value

List containing data matrix of dummy variables, level names and seasonal periods.

Note

This function is intended to be called from within a model formula.

Author(s)

Washington Leite Junger 〈[email protected]

See Also

pgam, formparser

fitted.pgam Fitted values extraction

Description

Method for fitted values extraction.

Usage

## S3 method for class 'pgam':fitted(object, ...)

Page 14: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

14 fitted.pgam

Arguments

object object of class pgam holding the fitted model

... further arguments passed to method

Details

Actually, the fitted values are worked out by the function predict.pgam. Thus, this method issupposed to turn fitted values extraction easier. See predict.pgam for details on one-step aheadprediction.

Value

Vector of predicted values of the model fitted.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

See Also

pgam, pgam.fit, predict.pgam

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

f <- fitted(m)

Page 15: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

fnz 15

fnz Utility function

Description

Return the index of first non-zero observation of a variable.

Usage

fnz(y)

Arguments

y variable vector

Value

The index of first non-zero value.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]

See Also

pgam

formparser Read the model formula and split it into the parametric and nonpara-metric partitions

Description

Read the model formula and split it into two new ones concerning the parametric and nonparametricpartitions of the predictor.

Usage

formparser(formula, env=parent.frame())

Page 16: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

16 formparser

Arguments

formula object representing the model formula. R standard for GLM models

parent.frame an environment to be used as the parent of the environment created

Details

This function extracts all the information in the model formula. Most important, split the modelinto two parts regarding the parametric nature of the model. A model can be specified as following:

Y f (sfr) + V 1 + V 2 + V 3 + g (V 4, df4) + g (V 5, df5)

where sfr is a seasonal factor with period r and dfi is the degree of freedom of the smoother of thei-th covariate. Actually, two new formulae will be created:

sf1 + . . . + sfr + V 1 + V 2 + V 3

and

V 4 + V 5

These two formulae will be used to build the necessary datasets for model estimation. Dummyvariables reproducing the seasonal factors will be created also.

Models without explanatory variables must be specified as in the following formula

Y NULL

Value

List containing the information needed for model fitting.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]

See Also

pgam, f, g

Page 17: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

framebuilder 17

framebuilder Utility function

Description

Generate a data frame given a formula and a dataset.

Usage

framebuilder(formula, dataset)

Arguments

formula model formula

dataset model dataset

Details

Actually, this function is a wrapper for model.frame.

Value

A data frame restricted to the model.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

See Also

pgam, formparser

Page 18: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

18 g

g Utility function

Description

Collect information to smooth the term in its argument. Used in the model formula.

Usage

g(var, df = NULL)

Arguments

var variable to be smoothed

df equivalent degrees of freedom to be passed to the smoother. If NULL, smoothingparameter is selected by cross-validation

Details

This function only sets things up for model fitting. The smooth terms are actually fitted by bkfsmooth.

Value

List containing the same elements of its argument.

Note

This function is intended to be called from within a model formula.

Author(s)

Washington Leite Junger 〈[email protected]

References

Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: aroughness penalty approach. Chapman and Hall, London

Hastie, T. J., Tibshirani, R. J.(1990) Generalized Additive Models. Chapman and Hall, London

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

See Also

pgam, formparser

Page 19: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

intensity 19

intensity Utility function

Description

Apply spectral decomposition to its argument.

Usage

intensity(w, x)

Arguments

w frequency values

x time series

Details

The function apllies the spectral decomposition to the time series according to the following ex-pression ((∑

(x ∗ cos (w ∗ t)))2

+(∑

(x ∗ cos (w ∗ t)))2

)/n

Value

Decomposed series.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Box, G., Jenkins, G., Reinsel, G. (1994) Time Series Analysis : Forecasting and Control. 3rdedition, Prentice Hall, New Jersey.

Diggle, P. J. (1989) Time Series : A Biostatistical Introduction. Oxford University Press, Oxford.

See Also

pgam, periodogram

Page 20: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

20 link

link Utility function

Description

Apply the link function or its inverse to the argument.

Usage

link(x, link = "log", inv = FALSE)

Arguments

x vector containing the predictor

link string with the name of the link function

inv if TRUE its inverse is applied

Details

This function is intended to port other link functions than log () to Poisson-Gamma Additive Mod-els. For now, the only allowed value is "log".

Value

Evaluated link function at x values.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

McCullagh, P., Nelder, J. A. (1989). Generalized Linear Models. Chapman and Hall, 2nd edition,London

See Also

pgam, formparser

Page 21: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

logLik.pgam 21

logLik.pgam Loglik extraction

Description

Method for loglik value extraction.

Usage

## S3 method for class 'pgam':logLik(object, ...)

Arguments

object object of class pgam holding the fitted model

... further arguments passed to method

Details

See pgam.likelihood for more information on log-likelihood evaluation in Poisson-Gammamodels.

Value

The maximum value achieved by the likelihood optimization process.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

See Also

pgam, pgam.fit, pgam.likelihood

Page 22: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

22 lpnorm

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

logLik(m)

lpnorm Utility function

Description

Compute the Lp-norm of two sequencies.

Usage

lpnorm(seq1, seq2 = 0, p = 0)

Arguments

seq1 first sequency

seq2 second sequency

p L-space of the norm. 0 is infinity norm or max norm, 1 is the absolute valuenorm, 2 is L2 norm and so on

Value

The computed norm value.

Author(s)

Washington Leite Junger 〈[email protected]

See Also

pgam

Page 23: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

periodogram 23

periodogram Raw Periodogram

Description

A raw periodogram is returned and optionally plotted.

Usage

periodogram(y, rows = trunc(length(na.omit(y))/2-1), plot = TRUE, ...)

Arguments

y time series

rows number of rows to be returned. Default and largest is n/2 − 1, where n is thenumber of valid observations of the time series y

plot if TRUE a raw periodogram is plotted

... further arguments to plot function

Details

The raw periodogram is an estimator of the spectrum of a time series, it still is a good indicator ofunresolved seasonality patterns in residuals of the fitted model. See intensity for frequenciesextraction.

This function plots a fancy periodogram where the intensities of the angular frequencies are plottedresembling tiny lollipops.

Value

Periodogram ordered by intensity.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Box, G., Jenkins, G., Reinsel, G. (1994) Time Series Analysis : Forecasting and Control. 3rdedition, Prentice Hall, New Jersey.

Diggle, P. J. (1989) Time Series : A Biostatistical Introduction. Oxford University Press, Oxford.

See Also

pgam, intensity

Page 24: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

24 pgam

pgam Poisson-Gamma Additive Models

Description

Fit Poisson-Gamma Additive Models using the roughness penalty approach

Usage

pgam(formula, dataset, omega = 0.8, beta = 0.1, offset = 1, digits = getOption("digits"),na.action="na.exclude", maxit = 100, eps = 1e-06, lfn.scale=1, control = list(),optim.method = "L-BFGS-B", bkf.eps = 0.001, bkf.maxit = 100, se.estimation = "numerical",verbose = TRUE)

Arguments

formula a model formula. See formparser for detailsdataset a data set in the environment search path. Missing data is temporarily not han-

dledomega initial value for the discount factorbeta vector of initial values for covariates coefficients. If a sigle value is supplied it

is replicated to fill in the whole vectoroffset default is 1. Other value can be supplied heredigits number of decimal places for printing information outna.action action to be taken if missing values are found. Default is "na.exclude" and

residuals and predictions are padded to fit the length of the data. If "na.fail"then the process will stop if missing values are found. If "na.omit" the pro-cess will continue without padding though. If "na.pass" the process willstop due to errors

maxit convergence control iterationseps convergence control criterionlfn.scale scales the likelihood function and is passed to control in optim. Value must

be positive to ensure maximizationcontrol convergence control of optim. See its help for detailsoptim.method optimization method passed to optim. Different methods can lead to different

results, so the user must attempt to the trade off between speed and robustness.For example, BFGS is faster but sensitive to starting values and L-BFGS-B ismore robust but slower. See its help for details.

bkf.eps convergence control criterion for the backfitting algorithmbkf.maxit convergence control iterations for the backfitting algorithmse.estimation

if numerical numerical standard error of parameters are returned. If analyticalthen analytical extraction of the standard errors is performed. By setting it tonone standard error estimation is avoided

verbose if TRUE information during estimation process is printed out

Page 25: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

pgam 25

Details

The formula is parsed by formparser in order to extract all the information necessary for modelfit. Split the model into two parts regarding the parametric nature of the model. A model can bespecified as following:

Y f (sfr) + V 1 + V 2 + V 3 + g (V 4, df4) + g (V 5, df5)

where sfr is a seasonal factor with period r and dfi is the degree of freedom of the smoother of thei-th covariate. Actually, two new formulae will be created:

sf1 + . . . + sfr + V 1 + V 2 + V 3

andV 4 + V 5

These two formulae will be used to build the necessary datasets for model estimation. Dummyvariables reproducing the seasonal factors will be created also.

Models without explanatory variables must be specified as in the following formula

Y NULL

There are a lot of details to be written. It will be very soon.

Specific information can be obtained on functions help.

This algorithm fits fully parametric Poisson-Gamma model also.

Value

List containing an object of class pgam.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: aroughness penalty approach. Chapman and Hall, London

See Also

predict.pgam, formparser, residuals.pgam, backfitting

Page 26: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

26 pgam.filter

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

summary(m)

pgam.filter Estimation of the conditional distributions parameters of the level

Description

The priori and posteriori conditional distributions of the level is gamma and their parameters areestimated through this recursive filter. See Details for a thorough description.

Usage

pgam.filter(w, y, eta)

Arguments

w running estimate of discount factor ω of a Poisson-Gamma model

y n length vector of the time series observations

eta full linear or semiparametric predictor. Linear predictor is a trivial case of semi-parameric model

Details

Consider Yt−1 a vector of observed values of a Poisson process untill the instant t− 1. Conditionalon that, µt has gamma distribution with parameters given by

at|t−1 = ωat−1

bt|t−1 = ωbt−1 exp (−ηt)

Once yt is known, the posteriori distribution of µt|Yt is also gamma with parameters given by

at = ωat−1 + yt

bt = ωbt−1 + exp (ηt)

with t = τ, . . . , n, where τ is the index of the first non-zero observation of y.

Diffuse initialization of the filter is applied by setting a0 = 0 and b0 = 0. A proper distribution ofµt is obtained at t = τ , where τ is the fisrt non-zero observation of the time series.

Page 27: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

pgam.fit 27

Value

A list containing the time varying parmeters of the priori and posteriori conditional distribution isreturned.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Harvey, A. C. (1990) Forecasting, structural time series models and the Kalman Filter. Cambridge,New York

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

See Also

pgam, pgam.likelihood, pgam.fit, predict.pgam

pgam.fit One-step ahead prediction and variance

Description

Estimate one-step ahead expectation and variance of yt conditional on observed time series untilthe instant t − 1.

Usage

pgam.fit(w, y, eta, partial.resid)

Arguments

w estimate of discount factor ω of a Poisson-Gamma modely observed time series which is the response variable of the modeleta semiparametric predictorpartial.resid

type of partial residuals.

Page 28: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

28 pgam.fit

Details

Partial residuals for semiparametric estimation is extracted. Those are regarded to the parametricpartition fit of the model. Available types are raw, pearson and deviance. The type raw isprefered. Properties of other form of residuals not fully tested. Must be careful on choosing it. Seedetails in predict.pgam and residuals.pgam.

Value

yhat vector of one-step ahead prediction

resid vector partial residuals

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Harvey, A. C. (1990) Forecasting, structural time series models and the Kalman Filter. Cambridge,New York

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: aroughness penalty approach. Chapman and Hall, London

See Also

pgam, residuals.pgam, predict.pgam

Page 29: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

pgam.hes2se 29

pgam.hes2se Utility function

Description

Put hyperparameters hessian matrix in the form of omega and beta standard error.

Usage

pgam.hes2se(hes, fperiod, se.estimation="numerical")

Arguments

hes hessian matrix returned by optim

fperiod vector containing as many seasonal factors as there are in model formulase.estimation

indicate what method is used to extract the stardard errors

Value

List containing the hyperparameters omega and beta standard errors.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

See Also

pgam, formparser

pgam.likelihood Likelihood function to be maximized

Description

This is the log-likelihood function that is passed to optim for likelihood maximization.

Usage

pgam.likelihood(par, y, x, offset, fperiod, env = parent.frame())

Page 30: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

30 pgam.likelihood

Arguments

par vector of parameters to be optimized

y observed time series which is the response variable of the model

x observed explanatory variables for parametric fit

offset model offset. Just like in GLM

fperiod vector of seasonal factors to be passed to pgam.par2psi

env the caller environment for log-likelihood value to be stored

Details

Log-likelihood function of hyperparameters ω and β is given by

log L (ω, β) =n∑

t=τ+1

log Γ(at|t−1 + yt

)− log yt! − log Γ

(at|t−1

)+ at|t−1 log bt|t−1 −

(at|t−1 + yt

)log

(1 + bt|t−1

)where at|t−1 and bt|t−1 are estimated as it is shown in pgam.filter.

Value

List containing log-likelihood value, optimum linear predictor and the gamma parameters vectors.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Harvey, A. C. (1990) Forecasting, structural time series models and the Kalman Filter. Cambridge,New York

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’trico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

See Also

pgam, pgam.filter, pgam.fit

Page 31: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

pgam.par2psi 31

pgam.par2psi Utility function

Description

Put unconstrained optimized parameters back into omega and beta form.

Usage

pgam.par2psi(par, fperiod)

Arguments

par vector of unconstrained parameters

fperiod vector containing as many seasonal factors as there are in model formula

Value

List containing the hyperparameters omega and beta.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

See Also

pgam, formparser

pgam.psi2par Utility function

Description

Put hyperparameters into unconstrained form for optimization.

Usage

pgam.psi2par(w, beta, fperiod)

Page 32: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

32 plot.pgam

Arguments

w discount factor of the Poisson-Gamma model

beta explanatory variables coefficients

fperiod vector containing as many seasonal factors as there are in model formula

Value

Vector of unconstrained parameters.

Note

This function is not intended to be called directly.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

See Also

pgam, formparser

plot.pgam Plot of estimated curves

Description

Plot of the local level and, when semiparametric model is fitted, the estimated smooth terms.

Usage

## S3 method for class 'pgam':plot(x, rug = TRUE, se = TRUE, at.once = FALSE, scaled = FALSE, ...)

Arguments

x object of class pgam holding the fitted model

rug if TRUE a density rug is drawn on the bottom of the graphic

se if TRUE error band is drawn around the fitted values

at.once if TRUE each plot goes to a separate window, else the user is prompted to con-tinue

scaled if TRUE the same scale will be used for plots of smoothed functions

... further arguments passed to method

Details

Error band of smooth terms is approximated.

Page 33: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

predict.pgam 33

Value

No value returned.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

See Also

pgam, pgam.fit, pgam.likelihood

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

plot(m,at.once=TRUE)

predict.pgam Prediction

Description

Prediction and forecasting of the fitted model.

Usage

## S3 method for class 'pgam':predict(object, forecast = FALSE, k = 1, x = NULL, ...)

Arguments

object object of class pgam holding the fitted model

forecast if TRUE the function tries to forecast

k steps for forecasting

x covariate values for forecasting if the model has covariates. Must have the krows and p columns

... further arguments passed to method

Page 34: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

34 predict.pgam

Details

It estimates predicted values, their variances, deviance components, generalized Pearson statisticscomponents, local level, smoothed prediction and forecast.

Considering a Poisson process and a gamma priori, the predictive distribution of the model is neg-ative binomial with parameters at|t−1 and bt|t−1. So, the conditional mean and variance are givenby

E (yt|Yt−1) = at|t−1/bt|t−1

andV ar (yt|Yt−1) = at|t−1

(1 + bt|t−1

)/b2

t|t−1

Deviance components are estimated as follow

D (y; µ) = 2n∑

t=τ+1

at|t−1 log(

at|t−1

ytbt|t−1

)−

(at|t−1 + yt

)log

(yt + at|t−1

)(1 + bt|t−1

)yt

Generalized Pearson statistics has the form

X2 =n∑

t=τ+1

(ytbt|t−1 − at|t−1

)2

at|t−1

(1 + bt|t−1

)Approximate scale parameter is given by the expression

φ = fracX2edf

where edf is the number o degrees of reedom of the fitted model.

Value

List with those described in Details

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: aroughness penalty approach. Chapman and Hall, London

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

Page 35: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

print.pgam 35

Harvey, A. C. (1990) Forecasting, structural time series models and the Kalman Filter. Cambridge,New York

Hastie, T. J., Tibshirani, R. J.(1990) Generalized Additive Models. Chapman and Hall, London

McCullagh, P., Nelder, J. A. (1989). Generalized Linear Models. Chapman and Hall, 2nd edition,London

See Also

pgam, residuals.pgam

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

p <- predict(m)$yhatplot(ITRESP5)lines(p)

print.pgam Model output

Description

Print model information

Usage

## S3 method for class 'pgam':print(x, digits, ...)

Arguments

x object of class summary.pgam holding the fitted model information

digits number of decimal places for output

... further arguments passed to method

Details

This function only prints out the information.

Value

No value is returned.

Page 36: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

36 print.summary.pgam

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

See Also

pgam, predict.pgam

print.summary.pgam Summary output

Description

Print output of model information

Usage

## S3 method for class 'pgam':print.summary(x, digits, ...)

Arguments

x object of class summary.pgam holding the fitted model information

digits number of decimal places for output

... further arguments passed to method

Details

This function actually only prints out the information.

Value

No value is returned.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

See Also

pgam, predict.pgam

Page 37: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

residuals.pgam 37

residuals.pgam Residuals extraction

Description

Method for residuals extraction.

Usage

## S3 method for class 'pgam':residuals(object, type = "deviance", ...)

Arguments

object object of class pgam holding the fitted model

type type of residuals to be extracted. Default is deviance. Options are describedin Details

... further arguments passed to method

Details

The types of residuals available and a brief description are the following:

responseThese are raw residuals of the form rt = yt − E (yt|Yt−1).

pearsonPearson residuals are quite known and for this model they take the form rt = (yt − E (yt|Yt−1)) /V ar (yt|Yt−1).

devianceDeviance residuals are estimated by rt = sign (yt − E (yt|Yt−1)) ∗ sqrt (dt), where dt is thedeviance contribution of the t-th observation. See deviance.pgam for details on deviance com-ponent estimation.

std_devianceSame as deviance, but the deviance component is divided by (1 − ht), where ht is the t-th elementof the diagonal of the pseudo hat matrix of the approximating linear model. So they turn intort = sign (yt − E (yt|Yt−1)) ∗ sqrt (dt/ (1 − ht)).The element ht has the form ht = ω exp (ηt+1) /

∑t−1j=0 ωj exp (ηt−j), where η is the predictor of

the approximating linear model.

std_scl_devianceJust like the last one except for the dispersion parameter in its expression, so they have the form rt =sign (yt − E (yt|Yt−1)) ∗ sqrt (dt/φ ∗ (1 − ht)), where φ is the estimated dispersion parameter ofthe model. See summary.pgam for φ estimation.

Value

Vector of residuals of the model fitted.

Page 38: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

38 summary.pgam

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

McCullagh, P., Nelder, J. A. (1989). Generalized Linear Models. Chapman and Hall, 2nd edition,London

Pierce, D. A., Schafer, D. W. (1986) Residuals in generalized linear models. Journal of the Ameri-can Statistical Association, 81(396),977-986

See Also

pgam, pgam.fit, predict.pgam

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

r <- resid(m,"pearson")plot(r)

summary.pgam Summary output

Description

Output of model information

Usage

## S3 method for class 'pgam':summary(object, smo.test = FALSE, ...)

Page 39: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

summary.pgam 39

Arguments

object object of class pgam holding the fitted model

smo.test Approximate significance test of smoothing terms. It can take long, so defaultis FALSE

... further arguments passed to method

Details

Hypothesis tests of coefficients are based o t distribution. Significance tests of smooth terms areapproximate for model selection purpose only. Be very careful about the later.

Value

List containing all the information about the model fitted.

Author(s)

Washington Leite Junger 〈[email protected]〉 and Antonio Ponce de Leon 〈[email protected]

References

Harvey, A. C., Fernandes, C. (1989) Time series models for count data or qualitative observations.Journal of Business and Economic Statistics, 7(4):407–417

Campos, E. L., De Leon, A. C. M. P., Fernandes, C. A. C. (2003) Modelo Poisson-Gama paraSÃl’ries Temporais de Dados de Contagem - Teoria e AplicaÃgÃtes. 10a ESTE - Escola de SÃl’riesTemporais e Econometria

Junger, W. L. (2004) Modelo Poisson-Gama Semi-ParamÃl’rico: Uma Abordagem de Penaliza-ÃgÃco por Rugosidade. MSc Thesis. Rio de Janeiro, PUC-Rio, Departamento de EngenhariaElÃl’trica

Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: aroughness penalty approach. Chapman and Hall, London

Hastie, T. J., Tibshirani, R. J.(1990) Generalized Additive Models. Chapman and Hall, London

McCullagh, P., Nelder, J. A. (1989). Generalized Linear Models. Chapman and Hall, 2nd edition,London

Pierce, D. A., Schafer, D. W. (1986) Residuals in generalized linear models. Journal of the Ameri-can Statistical Association, 81(396),977-986

See Also

pgam, predict.pgam

Page 40: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

40 tbl2tex

Examples

library(pgam)data(aihrio)attach(aihrio)form <- ITRESP5~f(WEEK)+HOLIDAYS+rain+PM+g(tmpmax,7)+g(wet,3)m <- pgam(form,aihrio,omega=.8,beta=.01,maxit=1e2,eps=1e-4,optim.method="BFGS")

summary(m)

tbl2tex LaTeX table exporter

Description

Export a data frame to a fancy LaTeX table environment.

Usage

tbl2tex(tbl, label = "tbl:label(must_be_changed!)", caption = "Table generated with tbl2tex.", centered = TRUE, alignment = "center", digits = getOption("digits"), hline = TRUE, vline = TRUE, file = "", topleftcell = " ")

Arguments

tbl object of type data frame or matrix

label label for LaTeX cross reference

caption caption for LaTeX tabular environment

centered logical. TRUE for centered cells

alignment alignment of the object on the page

digits decimal digits after decimal point

hline logical. TRUE for horizontal borders

vline logical. TRUE for vertical borders

file filename for outputting. If none is provided, LaTeX code is routed through theconsole

topleftcell text for the top-left cell of the table

Details

This is a utility function intended to ease convertion of R objects to LaTeX format. It only exportsdata frame or data matrix nonetheless.

Value

LaTeX code is routed through file or console for copying and pasting.

Page 41: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

tbl2tex 41

Note

For now, it handles only numerical data.

Author(s)

Washington Leite Junger 〈[email protected]

See Also

pgam

Examples

library(pgam)data(aihrio)m <- aihrio[1:10,4:10]tbl2tex(m,label="tbl:r_example",caption="R example of tbl2tex",digits=4)

Page 42: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

Index

∗Topic datasetsaihrio, 3

∗Topic internalbackfitting, 4bkfsmooth, 5elapsedtime, 9envelope, 10fnz, 14formparser, 14framebuilder, 16intensity, 18link, 19lpnorm, 21pgam.filter, 25pgam.fit, 26pgam.hes2se, 28pgam.likelihood, 28pgam.par2psi, 30pgam.psi2par, 30

∗Topic regressionAIC.pgam, 1coef.pgam, 7deviance.pgam, 8envelope.pgam, 10f, 12fitted.pgam, 12g, 17logLik.pgam, 20periodogram, 22pgam, 23plot.pgam, 31predict.pgam, 32print.pgam, 34print.summary.pgam, 35residuals.pgam, 36summary.pgam, 37tbl2tex, 39

∗Topic smoothAIC.pgam, 1

coef.pgam, 7deviance.pgam, 8envelope.pgam, 10f, 12fitted.pgam, 12g, 17logLik.pgam, 20periodogram, 22pgam, 23plot.pgam, 31predict.pgam, 32print.pgam, 34print.summary.pgam, 35residuals.pgam, 36summary.pgam, 37tbl2tex, 39

∗Topic tsAIC.pgam, 1coef.pgam, 7deviance.pgam, 8envelope.pgam, 10f, 12fitted.pgam, 12g, 17logLik.pgam, 20periodogram, 22pgam, 23plot.pgam, 31predict.pgam, 32print.pgam, 34print.summary.pgam, 35residuals.pgam, 36summary.pgam, 37tbl2tex, 39

AIC.pgam, 1aihrio, 3

backfitting, 4, 24bkfsmooth, 5, 5, 17

42

Page 43: The pgam Package - Welcome to the University of Bayreuthftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/packages/... ·  · 2007-04-18The pgam Package April 18, 2007 Version 0.4.7

INDEX 43

coef.pgam, 7

deviance.pgam, 2, 8, 36

elapsedtime, 9envelope, 10, 11envelope.pgam, 10

f, 12, 15fitted.pgam, 12fnz, 14formparser, 12, 14, 16, 17, 19, 23, 24, 28,

30, 31framebuilder, 16

g, 15, 17

intensity, 18, 22

link, 19logLik.pgam, 2, 20lpnorm, 21

model.frame, 16

optim, 11, 23

periodogram, 18, 22pgam, 2, 5–7, 9, 11–22, 23, 26–32, 34, 35, 37,

38, 40pgam.filter, 25, 29pgam.fit, 7, 9, 13, 20, 26, 26, 29, 32, 37pgam.hes2se, 28pgam.likelihood, 9, 20, 26, 28, 32pgam.par2psi, 30pgam.psi2par, 30plot, 11, 22plot.pgam, 31predict.pgam, 5–8, 11, 13, 24, 26, 27, 32,

35, 37, 38print.pgam, 34print.summary.pgam, 35proc.time, 9

residuals.pgam, 11, 24, 27, 34, 36

smooth.spline, 6summary.pgam, 36, 37

tbl2tex, 39