## ----echo=FALSE, message=FALSE------------------------------------------------
knitr::opts_chunk$set(global.par=TRUE, collapse=TRUE, comment="#>", fig.width=5, fig.height=5, fig.align="center", dpi=96)
options(tibble.print_min=4L, tibble.print_max=4L)

## -----------------------------------------------------------------------------
library(prim)
data(Boston, package="MASS")
x <- Boston[,5:6]
y <- Boston[,1]
boston.prim <- prim.box(x=x, y=y, threshold.type=1)

## -----------------------------------------------------------------------------
summary(boston.prim, print.box=TRUE)

## ----fig.asp=1----------------------------------------------------------------
plot(boston.prim, col="transparent")
points(x[y>3.5,])

## -----------------------------------------------------------------------------
boston.prim.med <- prim.box(x=x, y=y, threshold.type=1, y.fun=median)

## ----fig.asp=1----------------------------------------------------------------
plot(boston.prim, col="transparent")
plot(boston.prim.med, col="transparent", border="red", add=TRUE)
legend("topleft", legend=c("mean", "median"), col=1:2, lty=1, bty="n")

## ----fig.asp=1----------------------------------------------------------------
x2 <- Boston[,c(5,9)]  
y <- Boston[,1]  
boston.cat.prim <- prim.box(x=x2, y=y, threshold.type=1)
summary(boston.cat.prim, print.box=TRUE)
plot(boston.cat.prim, col="transparent")
points(x2[y>3.5,])

## -----------------------------------------------------------------------------
library(prim)
data(quasiflow)
yflow <- quasiflow[,4]
xflow <- quasiflow[,1:3]
xflowp <- quasiflow[yflow==1,1:3]
xflown <- quasiflow[yflow==-1,1:3]

## -----------------------------------------------------------------------------
pairs(xflowp, cex=0.5, pch=16, col=grey(0,0.1), xlim=c(0,1), ylim=c(0,1))
pairs(xflown, cex=0.5, pch=16, col=grey(0,0.1), xlim=c(0,1), ylim=c(0,1))

## -----------------------------------------------------------------------------
qflow.hdr.pos <- prim.box(x=xflow, y=yflow, threshold=0.38, threshold.type=1)
summary(qflow.hdr.pos)

## -----------------------------------------------------------------------------
qflow.neg <- prim.box(x=xflow, y=yflow, threshold.type=-1)
qflow.hdr.neg1 <- prim.hdr(qflow.neg, threshold=-0.23, threshold.type=-1)
qflow.hdr.neg2 <- prim.hdr(qflow.neg, threshold=-0.43, threshold.type=-1)
qflow.hdr.neg3 <- prim.hdr(qflow.neg, threshold=-0.63, threshold.type=-1)

## -----------------------------------------------------------------------------
summary(qflow.hdr.neg1)

## -----------------------------------------------------------------------------
qflow.prim2 <- prim.combine(qflow.hdr.pos, qflow.hdr.neg1)
summary(qflow.prim2)

## ----fig.asp=1, fig.height=10-------------------------------------------------
plot(qflow.prim2, x.pt=xflow, pch=16, cex=0.5, alpha=0.1)

## ----fig.asp=1, fig.height=10-------------------------------------------------
plot(qflow.prim2, x.pt=xflow, pch=16, cex=0.5, alpha=0.1, splom=FALSE, colkey=FALSE, ticktype="detailed")

