bw {tvReg}R Documentation

Bandwidth Selection by Cross-Validation

Description

Calculate bandwidth(s) by cross-validation for functions tvSURE, tvVAR and tvLM.

Usage

bw(x, ...)

## Default S3 method:
bw(
  x,
  y,
  z = NULL,
  cv.block = 0,
  est = c("lc", "ll"),
  tkernel = c("Triweight", "Epa", "Gaussian"),
  singular.ok = TRUE,
  ...
)

## S3 method for class 'list'
bw(
  x,
  y,
  z = NULL,
  cv.block = 0,
  est = c("lc", "ll"),
  tkernel = c("Triweight", "Epa", "Gaussian"),
  singular.ok = TRUE,
  ...
)

## S3 method for class 'tvlm'
bw(x, ...)

## S3 method for class 'tvar'
bw(x, ...)

## S3 method for class 'tvvar'
bw(x, ...)

## S3 method for class 'tvsure'
bw(x, ...)

## S3 method for class 'tvplm'
bw(x, ...)

## S3 method for class 'pdata.frame'
bw(
  x,
  z = NULL,
  method,
  cv.block = 0,
  est = c("lc", "ll"),
  tkernel = c("Triweight", "Epa", "Gaussian"),
  ...
)

Arguments

x

An object used to select a method.

...

Other parameters passed to specific methods.

y

A matrix or vector with the dependent variable(s).

z

A vector with the variable over which coefficients are smooth over.

cv.block

A positive scalar with the size of the block in leave-one block-out cross-validation. By default 'cv.block=0' meaning leave-one-out cross-validation.

est

The nonparametric estimation method, one of "lc" (default) for linear constant or "ll" for local linear.

tkernel

A character, either "Triweight" (default), "Epa" or "Gaussian" kernel function.

singular.ok

Logical. If FALSE, a singular model is an error.

method

A character with the choice of panel model/estimation method: If method = tvPOLS (default) then the data is pooled estimated with time-varying OLS. No individual or time effects are estimated If method = tvFE then individual effects which might be correlated with the regressors are estimated. If method = tvRE then individual effects are considered random and independent of the regressors.

Value

bw returns a vector or a scalar with the bandwith to estimate the mean or the covariance residuals, fitted values.

A scalar or a vector of scalars.

A scalar.

Examples

##Generate data
tau <- seq(1:200)/200
beta <- data.frame(beta1 = sin(2*pi*tau), beta2 =  2*tau)
X <- data.frame(X1 = rnorm(200), X2 =  rchisq(200, df = 4))
error <- rt(200, df = 10)
y <- apply(X*beta, 1, sum) + error

##Select bandwidth by cross-validation
bw <- bw(X, y, est = "ll", tkernel = "Gaussian")

data( Kmenta, package = "systemfit" )

## x is a list of matrices containing the regressors, one matrix for each equation
x <- list()
x[[1]] <- Kmenta[, c("price", "income")]
x[[2]] <- Kmenta[, c("price", "farmPrice", "trend")]

## 'y' is a matrix with one column for each equation
y <- cbind(Kmenta$consump, Kmenta$consump)

## Select bandwidth by cross-validation
bw <- bw(x = x, y = y)

##One bandwidth per equation
print(bw)


[Package tvReg version 0.5.9 Index]