knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "rmd_files/README-"
)

jackknife version 0.1.0 (RED JACK)

The jackknife package implements jackknife method of estimating standard errors.

The corresponding reference here

The Jackknife and the Bootstrap for eneral Stationary Observations

How to install

You can install the development version from GitHub by running

devtools::install_github("yukai-yang/jackknife")

provided that the package "devtools" has been installed beforehand.

After installing the package, you need to load (attach better say) it by running the code

library(jackknife)

You can take a look at all the available functions and data in the package

ls( grep("jackknife", search()) ) 

Example

let us define the weights for deleting or downweighting the blocks:

vw1 = 1
vw2 = c(0.25,0.75,1,0.75,0.25)

Then we simulate data from the AR(1) model ```r{ar1}

the AR(1) model

iN = 100 mdl <- list(ar = c(0.8)) vx <- arima.sim(model=mdl, iN)

### First order autocorrelation

The first order autocorrelation is a linear statistic. We define the corresponding T and delta function below.
```r{auto}
# for first order autocorrelation
# dfunc vec 2, y_t and y_t-1
dfunc <- function(yy, my, vy) return(prod(yy - my)/vy)

tfunc <- function(rho, my, vy) return(rho)

We do the jackknife for the first kind of weights: ```r{jack1}

results

ret = jackknife(as.vector(vx), tfunc, dfunc, im=2, vw=vw1, my=mean(vx), vy=var(vx)) ret

Then the second
```r{jack2}
ret = jackknife(as.vector(vx), tfunc, dfunc, im=2, vw=vw2, my=mean(vx), vy=var(vx))
ret

Compare them with the autocorrelation function. ```r{acf}

acf

tmp = acf(vx) tmp

### OLS estimator

The OLS estimator is also a linear statistic. We define the corresponding T and delta function below.
```r{para}
# for estimator of the AR(1)
dfunc <- function(yy, inv_xx) return(c(inv_xx %*% rbind(1, yy[1]) * yy[2]))

tfunc <- function(rho, inv_xx) return(rho)

We also need some additional arguments: ```r{inv} inv_xx = cbind(1,vx[1:(length(vx)-1)]) inv_xx = chol2inv(chol(crossprod(inv_xx)/(length(vx)-1)))

The results
```r{res1}
# results
ret = jackknife(as.vector(vx), tfunc, dfunc, im=2, vw=vw1, inv_xx=inv_xx)
ret

r{res2} ret = jackknife(as.vector(vx), tfunc, dfunc, im=2, vw=vw2, inv_xx=inv_xx) ret



yukai-yang/jackknife documentation built on Nov. 5, 2019, 1:21 p.m.