cpsrm: Fit the Co-Partner Social Relations Model from Raw...

View source: R/cpsrm.R

cpsrmR Documentation

Fit the Co-Partner Social Relations Model from Raw Long-Format Data

Description

cpsrm() is a friendly, tidyverse-style entry point for the Co-Partner SRM. Give it raw long-format data and the names of the outcome, actor, and group columns; it builds the actor/partner dummy matrices with create_cp_dummies and fits the model with cpsrm_run. Use cpsrm_run directly when you need to supply your own dummy matrices (e.g. dummies built once and reused across several model calls).

Usage

cpsrm(
  data,
  dv,
  actor_id,
  group_id,
  location_id = NULL,
  weight_partners = TRUE,
  ...
)

Arguments

data

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

dv

character; column name of the outcome variable

actor_id

character; column name of the actor/person identifier

group_id

character; column name of the group identifier

location_id

character or NULL; column name of a higher-level clustering variable (e.g. course, site), if any

weight_partners

logical; passed to both create_cp_dummies (how the dummies are built) and cpsrm_run (how \sigma_P^2 is interpreted) — see create_cp_dummies for details. Default TRUE

...

additional arguments passed through to cpsrm_run (e.g. zero_rho, fixed_effects, method, optimizer, se_method, start, verbose)

Value

an object of class "cpsrm"; see cpsrm_run for the full return value. The dummy-construction output from create_cp_dummies is attached as $dummies for reference (e.g. to inspect $dummies$group_size_table).

See Also

cpsrm_run for the full-control interface, create_cp_dummies for the dummy-matrix construction this wrapper calls internally

Examples


# cpsrm() 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)
}))
team_dat$score <- rnorm(nrow(team_dat), mean = 70, sd = 3)

fit <- cpsrm(
  data         = team_dat,
  dv           = "score",
  actor_id     = "player",
  group_id     = "team",
  zero_rho     = TRUE,     # keep the toy example fast/well-behaved
  se_method    = "none",
  stage1_maxit = 100,
  stage2_maxit = 100
)
print(fit)


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