```
library("topmodels")
## load packages
library("topmodels")
library("distributions3")
## Poisson regression model for FIFA 2018 data:
## number of goals scored by each team in each game, explained by
## predicted ability difference of the competing teams
data("FIFA2018", package = "distributions3")
m <- glm(goals ~ difference, data = FIFA2018, family = poisson)
## predicted probability distributions for all matches (in sample)
head(procast(m))
```

```
distribution
1 Poisson(lambda = 1.7680273)
2 Poisson(lambda = 0.8655224)
3 Poisson(lambda = 1.0296663)
4 Poisson(lambda = 1.4861779)
5 Poisson(lambda = 1.4353952)
6 Poisson(lambda = 1.0660948)
```

```
1 2
"Poisson(lambda = 1.7680)" "Poisson(lambda = 0.8655)"
3 4
"Poisson(lambda = 1.0297)" "Poisson(lambda = 1.4862)"
5 6
"Poisson(lambda = 1.4354)" "Poisson(lambda = 1.0661)"
```

```
## procasts for new data
## much lower, equal, and much higher ability than opponent
nd <- data.frame(difference = c(-1, 0, 1))
## predicted goal distribution object
goals <- procast(m, newdata = nd, drop = TRUE)
goals
```

```
1 2
"Poisson(lambda = 0.8181)" "Poisson(lambda = 1.2370)"
3
"Poisson(lambda = 1.8704)"
```

```
## predicted densities/probabilities for scoring 0, 1, ..., 5 goals
procast(m, newdata = nd, type = "density", at = 0:5)
```

```
d_0 d_1 d_2 d_3 d_4 d_5
1 0.4412492 0.3610060 0.1476777 0.04027394 0.008237485 0.001347892
2 0.2902421 0.3590411 0.2220740 0.09157147 0.028319386 0.007006441
3 0.1540605 0.2881563 0.2694852 0.16801593 0.078564672 0.029389630
```

```
## by hand
pdf(goals, 0:5)
```

```
d_0 d_1 d_2 d_3 d_4 d_5
1 0.4412492 0.3610060 0.1476777 0.04027394 0.008237485 0.001347892
2 0.2902421 0.3590411 0.2220740 0.09157147 0.028319386 0.007006441
3 0.1540605 0.2881563 0.2694852 0.16801593 0.078564672 0.029389630
```

```
## means and medians
procast(m, newdata = nd, type = "mean")
```

```
mean
1 0.8181454
2 1.2370397
3 1.8704100
```

`procast(m, newdata = nd, type = "quantile", at = 0.5)`

```
quantile
1 1
2 1
3 2
```

```
## by hand
mean(goals)
```

```
1 2 3
0.8181454 1.2370397 1.8704100
```

`quantile(goals, 0.5)`

```
1 2 3
1 1 2
```

```
## evaluate procast elementwise or for all possible combinations
## of distributions from 'nd' and observations in 'at'
procast(m, newdata = nd, type = "probability", at = 1:3, elementwise = TRUE)
```

```
probability
1 0.8022553
2 0.8713572
3 0.8797179
```

`procast(m, newdata = nd, type = "probability", at = 1:3, elementwise = FALSE)`

```
p_1 p_2 p_3
1 0.8022553 0.9499330 0.9902069
2 0.6492832 0.8713572 0.9629287
3 0.4422167 0.7117019 0.8797179
```

```
## compute in-sample log-likelihood sum via procast
sum(procast(m, type = "density", at = FIFA2018$goals, log = TRUE))
```

`[1] -177.6971`

`logLik(m)`

`'log Lik.' -177.6971 (df=2)`