fitted.btfit returns the fitted values from a fitted btfit model object.

# S3 method for btfit
fitted(object, subset = NULL, as_df = FALSE, ...)

## Details

Consider a set of $$K$$ items. Let the items be nodes in a graph and let there be a directed edge $$(i, j)$$ when $$i$$ has won against $$j$$ at least once. We call this the comparison graph of the data, and denote it by $$G_W$$. Assuming that $$G_W$$ is fully connected, the Bradley-Terry model states that the probability that item $$i$$ beats item $$j$$ is $$p_{ij} = \frac{\pi_i}{\pi_i + \pi_j},$$ where $$\pi_i$$ and $$\pi_j$$ are positive-valued parameters representing the skills of items $$i$$ and $$j$$, for $$1 \le i, j, \le K$$.

The expected, or fitted, values under the Bradley-Terry model are therefore: $$m_{ij} = n_{ij}p_{ij},$$

where $$n_{ij}$$ is the number of comparisons between item $$i$$ and item $$j$$.

If there are values on the diagonal in the original btdata$wins matrix, then these appear as the values on the diagonal of the fitted matrix. These values do not appear in the data frame if the as_df argument is set to TRUE. The function btfit is used to fit the Bradley-Terry model. It produces a "btfit" object that can then be passed to fitted.btfit to obtain the fitted values $$m_{ij}$$. Note that the Bradley-Terry probabilities $$p_{ij}$$ can be calculated using btprob. If $$G_W$$ is not fully connected, then a penalised strength parameter can be obtained using the method of Caron and Doucet (2012) (see btfit, with a > 1), which allows for a Bradley-Terry probability of any of the $$K$$ items beating any of the others. Alternatively, the MLE can be found for each fully-connected component of $$G_W$$ (see btfit, with a = 1), and the probability of each item in each component beating any other item in that component can be found. Bradley, R. A. and Terry, M. E. (1952). Rank analysis of incomplete block designs: 1. The method of paired comparisons. Biometrika, 39(3/4), 324-345. Caron, F. and Doucet, A. (2012). Efficient Bayesian Inference for Generalized Bradley-Terry Models. Journal of Computational and Graphical Statistics, 21(1), 174-196. ## See also btfit, btprob, btdata ## Examples citations_btdata <- btdata(BradleyTerryScalable::citations) fit1 <- btfit(citations_btdata, 1) fitted(fit1)#> 4 x 4 sparse Matrix of class "dgCMatrix" #> citing #> cited JRSS-B Biometrika JASA Comm Statist #> JRSS-B 188.00000 286.4629 317.26219 281.7444 #> Biometrika 218.53715 714.0000 505.35443 725.0322 #> JASA 149.73781 312.6456 1072.00000 812.2472 #> Comm Statist 11.25564 37.9678 68.75276 425.0000fitted(fit1, as_df = TRUE)#> # A tibble: 6 x 5 #> component cited citing fit1 fit2 #> <chr> <chr> <chr> <dbl> <dbl> #> 1 full_dataset JRSS-B Biometrika 286.4629 218.53715 #> 2 full_dataset JRSS-B JASA 317.2622 149.73781 #> 3 full_dataset Biometrika JASA 505.3544 312.64557 #> 4 full_dataset JRSS-B Comm Statist 281.7444 11.25564 #> 5 full_dataset Biometrika Comm Statist 725.0322 37.96780 #> 6 full_dataset JASA Comm Statist 812.2472 68.75276toy_df_4col <- codes_to_counts(BradleyTerryScalable::toy_data, c("W1", "W2", "D")) toy_btdata <- btdata(toy_df_4col) fit2a <- btfit(toy_btdata, 1) fitted(fit2a)#>$2
#> 3 x 3 sparse Matrix of class "dgCMatrix"
#>        player2
#> player1       Han       Gal       Fin
#>     Han .         1.1406148 0.8586132
#>     Gal 0.8593852 .         1.6412871
#>     Fin 0.1413868 0.3587129 .
#>
#> $3 #> 4 x 4 sparse Matrix of class "dgCMatrix" #> player2 #> player1 Cyd Amy Ben Dan #> Cyd . 1.2728582 . 0.7259617 #> Amy 0.7271418 . 0.5684605 1.2042516 #> Ben . 0.4315395 . 1.0692677 #> Dan 0.2740383 0.7957484 0.9307323 . #> fitted(fit2a, as_df = TRUE)#> # A tibble: 8 x 5 #> component player1 player2 fit1 fit2 #> <chr> <chr> <chr> <dbl> <dbl> #> 1 2 Han Gal 1.1406148 0.8593852 #> 2 2 Han Fin 0.8586132 0.1413868 #> 3 2 Gal Fin 1.6412871 0.3587129 #> 4 3 Cyd Amy 1.2728582 0.7271418 #> 5 3 Amy Ben 0.5684605 0.4315395 #> 6 3 Cyd Dan 0.7259617 0.2740383 #> 7 3 Amy Dan 1.2042516 0.7957484 #> 8 3 Ben Dan 1.0692677 0.9307323fitted(fit2a, subset = function(x) "Amy" %in% names(x))#>$3
#> 4 x 4 sparse Matrix of class "dgCMatrix"
#>        player2
#> player1       Cyd       Amy       Ben       Dan
#>     Cyd .         1.2728582 .         0.7259617
#>     Amy 0.7271418 .         0.5684605 1.2042516
#>     Ben .         0.4315395 .         1.0692677
#>     Dan 0.2740383 0.7957484 0.9307323 .
#> fit2b <- btfit(toy_btdata, 1.1)
fitted(fit2b, as_df = TRUE)#> # A tibble: 12 x 5
#>       component player1 player2      fit1       fit2
#>           <chr>   <chr>   <chr>     <dbl>      <dbl>
#>  1 full_dataset     Cyd     Amy 1.2677729 0.73222715
#>  2 full_dataset     Eve     Gal 0.8811003 0.11889971
#>  3 full_dataset     Han     Gal 1.1718336 0.82816645
#>  4 full_dataset     Eve     Ben 0.9108535 0.08914648
#>  5 full_dataset     Amy     Ben 0.5857476 0.41425236
#>  6 full_dataset     Eve     Dan 0.9196439 0.08035613
#>  7 full_dataset     Cyd     Dan 0.7327768 0.26722321
#>  8 full_dataset     Amy     Dan 1.2259480 0.77405202
#>  9 full_dataset     Ben     Dan 1.0566477 0.94335225
#> 10 full_dataset     Eve     Fin 0.9671479 0.03285215
#> 11 full_dataset     Han     Fin 0.8489711 0.15102890
#> 12 full_dataset     Gal     Fin 1.5978031 0.40219689