Title: | Generate Simulated Data for Voting Rules using Evaluations |
---|---|
Description: | Provide functions to generate random simulated evaluations on candidates by voters for evaluation-based elections. Functions are based on several models for continuous or discrete evaluations. |
Authors: | Antoine Rolland [aut, cre], Nathan Grimault [aut] |
Maintainer: | Antoine Rolland <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2025-02-20 04:59:49 UTC |
Source: | https://github.com/cran/voteSim |
Distance formula
distance(votant, candidats)
distance(votant, candidats)
votant |
array |
candidats |
array |
distance
Distance formula
distance_to_pref(distance_matrix)
distance_to_pref(distance_matrix)
distance_matrix |
distance_matrix |
mat_inverse
Distance to score
DistToScores(dist, dim = 2, method = "linear", lambda = 5)
DistToScores(dist, dim = 2, method = "linear", lambda = 5)
dist |
int |
dim |
dimension int |
method |
method string |
lambda |
lambdad int |
score
Generates a simulation of voting according to a beta law, returns voters preferences
generate_beta( n_voters, n_candidates, beta_a = 0.5, beta_b = 0.5, lambda = 0, min = 0, max = 1 )
generate_beta( n_voters, n_candidates, beta_a = 0.5, beta_b = 0.5, lambda = 0, min = 0, max = 1 )
n_voters |
integer, represents the number of voters in the election |
n_candidates |
integer, represents the number of candidates in the election |
beta_a |
double, parameter of the Beta law (by default 0.5) |
beta_b |
double, parameter of the Beta law (by default 0.5) |
lambda |
double, alternative parameter of the Beta law |
min |
int, the minimum value of the range of possible scores (by default 0) |
max |
int, the maximum value of the range of possible scores (by default 1) |
scores
voting_situation<- generate_beta(n_voters=10, n_candidates=3, beta_a=1, beta_b=5)
voting_situation<- generate_beta(n_voters=10, n_candidates=3, beta_a=1, beta_b=5)
This function generates discrete scores following a beta-binomial distribution on a given scale
generate_beta_binomial( n_voters, n_candidates, min = 0, max = 10, alpha = 0.5, beta = 0.5 )
generate_beta_binomial( n_voters, n_candidates, min = 0, max = 10, alpha = 0.5, beta = 0.5 )
n_voters |
integer, the number of voters to generate scores for. |
n_candidates |
integer, The number of candidates to generate scores for. |
min |
The minimum value of the distribution, by default 0 |
max |
The maximum value of the distribution, by default 10 |
alpha |
The first parameter of the beta-binomial distribution, by default 0.5 |
beta |
The second parameter of the beta-binomial distribution, by default 0.5 |
A matrix of scores with 'n_candidates' rows and 'n_voters' columns.
voting_situation <- generate_beta_binomial(n_voters=10, n_candidates=3, max=7)
voting_situation <- generate_beta_binomial(n_voters=10, n_candidates=3, max=7)
This function generates discrete scores following a binomial distribution on a given scale
generate_binomial(n_voters, n_candidates, min = 0, max = 10, mean = 5)
generate_binomial(n_voters, n_candidates, min = 0, max = 10, mean = 5)
n_voters |
integer, the number of voters to generate scores for. |
n_candidates |
integer, The number of candidates to generate scores for. |
min |
The minimum value of the distribution, by default 0 |
max |
The maximum value of the distribution, by default 10 |
mean |
The mean value of the distribution, by default 5 |
A matrix of scores with 'n_candidates' rows and 'n_voters' columns.
voting_situation <- generate_binomial(n_voters=10, n_candidates=3, min=0, max=7, mean=5)
voting_situation <- generate_binomial(n_voters=10, n_candidates=3, min=0, max=7, mean=5)
This function generates scores following a Dirichlet distribution
generate_dirichlet(n_voters, n_candidates, probs = 0)
generate_dirichlet(n_voters, n_candidates, probs = 0)
n_voters |
integer, the number of voters to generate scores for. |
n_candidates |
integer, The number of candidates to generate scores for. |
probs |
A vector of size n_candidates corresponding to the parameters of the Dirichlet distribution. By default all values are equal to 1. |
A matrix of scores with 'n_candidates' rows and 'n_voters' columns.
voting_situation <- generate_dirichlet(n_voters=10, n_candidates=3, probs=c(0.5, 0.3, 0.2))
voting_situation <- generate_dirichlet(n_voters=10, n_candidates=3, probs=c(0.5, 0.3, 0.2))
This function generates discrete scores following marginals distributions linked by a copula #'
generate_discrete_copula_based( n_voters, n_candidates, min = 0, max = 10, margins = list("default"), cor_mat = 0 )
generate_discrete_copula_based( n_voters, n_candidates, min = 0, max = 10, margins = list("default"), cor_mat = 0 )
n_voters |
integer, the number of voters to generate scores for. |
n_candidates |
integer, The number of candidates to generate scores for. |
min |
The minimum value of the distribution, by default 0 |
max |
The maximum value of the distribution, by default 10 |
margins |
A list of n_candidates cumulative distribution vectors of length (max-min-1) : the last value of the cumulative distribution, 1, should be omitted. By default margin distribution are uniform distributions. |
cor_mat |
A matrix of correlation coefficients between the n_candidates distributions. By default all correlation coefficients are set up alternatively to 0.5 or -0.5. |
A matrix of scores with 'n_candidates' rows and 'n_voters' columns.
# Example for 3 candidates, binomial distributions min=0 max=7 n_candidates<-3 distribution<-dbinom(x=(min:max), size=max, prob=0.7) distribution_cumul<-cumsum(distribution) distribution_cumul<-distribution_cumul[-length(distribution_cumul)] margins <- matrix(rep(distribution_cumul, n_candidates), ncol=n_candidates) margins <-as.list(as.data.frame(margins)) cor_mat<-matrix(c(1,0.8,0,0.8,1,0, 0,0,1), ncol=n_candidates) voting_situation <- generate_discrete_copula_based(10, 3, max=max, margins=margins, cor_mat=cor_mat)
# Example for 3 candidates, binomial distributions min=0 max=7 n_candidates<-3 distribution<-dbinom(x=(min:max), size=max, prob=0.7) distribution_cumul<-cumsum(distribution) distribution_cumul<-distribution_cumul[-length(distribution_cumul)] margins <- matrix(rep(distribution_cumul, n_candidates), ncol=n_candidates) margins <-as.list(as.data.frame(margins)) cor_mat<-matrix(c(1,0.8,0,0.8,1,0, 0,0,1), ncol=n_candidates) voting_situation <- generate_discrete_copula_based(10, 3, max=max, margins=margins, cor_mat=cor_mat)
This function generates discrete scores following a multinomial distribution on a given scale
generate_multinom(n_voters, n_candidates, max = 10, probs = 0)
generate_multinom(n_voters, n_candidates, max = 10, probs = 0)
n_voters |
integer, the number of voters to generate scores for. |
n_candidates |
integer, The number of candidates to generate scores for. |
max |
The maximum value of the distribution, by default 10. It also corresponds to the sum of scores on all the candidates |
probs |
A vector of size n_candidates corresponding to the parameters of the multinomial distribution. By default all values are equal to 1/n_candidates |
A matrix of scores with 'n_candidates' rows and 'n_voters' columns.
voting_situation <- generate_multinom(n_voters=10, n_candidates=3, max=100, probs=c(0.5, 0.3, 0.2))
voting_situation <- generate_multinom(n_voters=10, n_candidates=3, max=100, probs=c(0.5, 0.3, 0.2))
This function generates truncated normal scores using the 'rtruncnorm' function from the 'truncnorm' package.
generate_norm(n_voters, n_candidates, min = 0, max = 1, mean = 0.5, sd = 0.25)
generate_norm(n_voters, n_candidates, min = 0, max = 1, mean = 0.5, sd = 0.25)
n_voters |
The number of voters to generate scores for. |
n_candidates |
The number of candidates to generate scores for. |
min |
The minimum value of the truncated normal distribution. |
max |
The maximum value of the truncated normal distribution. |
mean |
The mean of the truncated normal distribution. |
sd |
The standard deviation of the truncated normal distribution. |
A matrix of scores with 'n_candidates' rows and 'n_voters' columns.
voting_situation<- generate_norm(n_voters=10, n_candidates=3, min=0, max=10, mean=0.7)
voting_situation<- generate_norm(n_voters=10, n_candidates=3, min=0, max=10, mean=0.7)
This function generates spatial data consisting of n_voters
voters and n_candidates
candidates. The spatial model is created by placing the candidates on a 2-dimensional plane according to the placement
parameter, and then computing a distance matrix between voters and candidates. The distances are then transformed into scores using the score_method
parameter. Finally, a plot of the candidates and voters is produced.
generate_spatial( n_voters, n_candidates, placement = "uniform", score_method = "linear", dim = 2 )
generate_spatial( n_voters, n_candidates, placement = "uniform", score_method = "linear", dim = 2 )
n_voters |
The number of voters. |
n_candidates |
The number of candidates. |
placement |
The method used to place the candidates on the 2-dimensional plane. Must be either "uniform" or "beta". Default is "uniform". |
score_method |
The method used to transform distances into scores. Must be either "linear" or "sigmoide". Default is "linear". |
dim |
The dimension of the latent space (by default dim =2) |
A matrix of scores.
generate_spatial(n_candidates = 5,n_voters = 100, placement = "uniform", score_method = "linear")
generate_spatial(n_candidates = 5,n_voters = 100, placement = "uniform", score_method = "linear")
Generates a simulation of voting according to a uniform law, returns voters preferences
generate_unif_continuous(n_voters, n_candidates, min = 0, max = 1)
generate_unif_continuous(n_voters, n_candidates, min = 0, max = 1)
n_voters |
integer, represents the number of voters in the election |
n_candidates |
integer, represents the number of candidates in the election |
min |
int, the minimum value of the range of possible scores (by default 0) |
max |
int, the maximum value of the range of possible scores (by default 1) |
scores
voting_situation<- generate_unif_continuous(n_voters=10, n_candidates=3, min=0, max=10)
voting_situation<- generate_unif_continuous(n_voters=10, n_candidates=3, min=0, max=10)
This function generates uniform discrete scores on a given scale
generate_unif_disc(n_voters, n_candidates, min = 0, max = 10)
generate_unif_disc(n_voters, n_candidates, min = 0, max = 10)
n_voters |
integer, the number of voters to generate scores for. |
n_candidates |
integer, The number of candidates to generate scores for. |
min |
The minimum value of the distribution, by default 0 |
max |
The maximum value of the distribution, by default 10 |
A matrix of scores with 'n_candidates' rows and 'n_voters' columns.
voting_situation <- generate_unif_disc(n_voters=10, n_candidates=3, min=0, max=5)
voting_situation <- generate_unif_disc(n_voters=10, n_candidates=3, min=0, max=5)
Generalized inverse of the empirical cumulative function.
icdf(u, x, n)
icdf(u, x, n)
u |
a numeric vector of quantiles to be transformed. |
x |
a numeric vector of data values. |
n |
a positive integer specifying the length of the output vector. |
Computes the generalized inverse of the empirical cumulative function,
which transforms quantiles u
to the corresponding values of x
based on
the frequency distribution of x
.
a numeric vector of transformed quantiles.
Preferences_to_ranks
preferences_to_ranks(preferences)
preferences_to_ranks(preferences)
preferences |
voters preferences |
ranks
Rename_rows
rename_rows(preferences)
rename_rows(preferences)
preferences |
voters preferences |
preferences
Score to distance
ScoresToDist(x, dim = 2, method = "linear")
ScoresToDist(x, dim = 2, method = "linear")
x |
score |
dim |
dimension int |
method |
method string |
distance