# set the knitr options ... for everyone!
# if you unset this, then vignette build bonks. oh, joy.
#opts_knit$set(progress=TRUE)
opts_knit$set(eval.after='fig.cap')
# for a package vignette, you do want to echo.
# opts_chunk$set(echo=FALSE,warning=FALSE,message=FALSE)
opts_chunk$set(warning=FALSE,message=FALSE)
#opts_chunk$set(results="asis")
opts_chunk$set(cache=TRUE,cache.path="cache/")

#opts_chunk$set(fig.path="github_extra/figure/",dev=c("pdf","cairo_ps"))
#opts_chunk$set(fig.path="github_extra/figure/",dev=c("png","pdf"))
opts_chunk$set(fig.path="tools/figure/",dev=c("png"))
opts_chunk$set(fig.width=7,fig.height=6,dpi=100,out.width='700px',out.height='600px')

# doing this means that png files are made of figures;
# the savings is small, and it looks like shit:
#opts_chunk$set(fig.path="figure/",dev=c("png","pdf","cairo_ps"))
#opts_chunk$set(fig.width=4,fig.height=4)
# for figures? this is sweave-specific?
#opts_knit$set(eps=TRUE)

# this would be for figures:
#opts_chunk$set(out.width='.8\\textwidth')
# for text wrapping:
options(width=64,digits=2)
opts_chunk$set(size="small")
opts_chunk$set(tidy=TRUE,tidy.opts=list(width.cutoff=50,keep.blank.line=TRUE))

#epsiwal.meta <- packageDescription('epsiwal')

epsiwal

Build Status codecov.io CRAN Downloads Total

Implements conditional inference on normal variates as described in Lee, Sun, Sun and Taylor, "Exact Post Selection Inference, with Application to the Lasso."

-- Steven E. Pav, shabbychef@gmail.com

Installation

This package may be installed from CRAN; the latest version may be found on github via devtools, or installed via drat:

# CRAN
install.packages(c('epsiwal'))
# devtools
if (require(devtools)) {
    # latest greatest
    install_github('shabbychef/epsiwal')
}
# via drat:
if (require(drat)) {
    drat:::add('shabbychef')
    install.packages('epsiwal')
}

Basic Usage

First we perform some simulations under the null to show that the p-values are uniform. We draw a normal vector with identity covariance and zero mean, then flip the sign of each element to make them positive. We then perform inference on the sum of the mean values.

library(epsiwal)
p <- 20
mu <- rep(0,p)
Sigma <- diag(p)
A <- - diag(p)
b <- rep(0,p)
eta <- rep(1,p)
Sigma_eta <- diag(Sigma)
eta_mu <- as.numeric(t(eta)%*%mu)
set.seed(1234)
pvals <- replicate(1000,{
    y <- rnorm(p,mean=mu,sd=sqrt(diag(Sigma)))
    ay <- abs(y)
    pconnorm(y=ay,A=A,b=b,eta=eta,Sigma_eta=Sigma_eta,eta_mu=eta_mu)
})
qqplot(pvals,qunif(ppoints(length(pvals))),main='p-values under procedure',
             ylab='theoretical',xlab='empirical') 
library(epsiwal)
p <- 20
mu <- rep(0,p)
Sigma <- diag(p)
A <- - diag(p)
b <- rep(0,p)
eta <- rep(1,p)
Sigma_eta <- diag(Sigma)
eta_mu <- as.numeric(t(eta)%*%mu)
type_I <- 0.05
set.seed(1234)
civals <- replicate(5000,{
    y <- rnorm(p,mean=mu,sd=sqrt(diag(Sigma)))
    ay <- abs(y)
    ci <- ci_connorm(y=ay,A=A,b=b,p=type_I,eta=eta,Sigma_eta=Sigma_eta)
})
cat('Empirical coverage of the',type_I,'confidence bound is around',mean(civals < eta_mu),'.\n')

See also



shabbychef/epsiwal documentation built on May 15, 2022, 4:30 a.m.