knitr::opts_chunk$set(echo = TRUE)
knitr::include_graphics(system.file("help/figures/hyper2.png", package = "hyper2"))

To cite the hyper2 package in publications please use @hankin2017_rmd. Here I show how to use the excellent Ternary package [@smith2017] to generate triangular plots for hyper2 likelihood functions with size 3. First load the Ternary and hyper2 packages:

library("hyper2")
library("Ternary")

The chess dataset

Now generate a synthetic dataset. Here we will sample from the posterior of a uniform prior with a likelihood function specified by the chess object (this takes quite a long time):

set.seed(0)
xx <- rp(1000,chess)

Using the TernaryPlot() and TernaryPoints() functions is straightforward:

jj <- pnames(chess)
TernaryPlot(atip=jj[1],btip=jj[2],ctip=jj[3])
TernaryPoints(xx,cex=0.5)
TernaryPoints(chess_maxp,pch=16,col="red")

Above we see black circles being samples from the posterior and the red point is the maximum likelihood estimate for the three players' strengths. We can adapt this technique to higher-dimensional hyper2 objects.

The icons dataset

Consider the icons likelihood function:

icons

We can sample from this object and plot it in different ways:

n <- 10000
x <- rp(n,icons)
x[sample(n,5),]
matplot(x,type="l",lty=1)
legend("topright",col=1:6,lty=1,legend=pnames(icons))
wanted <- c(1,3) # NB,PB
xx <- cbind(x[,wanted],fillup=rowSums(x[,-wanted]))
TernaryPlot(atip="NB",btip="PB",ctip="other")
TernaryPoints(xx,cex=0.5)


RobinHankin/hyper2 documentation built on April 21, 2024, 11:38 a.m.