View source: R/create_cp_dummies.R
| create_cp_dummies | R Documentation |
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.
create_cp_dummies(
data,
actor_id,
group_id,
weight_partners = TRUE,
prefix_actor = "A",
prefix_partner = "P"
)
data |
a |
actor_id |
character; column name of the actor/person identifier |
group_id |
character; column name of the group identifier |
weight_partners |
logical; if |
prefix_actor |
character; prefix for actor dummy columns. Default
|
prefix_partner |
character; prefix for partner dummy columns. Default
|
a list with elements:
actor_matmatrix of actor dummies (n x n_persons)
partner_matmatrix of partner dummies, optionally weighted (n x n_persons)
actor_namescharacter vector of actor dummy column names
partner_namescharacter vector of partner dummy column names
group_sizesinteger vector of length n giving the group size
for each observation; pass this to cpsrm_run() via the
group_sizes argument
person_levelscharacter vector of person IDs (column order)
n_personsinteger; number of unique persons
n_groupsinteger; number of unique groups
group_size_tabletable of group size frequencies
cpsrm_run, create_dummies
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.