pkg.plm.fast {plm}R Documentation

Function to Switch On/Off Fast Data Transformations

Description

A significant speed up can be gained by using fast (panel) data transformation functions from package collapse. By default, this speed up is not enabled and function pkg.plm.fast can be used to enable/disable the speed up.

Usage

pkg.plm.fast(use = TRUE, suppressPrint = FALSE)

Arguments

use

logical, indicating whether the fast data transformations shall be turned on (TRUE, the default) or off (FALSE).

suppressPrint

logical (default is FALSE), indicating whether the function shall print messages about (de-)activation of the fast functions.

Details

The package collapse provides fast data transformation functions written in C/C++, among them some especially suitable for panel data.

By default, package plm uses base R implementations and R-based code in from package plm. A significant speed-up can be gained by using the functions provided in package collapse. To enable the speed-up, execute pkg.plm.fast(use = TRUE) once per session. The package will then make use of the faster functions until the session ends or the speed-up is disabled by executing pkg.plm.fast(use = FALSE).

Having package collapse installed locally, is a requirement for this function. However, this package currently not a hard dependency for package plm but a 'Suggests' dependency.

Currently, these functions benefit from the speed-up (more functions are under investigation):

Value

A logical (TRUE if use = TRUE was set, FALSE if use = FALSE), returned invisibly.

See Also

package 'collapse' on CRAN

Examples

## Not run: 
### A benchmark plm without and with speed-up
library("plm")
library("collapse")
library("microbenchmark")
rm(list = ls())
data("wlddev", package = "collapse")
form <- LIFEEX ~ PCGDP + GINI

# produce big data set (taken from collapse's vignette)
wlddevsmall <- get_vars(wlddev, c("iso3c","year","OECD","PCGDP","LIFEEX","GINI","ODA"))
wlddevsmall$iso3c <- as.character(wlddevsmall$iso3c)
data <- replicate(100, wlddevsmall, simplify = FALSE)
rm(wlddevsmall)
uniquify <- function(x, i) {
	x$iso3c <- paste0(x$iso3c, i)
	x
}
data <- unlist2d(Map(uniquify, data, as.list(1:100)), idcols = FALSE)
data <- pdata.frame(data, index = c("iso3c", "year"))
pdim(data) # Balanced Panel: n = 21600, T = 59, N = 1274400 // but many NAs
# data <- na.omit(data)
# pdim(data) # Unbalanced Panel: n = 13300, T = 1-31, N = 93900

pkg.plm.fast(use = FALSE) # default: fast functions of 'collapse' not in use
times <- 3 # no. of repetitions for benchmark
bench_res_plm <- microbenchmark(
  plm(form, data = data, model = "within"),
  plm(form, data = data, model = "within", effect = "twoways"),
  plm(form, data = data, model = "random"),
  plm(form, data = data, model = "random", effect = "twoways"),
 times = times)

pkg.plm.fast(use = TRUE)
bench_res_collapse <- microbenchmark(
  plm(form, data = data, model = "within"),
  plm(form, data = data, model = "within", effect = "twoways"),
  plm(form, data = data, model = "random"),
  plm(form, data = data, model = "random", effect = "twoways"),
 times = times)
print(bench_res_plm,      unit = "s")
print(bench_res_collapse, unit = "s")

## End(Not run)

[Package plm version 2.3-0 Index]