---
title: "Javelins with hyper3 objects"
author: "Robin KS Hankin"
date: "10/04/2022"
output: html_document
---

```{r setup, include=FALSE}
set.seed(1)
knitr::opts_chunk$set(echo = TRUE)
library("hyper2")
library("disordR")
```

<p style="text-align: right;">
![](`r system.file("help/figures/hyper2.png", package = "hyper2")`){width=10%}
</p>


We analyse results from the men's javelin, 2020 Summer Olympics.

```{r,label=loadjavelinandconvert}
javelin_table <- read.table("javelin.txt",header=TRUE)
a <- javelin_table # saves typing
javelin_table
```

Above, we see that Chopra threw 87.03m on his first throw, 87.58m on
his second, and so on.  Vadlejch threw 83.98m on his first throw, etc.
We may convert this to a named vector with elements being the throw
distances, and names being the competitors, using
`attemptstable2supp3()`:

```{r,label=converttosupp3,cache=TRUE}
javelin_vector <- attemptstable2supp3(a,decreasing=TRUE,give.supp=FALSE)
javelin_vector
o <- javelin_vector # saves typing
```

Above we see that Chopra threw the longest and second-longest throws
of 87.58m and 87.03 respectively; Vadlejch threw the third-longest
throw of 86.67m, and so on.  `NA` entries correspond to no-throws.  It
is easy to plot the data in visual form:

```{r, label=plotjav}
n <- length(levels(as.factor(names(o))))
plot(o,pch=16,col=rainbow(n)[as.factor(names(o))])
legend("topright",pch=16,col=rainbow(n),legend=levels(as.factor(names(o))))
```

Now convert the attempts table to a `hyper3` object, again using
function `attemptstable2supp3()` but this time pass `give.supp=TRUE`.
However, note that there are two reasonable interpretations: firstly,
we simply ignore no-throws [in the package docs, these are sometimes
referred to as "DNF", or "Did not finish", following Formula 1
terminology]:

```{r,label=dothething2,cache=TRUE}    	   
javelin1 <- ordervec2supp3(v=names(o)[!is.na(o)])
H1 <- javelin1 # saves typing
javelin1_maxp  <- maxp(H1)
m1 <- javelin1_maxp
```

Secondly, we may treat no-throws as being inferior to any actual
measured throw.  To do this it is easiest to pass `give.supp=TRUE` to
`attemptstable2supp3()`:

```{r,label=dothething1,cache=TRUE}    	   
javelin2 <- attemptstable2supp3(a,decreasing=TRUE,give.supp=TRUE)
H2 <- javelin2 # saves typing
javelin2_maxp <- maxp(H2)
m2 <- javelin2_maxp
```

Investigation:

```{r,plotm}
rbind(one=m1,two=m2)
pie(m1)
pie(m2)
dotchart(m1,pch=16)
dotchart(m2,pch=16)
abline(0,1)
ordertransplot(m1,m2)
```

```{r,dothetests,cache=TRUE}
equalp.test(javelin1)
equalp.test(javelin2)
```


Reference

`https://en.wikipedia.org/w/index.php?title=Athletics_at_the_2020_Summer_Olympics_%E2%80%93_Men%27s_javelin_throw&oldid=1051014985`



### Package dataset {-}

Following lines create `javelin.rda`, residing in the `data/`
directory of the package.

```{r,label=savejavelindataset}
save(javelin1,javelin2,javelin_table,javelin_vector,javelin1_maxp,javelin2_maxp,  file="javelin.rda")
```

