Version: | 0.4.17 |
Date: | 2022-08-19 |
Author: | Washington Junger <wjunger@ims.uerj.br> |
Maintainer: | Washington Junger <wjunger@ims.uerj.br> |
Depends: | R (≥ 3.0.0),stats,utils |
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-3 | file LICENSE |
NeedsCompilation: | yes |
Packaged: | 2022-08-19 17:38:13 UTC; wjunger |
Repository: | CRAN |
Date/Publication: | 2022-08-19 19:40:02 UTC |
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 |
k |
default is 2 for AIC. If |
... |
further arguments passed to method |
Details
An approximate measure of parsimony of the Poisson-Gama Additive Models can be achieved by the expression
AIC=\left(D\left(y;\hat\mu\right)+2gle\right)/\left(n-\tau\right)
where gle
is the number of degrees of freedom of the fitted model and \tau
is the index of the first non-zero observation.
Value
The approximate AIC value of the fitted model.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
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)
Sample dataset
Description
This is a dataset for Poisson-Gamma Additive Models functions testing.
Usage
data(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
Details
This is a reduced dataset of those used to estimate possible effects of air pollution on hospital admissions outcomes in Universidade do Estado do Rio de Janeiro, Rio de Janeiro, Brasil.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
Source
Secretary for the Environment of the Rio de Janeiro City, Brazilian Ministry of Defense and Brazilian Ministry of Health
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 residuals of parametric fit |
x |
matrix of covariates |
df |
equivalent degrees of freedom. If |
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 |
eps |
convergence control criterion |
maxit |
convergence control iterations |
info |
if |
Details
Backfitting algorithm estimates the approximating regression surface, working around the "curse of dimentionality".
More details soon enough.
Value
Fitted smooth curves and partial residuals.
Note
This function is not intended to be called directly.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
References
Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: a roughness penalty approach. Chapman and Hall, London
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
Hastie, T. J., Tibshirani, R. J.(1990) Generalized Additive Models. Chapman and Hall, London
See Also
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 residuals of parametric fit |
x |
independent variable. Univariate fit only |
df |
equivalent degrees of freedom. If |
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 |
Details
Although several smoothers can be used in semiparametric regression models, only natural cubic splines is intended to be used in Poisson-Gamma Additive Models due to its interesting mathematical properties.
Nowadays, this function interfaces the smooth.spline
in stats
library. It will become not dependent 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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
References
Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: a roughness penalty approach. Chapman and Hall, London
Hastie, T. J., Tibshirani, R. J.(1990) Generalized Additive Models. Chapman and Hall, London
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
See Also
Coefficients extraction
Description
Method for parametric coefficients extraction.
Usage
## S3 method for class 'pgam'
coef(object, ...)
Arguments
object |
object of class |
... |
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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
See Also
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)
Deviance extraction
Description
Method for total deviance value extraction.
Usage
## S3 method for class 'pgam'
deviance(object, ...)
Arguments
object |
object of class |
... |
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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
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")
deviance(m)
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 wjunger@ims.uerj.br
See Also
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 wjunger@ims.uerj.br
References
Atkinson, A. C. (1985) Plots, transformations and regression : an introduction to graphical methods of diagnostic regression analysis. Oxford Science Publications, Oxford.
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, ...)
Arguments
object |
object of class |
type |
type of residuals to be extracted. Default is |
size |
value giving the size of the envelope. Default is |
rep |
number of replications for envelope construction. Default is |
, that is the smallest 95% band that can be build
optim.method |
optimization method to be passed to |
epsilon |
convergence control to be passed to |
maxit |
convergence control to be passed to |
plot |
if |
title |
title for the plot |
verbose |
if |
... |
further arguments to |
Details
Method for the generic function envelope
.
Sometimes the usual Q-Q plot shows an unsatisfactory pattern of the residuals of a model fitted and we are led to think that the model is badly specificated. The normal plot with simulated envelope indicates that under the distribution of the response variable the model is OK if only a few points fall off the envelope.
If object
is of class pgam
the envelope is estimated and optionally plotted, else if is of class envelope
then it is only plotted.
Value
An object of class envelope
holding the information needed to plot the envelope.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
References
Atkinson, A. C. (1985) Plots, transformations and regression : an introduction to graphical methods of diagnostic regression analysis. Oxford Science Publications, Oxford.
See Also
pgam
, predict.pgam
, residuals.pgam
Utility function
Description
Generate the partition of design matrix regarded to the seasonal factor in its argument. Used in the model 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 wjunger@ims.uerj.br
See Also
Fitted values extraction
Description
Method for fitted values extraction.
Usage
## S3 method for class 'pgam'
fitted(object, ...)
Arguments
object |
object of class |
... |
further arguments passed to method |
Details
Actually, the fitted values are worked out by the function predict.pgam
. Thus, this method is supposed to turn fitted values extraction easier. See predict.pgam
for details on one-step ahead prediction.
Value
Vector of predicted values of the model fitted.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
See Also
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)
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 wjunger@ims.uerj.br
See Also
Read the model formula and split it into the parametric and nonparametric partitions
Description
Read the model formula and split it into two new ones concerning the parametric and nonparametric partitions of the predictor.
Usage
formparser(formula, env=parent.frame())
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 model into two parts regarding the parametric nature of the model. A model can be specified as following:
Y~f\left(sf_{r}\right)+V1+V2+V3+g\left(V4,df_{4}\right)+g\left(V5,df_{5}\right)
where sf_{r}
is a seasonal factor with period r
and df_{i}
is the degree of freedom of the smoother of the i-th covariate. Actually, two new formulae will be created:
~sf_{1}+\dots+sf_{r}+V1+V2+V3
and
~V4+V5
These two formulae will be used to build the necessary datasets for model estimation. Dummy variables 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 wjunger@ims.uerj.br
See Also
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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
See Also
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 |
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 wjunger@ims.uerj.br
References
Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: a roughness penalty approach. Chapman and Hall, London
Hastie, T. J., Tibshirani, R. J.(1990) Generalized Additive Models. Chapman and Hall, London
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
See Also
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 |
Details
This function is intended to port other link functions than \log{\left(\right)}
to Poisson-Gamma Additive Models. 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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Loglik extraction
Description
Method for loglik value extraction.
Usage
## S3 method for class 'pgam'
logLik(object, ...)
Arguments
object |
object of class |
... |
further arguments passed to method |
Details
See pgam.likelihood
for more information on log-likelihood evaluation in Poisson-Gamma models.
Value
The maximum value achieved by the likelihood optimization process.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
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")
logLik(m)
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. |
Value
The computed norm value.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br
See Also
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 |
plot |
if |
... |
further arguments to |
Details
The raw periodogram is an estimator of the spectrum of a time series, it still is a good indicator of unresolved seasonality patterns in residuals of the fitted model. Check the function intensity
for frequencies extraction.
This function plots a fancy periodogram where the intensities of the angular frequencies are plotted resembling tiny lollipops.
Value
Periodogram ordered by intensity.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
References
Box, G., Jenkins, G., Reinsel, G. (1994) Time Series Analysis : Forecasting and Control. 3rd edition, Prentice Hall, New Jersey.
Diggle, P. J. (1989) Time Series : A Biostatistical Introduction. Oxford University Press, Oxford.
See Also
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 |
dataset |
a data set in the environment search path. Missing data is temporarily not handled |
omega |
initial value for the discount factor |
beta |
vector of initial values for covariates coefficients. If a sigle value is supplied it is replicated to fill in the whole vector |
offset |
default is |
digits |
number of decimal places for printing information out |
na.action |
action to be taken if missing values are found. Default is |
maxit |
convergence control iterations |
eps |
convergence control criterion |
lfn.scale |
scales the likelihood function and is passed to |
control |
convergence control of |
optim.method |
optimization method passed to |
bkf.eps |
convergence control criterion for the backfitting algorithm |
bkf.maxit |
convergence control iterations for the backfitting algorithm |
se.estimation |
if |
verbose |
if |
Details
The formula is parsed by formparser
in order to extract all the information necessary for model fit. Split the model into two parts regarding the parametric nature of the model.
A model can be specified as following:
Y~f\left(sf_{r}\right)+V1+V2+V3+g\left(V4,df_{4}\right)+g\left(V5,df_{5}\right)
where sf_{r}
is a seasonal factor with period r
and df_{i}
is the degree of freedom of the smoother of the i-th covariate. Actually, two new formulae will be created:
~sf_{1}+\dots+sf_{r}+V1+V2+V3
and
~V4+V5
These two formulae will be used to build the necessary datasets for model estimation. Dummy variables 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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
References
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
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
Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: a roughness penalty approach. Chapman and Hall, London
See Also
predict.pgam
, formparser
, residuals.pgam
, backfitting
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)
Estimation of the conditional distributions parameters of the level
Description
The priori and posteriori conditional distributions of the level is gamma and their parameters are estimated through this recursive filter. See Details for a thorough description.
Usage
pgam.filter(w, y, eta)
Arguments
w |
running estimate of discount factor |
y |
|
eta |
full linear or semiparametric predictor. Linear predictor is a trivial case of semiparameric model |
Details
Consider Y_{t-1}
a vector of observed values of a Poisson process untill the instant t-1
. Conditional on that, \mu_{t}
has gamma distribution with parameters given by
a_{t|t-1}=\omega a_{t-1}
b_{t|t-1}=\omega b_{t-1}\exp\left(-\eta_{t}\right)
Once y_{t}
is known, the posteriori distribution of \mu_{t}|Y_{t}
is also gamma with parameters given by
a_{t}=\omega a_{t-1}+y_{t}
b_{t}=\omega b_{t-1}+\exp\left(\eta_{t}\right)
with t=\tau,\ldots,n
, where \tau
is the index of the first non-zero observation of y
.
Diffuse initialization of the filter is applied by setting a_{0}=0
and b_{0}=0
. A proper distribution of \mu_{t}
is obtained at t=\tau
, where \tau
is the fisrt non-zero observation of the time series.
Value
A list containing the time varying parmeters of the priori and posteriori conditional distribution is returned.
Note
This function is not intended to be called directly.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
See Also
pgam
, pgam.likelihood
, pgam.fit
, predict.pgam
One-step ahead prediction and variance
Description
Estimate one-step ahead expectation and variance of y_{t}
conditional on observed time series until the instant t-1
.
Usage
pgam.fit(w, y, eta, partial.resid)
Arguments
w |
estimate of discount factor |
y |
observed time series which is the response variable of the model |
eta |
semiparametric predictor |
partial.resid |
type of partial residuals. |
Details
Partial residuals for semiparametric estimation is extracted. Those are regarded to the parametric partition fit of the model. Available types are raw
, pearson
and deviance
. The type raw
is prefered. Properties of other form of residuals not fully tested. Must be careful on choosing it.
See details 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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: a roughness penalty approach. Chapman and Hall, London
See Also
pgam
, residuals.pgam
, predict.pgam
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 |
fperiod |
vector containing as many seasonal factors as there are in model formula |
se.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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
See Also
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())
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 |
env |
the caller environment for log-likelihood value to be stored |
Details
Log-likelihood function of hyperparameters \omega
and \beta
is given by
\log L\left(\omega,\beta\right)=\sum_{t=\tau+1}^{n}{\log \Gamma\left(a_{t|t-1}+y_{t}\right)-\log y_{t}!-\log \Gamma\left(a_{t|t-1}\right)+a_{t|t-1}\log b_{t|t-1}-\left(a_{t|t-1}+y_{t}\right)\log \left(1+b_{t|t-1}\right)}
where a_{t|t-1}
and b_{t|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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
See Also
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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
See Also
Utility function
Description
Put hyperparameters into unconstrained form for optimization.
Usage
pgam.psi2par(w, beta, fperiod)
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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
See Also
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 |
rug |
if |
se |
if |
at.once |
if |
scaled |
if |
... |
further arguments passed to method |
Details
Error band of smooth terms is approximated.
Value
No value returned.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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)
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 |
forecast |
if |
k |
steps for forecasting |
x |
covariate values for forecasting if the model has covariates. Must have the |
... |
further arguments passed to method |
Details
It estimates predicted values, their variances, deviance components, generalized Pearson statistics components, local level, smoothed prediction and forecast.
Considering a Poisson process and a gamma priori, the predictive distribution of the model is negative binomial with parameters a_{t|t-1}
and b_{t|t-1}
. So, the conditional mean and variance are given by
E\left(y_{t}|Y_{t-1}\right)=a_{t|t-1}/b_{t|t-1}
and
Var\left(y_{t}|Y_{t-1}\right)=a_{t|t-1}\left(1+b_{t|t-1}\right)/b_{t|t-1}^{2}
Deviance components are estimated as follow
D\left(y;\hat\mu\right)=2\sum_{t=\tau+1}^{n}{a_{t|t-1}\log \left(\frac{a_{t|t-1}}{y_{t}b_{t|t-1}}\right)-\left(a_{t|t-1}+y_{t}\right)\log \frac{\left(y_{t}+a_{t|t-1}\right)}{\left(1+b_{t|t-1}\right)y_{t}}}
Generalized Pearson statistics has the form
X^{2}=\sum_{t=\tau+1}^{n}\frac{\left(y_{t}b_{t|t-1}-a_{t|t-1}\right)^{2}} {a_{t|t-1}\left(1+b_{t|t-1}\right)}
Approximate scale parameter is given by the expression
\hat\phi=frac{X^{2}}{edf}
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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
References
Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: a roughness 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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
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
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)$yhat
plot(ITRESP5)
lines(p)
Model output
Description
Print model information
Usage
## S3 method for class 'pgam'
print(x, digits, ...)
Arguments
x |
object of class |
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.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
See Also
Summary output
Description
Print output of model information
Usage
## S3 method for class 'pgam'
print.summary(x, digits, ...)
Arguments
x |
object of class |
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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
See Also
Residuals extraction
Description
Method for residuals extraction.
Usage
## S3 method for class 'pgam'
residuals(object, type = "deviance", ...)
Arguments
object |
object of class |
type |
type of residuals to be extracted. Default is |
... |
further arguments passed to method |
Details
The types of residuals available and a brief description are the following:
response
These are raw residuals of the form r_{t}=y_{t}-E\left(y_{t}|Y_{t-1}\right)
.
pearson
Pearson residuals are quite known and for this model they take the form r_{t}=\left(y_{t}-E\left(y_{t}|Y_{t-1}\right)\right)/Var\left(y_{t}|Y_{t-1}\right)
.
deviance
Deviance residuals are estimated by r_{t}=sign\left(y_{t}-E\left(y_{t}|Y_{t-1}\right)\right)*sqrt\left(d_{t}\right)
, where d_{t}
is the deviance contribution of the t-th observation. See deviance.pgam
for details on deviance component estimation.
std_deviance
Same as deviance, but the deviance component is divided by (1-h_{t})
, where h_{t}
is the t-th element of the diagonal of the pseudo hat matrix of the approximating linear model. So they turn into r_{t}=sign\left(y_{t}-E\left(y_{t}|Y_{t-1}\right)\right)*sqrt\left(d_{t}/\left(1-h_{t}\right)\right)
.
The element h_{t}
has the form h_{t}=\omega\exp\left(\eta_{t+1}\right)/\sum_{j=0}^{t-1}\omega^{j}\exp\left(\eta_{t-j}\right)
, where \eta
is the predictor of the approximating linear model.
std_scl_deviance
Just like the last one except for the dispersion parameter in its expression, so they have the form r_{t}=sign\left(y_{t}-E\left(y_{t}|Y_{t-1}\right)\right)*sqrt\left(d_{t}/\phi*\left(1-h_{t}\right)\right)
, where \phi
is the estimated dispersion parameter of the model. See summary.pgam
for \phi
estimation.
Value
Vector of residuals of the model fitted.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
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 American Statistical Association, 81(396),977-986
See Also
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 output
Description
Output of model information
Usage
## S3 method for class 'pgam'
summary(object, smo.test = FALSE, ...)
Arguments
object |
object of class |
smo.test |
Approximate significance test of smoothing terms. It can take long, so default is |
... |
further arguments passed to method |
Details
Hypothesis tests of coefficients are based o t distribution. Significance tests of smooth terms are approximate 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 wjunger@ims.uerj.br and Antonio Ponce de Leon ponce@ims.uerj.br
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
Junger, W. L. (2004) Semiparametric Poisson-Gamma models: a roughness penalty approach. MSc Dissertation. Rio de Janeiro, PUC-Rio, Department of Electrical Engineering.
Green, P. J., Silverman, B. W. (1994) Nonparametric Regression and Generalized Linear Models: a roughness 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 American Statistical Association, 81(396),977-986
See Also
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)
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. |
alignment |
alignment of the object on the page |
digits |
decimal digits after decimal point |
hline |
logical. |
vline |
logical. |
file |
filename for outputting. If none is provided, LaTeX code is routed through the console |
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 exports data frame or data matrix nonetheless.
Value
LaTeX code is routed through file or console for copying and pasting.
Note
For now, it handles only numerical data.
Author(s)
Washington Leite Junger wjunger@ims.uerj.br
See Also
Examples
library(pgam)
data(aihrio)
m <- aihrio[1:10,4:10]
tbl2tex(m,label="tbl:r_example",caption="R example of tbl2tex",digits=4)