pred_int_conformal: Prediction interval for a 'numeric' based on conformal...

Description Usage Arguments Details Value Examples

View source: R/pred_int_conformal.R

Description

Conformal inference prediction interval for a numeric

Usage

1
2
3
4
5
6
7
pred_int_conformal(
  x,
  neval = 200,
  level = 0.95,
  point.pred = c("mean", "median"),
  method = c("quantile", "deviation", "jackknife")
)

Arguments

x

should be an object of class "numeric"

neval

number of evaluations to perform

level

coverage level with default 0.95

point.pred

point prediction either 'mean' or 'median'

method

totally experimental either 'quantile' or 'deviation'

Details

Calculate prediction interval based on conformal inference.

I wrote this function after reading this tutorial: https://cdsamii.github.io/cds-demos/conformal/conformal-tutorial.html

Value

a prediction interval

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Not run: 
## Prediciton interval for simulated data
set.seed(123)
x <- rnorm(100)
pdi.t <- pred_int_tdist(x) 
pdi.q <- pred_int_conformal(x)
pdi.d <- pred_int_conformal(x, method = "deviation")
pdi.j <- pred_int_conformal(x, method = "jackknife")
## Not really a prediction interval, but related
pdi.q <- quantile(x, probs = c(0.5, 0.025, 0.975))

## Following example from the link above
set.seed(12345)
n <- 1000
U <- rnorm(n)
hist(U)
u <- 2 ## New proposed value
Ua <- c(U,u) ## Augmented set
hist(Ua)
abline(v=u)
print(round(mean(Ua > u), 3))
nEval <- 200
u.candidate <- seq(from=min(U), to=max(U), length = nEval)
Cbounds <- c(u.candidate[match(5, 
                                 apply(as.matrix(u.candidate),1,
                                 function(x){floor(2.5+100*(mean(c(U, x) < x)))}))],
                                 rev(u.candidate)[match(95, rev(apply(as.matrix(u.candidate),1,
                                 function(x){ceiling(-2.5+100*(mean(c(U, x) < x)))})))])
print(Cbounds)
hist(U)
abline(v = Cbounds)
## Alternatively
pdi.cb <- pred_int_conformal(U)

## From Shafer and Vovk (pg. 5)
## Numners generated by Emmanuel Czuber
xn <- c(17,20,10,17,12,15,19,22,17,19,14,22,18,17,13,12,18,15,17)
pdi.xn <- pred_int_conformal(xn, neval = 500)

## End(Not run)

femiguez/predintma documentation built on July 5, 2021, 4:16 a.m.