elo_model3: Get likelihood of elo-ratings

View source: R/elo_model3.R

elo_model3R Documentation

Get likelihood of elo-ratings

Description

This function calulates the log likelihood of the winning probability of winner, or generates an elo sequence.

Function taken from Foerster et al. 2016

Usage

elo_model3(par, IA_data, all_ids, return_likelihood = T)

Arguments

par

numeric vector of values. par[1] will be used as initial value of k. rest of vector will be used as starting elo values

IA_data

A data frame with sequencce of Winner/Loser interactions.

all_ids

A character vector os unique individual IDs

return_likelihood

If TRUE (default), returns a list with parameters estimated by maximum likelihood. If FALSE, returns a IA_data with updated elo scores given the k value and initial scores set with 'par'.

Value

A likelihood value or elo sequence

References

Foerster, S., Franz, M., Murray, C. M., Gilby, I. C., Feldblum, J. T., Walker, K. K., & Pusey, A. E. (2016). Chimpanzee females queue but males compete for social status. Scientific Reports, 6, 35404. https://doi.org/10.1038/srep35404

Examples


# Calculate maximum likelihood
res_m_model3 <- optim(par=c(5, rep(0, length(ama_c))), 
                      elo.model3, 
                      all_ids = ama_c, 
                      IA_data = dom.ama2, 
                      return_likelihood=T, 
                      method='BFGS', 
                      control = list(maxit = 10000, reltol=1e-10))
                      
# Get K
k <- exp(res_m_model3$par[1])
# Get AIC
AIC <- res_m_model3$value * 2 + 2 * (length(ama_c) + 1)

# Get elo sequence given ML k and starting values
ama_seq3.2 <- elo.model3(par = res_m_model3$par, 
                         IA_data = dom.ama2, 
                         all_ids = ama_c, 
                         return_likelihood = FALSE)

avrincon/phdfuns documentation built on Nov. 13, 2022, 10:34 a.m.