bagging: Estimates bagging coefficients for a given pre-testing...

Description Usage Arguments Details Value References See Also Examples

View source: R/bagging.R

Description

Estimates the Inuoe and Kilian (2008) bagging for a given pre-testing procedure.

Usage

1
2
3
bagging(x, y, fn = NULL, R = 100, l = 3, sim = "fixed",
  pre.testing = c("group-joint", "joint", "individual", "personal"),
  fixed.controls = NULL, ...)

Arguments

x

Matrix of independent variables. Each row is an observation and each column is a variable.

y

Response variable equivalent to the function.

fn

If pre-testing="personal" the user must define the pre-testing function through this argument. This function must return a vector of coefficients where the first coefficient is the intercept. The first argument must be a matrix where the first column is the y and the remaining columns are x.

R

Number of bootstrap replucations.

l

lenght of the blocks for the block-boostrap.

sim

tsboot argument.

pre.testing

The type of pre-testing (see details).

fixed.controls

numeric or character vector indicating variables that must be used as fixed controls in the pre-testing. These variables are always selected.

...

Other arguments passed to tsboot and to personal pre-testing

Details

This function returns the pre-testing coefficients for all bootstrap samples. This coefficients may then be used to calculate forecasts.

There are three types of pre-testing:

Value

An object with S3 class bagging.

coefficients

Boostrap coefficients on each sample.

orig.coef

Coefficients on the original sample.

fitted.values

In-sample fitted values.

residuals

Model residuals.

pre.testing

The pre-testing used.

call

The matched call.

References

Inoue, Atsushi, and Lutz Kilian. "How useful is bagging in forecasting economic time series? A case study of US consumer price inflation." Journal of the American Statistical Association 103.482 (2008): 511-522.

Garcia, Medeiros and Vasconcelos (2017).

See Also

predict.bagging

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## == This example uses the Brazilian inflation data from
#Garcia, Medeiros and Vasconcelos (2017) == ##
data("BRinf")

## == Data preparation == ##
## == The model is yt = a + Xt-1'b + ut == ##
## == The autorregressive is a fixed control == ##
aux = embed(BRinf,2)
y=aux[,1]
x=aux[,-c(1:ncol(BRinf))]

model=bagging(x,y,pre.testing = "group-joint")
model$orig.coef

## == check selection frequency == ##
coef=coef(model)
coef[coef!=0]=1
frequency=(colSums(coef))[-1] # remove intercept
barplot(frequency)

## == see fitted values == ##
plot(y,type="l")
lines(fitted(model),col=2)

tboonman/eba_lasso_bma documentation built on Nov. 5, 2019, 10:01 a.m.