Covariance matrix for preferences, calculated using the rankings matrix.
Source:R/pref_summaries.R
pref_cov.Rd
Covariance matrix for preferences, calculated using the rankings matrix.
Arguments
- x
A vector of preferences, or a tibble with a column of preferences.
- preferences_col
<
tidy-select
> Whenx
is atibble
, the column containing the preferences.- frequency_col
<
tidy-select
> Whenx
is atibble
, the column containing the frequency of the preferences. If not provided, each row is considered to be observed a single time.- ...
Extra arguments to be passed to
stats::cov.wt
.
Examples
# Simple covariance on a vector of preferences
prefs <- preferences(c("a > b > c", "b > c > a", "c > a > b"))
pref_cov(prefs)
#> $cov
#> a b c
#> a 1.0 -0.5 -0.5
#> b -0.5 1.0 -0.5
#> c -0.5 -0.5 1.0
#>
#> $center
#> a b c
#> 2 2 2
#>
#> $n.obs
#> [1] 3
#>
# Weighted covariance by frequency
df <- tibble::tibble(
prefs = preferences(c("a > b > c", "b > c > a")),
freq = c(3, 2)
)
pref_cov(df, preferences_col = prefs, frequency_col = freq)
#> $cov
#> a b c
#> a 1.2 -0.6 -0.6
#> b -0.6 0.3 0.3
#> c -0.6 0.3 0.3
#>
#> $center
#> a b c
#> 1.8 1.6 2.6
#>
#> $n.obs
#> [1] 5
#>