Package 'gfunctions'

Title: G-Functions
Description: Modified versions of the lag() and summary() functions: glag() and gsummary(). The prefix 'g' is a reminder of who to blame if things do not work as they should.
Authors: Genaro Sucarrat [aut, cre]
Maintainer: Genaro Sucarrat <[email protected]>
License: GPL (>= 2)
Version: 1.0
Built: 2024-11-14 03:42:50 UTC
Source: https://github.com/cran/gfunctions

Help Index


glag() and gsummary(): Modified versions of lag() and summary()

Description

glag() and gsummary() are modifications of the lag() and summary() functions from the stats package in that they return different information.

Details

Version: 1.0
Date: 2024-04-16
Licence: GPL-2

Author(s)

Genaro Sucarrat: http://www.sucarrat.net/

Maintainer: Genaro Sucarrat

See Also

lag(), summary()


Lag a vector or a matrix, with special treatment of zoo and ts objects

Description

The glag() function is similar to the lag() function from the stats package, but glag() actually lags (the default in lag() is to lead). The funtion glag() also enables padding (for example NAs or 0s) of the lost entries. Contrary to the lag() function, however, the default in glag() is to pad (with NAs). The glag() is particularly suited for zoo objects, since their indexing is retained. The prefix g is a reminder of who to blame if things do not work properly.

Usage

## generic:
glag(x, ...)
## Default S3 method:
glag(x, k = 1, pad = TRUE, pad.value = NA, ...)

Arguments

x

a numeric vector or matrix, or objects of class zoo or ts.

k

integer equal to the lag (the default is 1). Negative values (that is, 'leading') is not possible.

pad

logical. If TRUE (default), then the lost entries are padded with pad.value. If FALSE, then no padding is undertaken.

pad.value

the padding value.

...

additional arguments

Value

A vector or matrix, or objects of class zoo or ts, with the lagged values.

Author(s)

Genaro Sucarrat, http://www.sucarrat.net/

See Also

lag(), lag.zoo()

Examples

##lag series with NA for the missing entries:
x <- rnorm(5)
glag(x)

##lag series with no padding:
x <- rnorm(5)
glag(x, pad = FALSE)

##lag series and retain the original zoo-index ordering:
x <- as.zoo(rnorm(5))
glag(x)

##lag two periods:
glag(x, k = 2)

The gsummary() function

Description

The gsummary() function provides an alternative to the summary() function by returning different information. The prefix g is a reminder of who to blame if things do not work properly.

Usage

## generic:
gsummary(object, ...)
## Default S3 method:
gsummary(object, ...)
## S3 method for class 'data.frame'
gsummary(object, ...)
## S3 method for class 'lm'
gsummary(object, vcov.type = c("ordinary", "robust", "hac"), confint.level = 0.95, ...)
## S3 method for class 'glm'
gsummary(object, confint.level = 0.95, ...)

Arguments

object

an object of suitable class, for example data.frame, lm or glm.

vcov.type

a character string that determines the variance-vcovariance estimator. If "ordinary" (default), then the ordinary estimator is used (vcov.lm()). If "robust", then the heteroscedasticity robust estimator of White (1980) (vcovHC() with type = "HC") is used. If "hac", then the heteroscedasticity and autocorrelation robust estimator of Newey and West (1987) (NeweyWest()) is used.

confint.level

a number between 0 and 1 (the default is 0.95), or NULL. If a number, then confidence intervals are printed (the default is 95 percent). If NULL, then confidence intervals are not printed.

...

additional arguments

Value

No value is returned, the function only prints. The content of the print depends on the class of its main argument object.

Author(s)

Genaro Sucarrat, http://www.sucarrat.net/

References

Halbert White (1980): 'A Heteroskedasticity-Consistent Covariance Matrix Estimator and a Direct Test for Heteroskedasticity', Econometrica 48, pp. 817-838. Whitney K. Newey and Kenned D. West (1987): 'A Simple, Positive Semi-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix', Econometrica 55, pp. 703-708.

See Also

summary()

Examples

##simulate some data:
set.seed(123)
y <- rnorm(20); x <- rnorm(20); z <- rnorm(20)

##illustrate gsummary.data.frame():
mydataframe <- as.data.frame(cbind(y,x,z))
gsummary(mydataframe)

##illustrate gsummary.lm():
mymodel <- lm(y ~ x + z)
gsummary(mymodel)
gsummary(mymodel, vcov.type="robust")
gsummary(mymodel, vcov.type="hac")
gsummary(mymodel, confint.level=0.90)
gsummary(mymodel, confint.level=0.99)
gsummary(mymodel, confint.level=NULL)

##illustrate gsummary.glm():
y <- as.numeric( y > 0 )
mymodel <- glm(y ~ x + z, family=binomial)
gsummary(mymodel)