create_cp_dummies: Create Actor and Partner Dummy Matrices for the Co-Partner...

View source: R/create_cp_dummies.R

create_cp_dummiesR Documentation

Create Actor and Partner Dummy Matrices for the Co-Partner SRM

Description

Generates the actor and partner dummy matrices required by cpsrm_run. Unlike create_dummies, which produces dummies for the standard Social Relations Model, this function is designed for the Co-Partner SRM where each observation involves one actor and all other members of the group acting simultaneously as partners. Variable group sizes (2, 3, 4, or mixed) are fully supported.

Usage

create_cp_dummies(
  data,
  actor_id,
  group_id,
  weight_partners = TRUE,
  prefix_actor = "A",
  prefix_partner = "P"
)

Arguments

data

a data.frame in long format, with one row per person-group observation

actor_id

character; column name of the actor/person identifier

group_id

character; column name of the group identifier

weight_partners

logical; if TRUE (default), partner dummies are weighted by 1/(group\_size - 1), making \sigma_P^2 the variance of the average partner contribution. If FALSE, dummies are 0/1 and \sigma_P^2 is the variance of the sum of partner contributions. Weighting is recommended when group sizes vary, as it ensures comparability of \sigma_P^2 across group sizes

prefix_actor

character; prefix for actor dummy columns. Default "A"

prefix_partner

character; prefix for partner dummy columns. Default "P"

Value

a list with elements:

actor_mat

matrix of actor dummies (n x n_persons)

partner_mat

matrix of partner dummies, optionally weighted (n x n_persons)

actor_names

character vector of actor dummy column names

partner_names

character vector of partner dummy column names

group_sizes

integer vector of length n giving the group size for each observation; pass this to cpsrm_run() via the group_sizes argument

person_levels

character vector of person IDs (column order)

n_persons

integer; number of unique persons

n_groups

integer; number of unique groups

group_size_table

table of group size frequencies

See Also

cpsrm_run, create_dummies

Examples


# create_cp_dummies() expects one row per PERSON per GROUP, with every
# other group member treated as a simultaneous co-partner (e.g. one row
# per player per team, as in three-person golf teams). sampleDyadData is
# a round-robin/directed-dyad dataset (multiple rows per actor per
# group, one per rated partner) and is NOT the right shape for this
# function -- see create_dummies()/srm_run() for that design instead.
# This example simulates a small, correctly-shaped dataset: 30
# three-person teams drawn from a pool of 90 players.
set.seed(1)
team_dat <- do.call(rbind, lapply(1:30, function(g) {
  data.frame(player = sample(1:90, 3), team = g)
}))

dummies <- create_cp_dummies(
  data        = team_dat,
  actor_id    = "player",
  group_id    = "team"
)
cat("Persons:", dummies$n_persons, "\n")
cat("Groups:", dummies$n_groups, "\n")


roundRobinR documentation built on Sept. 18, 2026, 1:06 a.m.