---
title: "Creating `hyper3` objects in the `hyper2` package"
author: "Robin K. S. Hankin"
output: html_vignette
bibliography: hyper2.bib
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{hyper3 creation methods}
  %\usepackage[utf8]{inputenc}
---

```{r setup, include=FALSE}
set.seed(0)
library("hyper2")
library("magrittr")
options(rmarkdown.html_vignette.check_title = FALSE)
knitr::opts_chunk$set(echo = TRUE)
knit_print.function <- function(x, ...){dput(x)}
registerS3method(
  "knit_print", "function", knit_print.function,
  envir = asNamespace("knitr")
)
```

```{r out.width='20%', out.extra='style="float:right; padding:10px"',echo=FALSE}
knitr::include_graphics(system.file("help/figures/hyper2.png", package = "hyper2"))
```

To cite the `hyper2` package in publications, please use
@hankin2017_rmd.  In this vignette I give self-contained short
examples of each function that creates or modifies `hyper3` objects.


```{r hyper3_default}
hyper3() # default creation, returns a uniform support function
```

---


```{r hyper3_1}
hyper3(list(c(a=1.2),c(b=1),c(a=1.2,b=1)),powers=c(3,4,-7)) # dispatches to hyper3_nv()
```

---

```{r hyper3_2}
hyper3(B=list("a",c("a","b"),"b"),W=list(1.2,c(1.2,1),1),powers=c(3,4,-7)) # dispatches to hyper3_bw()
```

---

```{r hyper3_3}
M <- matrix(rpois(15,3),5,3)
colnames(M) <- letters[1:3]
M
hyper3(M,c(2,3,-1,-5,1))   # dispatches to hyper3_m()
```
---

```{r hyper3_add_terms}
H <- hyper3()
H[c(p1=1.3)] <- 5  # terms not present are created
H[c(p2=1  )] <- 2
H[c(p1=1.3,p2=1)] <- -7
H
```
---


```{r hyper3_extract}
H <- hyper3(list(c(a=1.2),c(b=1),c(a=1.2,b=1)),powers=c(3,4,-7))
H[c(a=1.2)] <- 100  # terms present may be modified...
H[c(a=1.2,x=1)] %<>% dec(97) # or incremented
H
```
---

```{r hyper3_ordervec2supp3}
ordervec2supp3(c("a","a","b","c","a","b","c"))
```
---

```{r hyper3_ordervec2supp3nonfinishers}
ordervec2supp3(c("a","b"),nonfinishers=c("a","b"))  # a > b >> {a,b}
```
---

```{r hyper3_attemptstable2supp3}
(jj <- data.frame(throw1=c(a=8,b=2,c=1),throw2=c(5,"X",3)))
attemptstable2supp3(jj)
```
---

```{r hyper3_dirichlet3}
dirichlet3(c(x=6,y=2,z=2),lambda=1.8)  
```
---


```{r hyper3_modifyweight}
(H <- rankvec_likelihood(letters[1:5]))
H["b"] <- as.weight(1.88)
H
setweight(H,"c",1000)
```
---

```{r hyper3_ordertable2supp3}
(o <- constructor_2020_table[1:6,1:4])
ordertable2supp3(o)
```
---

```{r hyper3_home_away3}
M <- matrix(c(NA,9+2i,7+2i,6+5i,NA,2+4i,2+2i,9+3i,NA),3,3)
teams <- letters[1:3]
dimnames(M) <- list("@home" = teams,"@away"=teams)
M
home_away3(M,lambda=1.88)
```
---

```{r hyper3_powersbecomes}
(H <- hyper3(list(c(a=1.2),c(b=1),c(a=1.2,b=1)),powers=c(3,4,-7)))
powers(H) <- powers(H) * 3
H
```





## References

.
