confpred: Conformal prediction

Description Usage Arguments Value Examples

View source: R/confpred.R

Description

Conformal predicions

Usage

1
confpred(object, data, newdata = data, alpha = 0.05, mad, ...)

Arguments

object

Model object (lm, glm or similar with predict method) or formula (lm)

data

data.frame

newdata

New data.frame to make predictions for

alpha

Level of prediction interval

mad

Conditional model (formula) for the MAD (locally-weighted CP)

...

Additional arguments to lower level functions

Value

data.frame with fitted (fit), lower (lwr) and upper (upr) predictions bands.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
set.seed(123)
n <- 200
x <- seq(0,6,length.out=n)
delta <- 3
ss <- exp(-1+1.5*cos((x-delta)))
ee <- rnorm(n,sd=ss)
y <- (x-delta)+3*cos(x+4.5-delta)+ee
d <- data.frame(y=y,x=x)

newd <- data.frame(x=seq(0,6,length.out=50))
cc <- confpred(lm(y~splines::ns(x,knots=c(1,3,5)),data=d), data=d, newdata=newd)
if (interactive()) {
plot(y~x,pch=16,col=lava::Col("black"),ylim=c(-10,10),xlab="X",ylab="Y")
with(cc,
     lava::confband(newd$x,lwr,upr,fit,
        lwd=3,polygon=TRUE,col=Col("blue"),border=FALSE))
}

kkholst/lava documentation built on Sept. 21, 2020, 7:29 a.m.