R/z_helpers.R

Defines functions n_moves make_tempelo

# this is a collection of smaller helper files that are of no immediate value to
# the user

# create the tempelo object in elo.seq
make_tempelo <- function(winner, loser, pmat, allids, startvalue) {
  # first interaction
  first_ia <- sapply(allids, function(x) min(which(winner == x | loser == x)))
  # first presence
  first_pres <- apply(pmat[, allids], 2, function(x)min(which(x == 1)))
  # combine
  res <- rbind(startvalue, NA, first_ia, first_pres)
  rownames(res) <- c("recelo", "present", "firstIA", "firstpres")
  res["recelo", which(pmat[1, allids] == 0)] <- NA

  # reorder
  res <- res[, names(sort(res[3, ], na.last = TRUE))]
  res <- res[, names(sort(res[4, ], na.last = TRUE))]

  res
}

# check whether presence data has individuals that both join and leave or
# leave and join
# i.e. have more than one movement in/out the group
n_moves <- function(presence) {
  presence <- presence[, -c(which(colnames(presence) %in% c("Date", "date")))]
  colSums(apply(presence, 2, function(x) diff(x) != 0))
}
gobbios/EloRating documentation built on June 4, 2023, 6:33 a.m.