File: confpred.Rd

package info (click to toggle)
r-cran-lava 1.8.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,816 kB
  • sloc: sh: 13; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,302 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/confpred.R
\name{confpred}
\alias{confpred}
\title{Conformal prediction}
\usage{
confpred(object, data, newdata = data, alpha = 0.05, mad, ...)
}
\arguments{
\item{object}{Model object (lm, glm or similar with predict method) or formula (lm)}

\item{data}{data.frame}

\item{newdata}{New data.frame to make predictions for}

\item{alpha}{Level of prediction interval}

\item{mad}{Conditional model (formula) for the MAD (locally-weighted CP)}

\item{...}{Additional arguments to lower level functions}
}
\value{
data.frame with fitted (fit), lower (lwr) and upper (upr) predictions bands.
}
\description{
Conformal predicions using locally weighted conformal inference with a split-conformal algorithm
}
\examples{
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))
}
}