## Example 1. Partition function of the uniform (null) model, coinciding with n!.
partition_fun_spear(theta = 0, n_items = 10, log = FALSE)
factorial(10)
## Example 2. Partition function of the Mallows model with Spearman distance.
partition_fun_spear(theta = 0.5, n_items = 10, log = FALSE)
## Example 3. Log-partition function of the Mallows model with Spearman distance
## as a function of theta.
partition_fun_spear_vec <- Vectorize(partition_fun_spear, vectorize.args = "theta")
curve(partition_fun_spear_vec(x, n_items = 10), from = 0, to = 0.1, lwd = 2,
xlab = expression(theta), ylab = expression(log(Z(theta))),
main = "Log-partition function of the Mallows model with Spearman distance",
ylim = c(7, log(factorial(10))))
## Example 4. Log-partition function of the Mallows model with Spearman distance
## for varying number of items and values of the concentration parameter.
partition_fun_spear_vec <- Vectorize(partition_fun_spear, vectorize.args = "theta")
curve(partition_fun_spear_vec(x, n_items = 10),
from = 0, to = 0.1, lwd = 2, col = 2,
xlab = expression(theta), ylab = expression(log(Z(theta))),
main = "Log-partition function of the Mallows model with Spearman distance",
ylim = c(0, log(factorial(30))))
curve(partition_fun_spear_vec(x, n_items = 20), add = TRUE, col = 3, lwd = 2)
curve(partition_fun_spear_vec(x, n_items = 30), add = TRUE, col = 4, lwd = 2)
legend("topright", legend = c(expression(n == 10), expression(n == 20), expression(n == 30)),
col = 2:4, lwd = 2, bty = "n")
Run the code above in your browser using DataLab