| cpsrm_run | R Documentation |
Fits the Co-Partner Social Relations Model (CP-SRM) using restricted
maximum likelihood (REML). The "block" method uses the Woodbury
matrix identity for fast computation on large datasets; the "loop"
method constructs the full covariance matrix by iterating over groups.
cpsrm_run(
dv,
actor_id,
group_id,
data,
actor_dummies,
partner_dummies,
group_sizes = NULL,
location_id = NULL,
method = c("block", "loop"),
zero_rho = FALSE,
zero_actor = FALSE,
zero_partner = FALSE,
zero_group = FALSE,
zero_location = FALSE,
weight_partners = TRUE,
fixed_effects = NULL,
start = NULL,
maxit = 200000L,
stage1_maxit = 1000L,
stage2_maxit = 1000L,
tol = 1e-10,
se_method = c("hessian", "none"),
rho_boundary = 0.99,
optimizer = c("Nelder-Mead", "L-BFGS-B"),
verbose = FALSE,
verbose_every = 50L
)
dv |
character; name of the dependent variable column |
actor_id |
character; name of the actor identifier column |
group_id |
character; name of the group identifier column |
data |
a |
actor_dummies |
character vector; actor dummy column names |
partner_dummies |
character vector; partner dummy column names |
group_sizes |
integer vector or |
location_id |
character or |
method |
character; |
zero_rho |
logical; fix actor-partner correlation at zero. Default
|
zero_actor |
logical; fix actor variance at zero. Default |
zero_partner |
logical; fix partner variance at zero. Default
|
zero_group |
logical; fix group variance at zero. Default |
zero_location |
logical; fix location variance at zero. Default
|
weight_partners |
logical; weight partner dummies by
|
fixed_effects |
character vector or |
start |
named numeric vector or |
maxit |
integer; maximum optimizer iterations. Default |
stage1_maxit |
integer; stage 1 Nelder-Mead iterations. Default
|
stage2_maxit |
integer; stage 2 Nelder-Mead iterations. Default
|
tol |
numeric; convergence tolerance. Default |
se_method |
character; |
rho_boundary |
numeric; boundary warning threshold. Default |
optimizer |
character; |
verbose |
logical; print progress. Default |
verbose_every |
integer; print every N evaluations. Default |
an object of class "cpsrm"
Because each row sums multiple independent partner effects (its
group_size - 1), \sigma_P^2 can be reported on two
different, equally valid bases when weight_partners = FALSE:
RAW (\sigma_P^2 itself): the variance of the
partner-effect parameter, on the same per-person basis as
\sigma_A^2. Use RAW whenever comparing the magnitude of
partner effects to actor effects (e.g. tests of generalized
reciprocity).
COMBINED (partner's row multiplied by
group_size - 1): partner identity's total contribution to
the variance of a single observed score. Use COMBINED only when
reading a full variance decomposition in which all components must
sum to the outcome's total variance.
Mixing the two conventions in the same comparison is a common source of
error: because COMBINED mechanically multiplies partner's numerator
while RAW does not, a naive COMBINED-vs-RAW comparison can make partner
effects look several times more (or less) important than actor effects
even when the two are, per person, identical in magnitude.
print.cpsrm/summary.cpsrm report both whenever
weight_partners = FALSE and group size is constant across the
data; when group size varies, or weight_partners = TRUE (partner
dummies already rescaled to average rather than sum partner effects),
only RAW is shown.
cpsrm_run reports a Wald z-statistic (estimate / SE) for each
variance component, but variance components are bounded below by zero,
so the usual two-sided reference distribution is not correct for
testing whether a variance component is zero. The standard correction
(Self & Liang, 1987; Snijders & Bosker, 2012; Stram & Lee, 1994) is to
fit the model with and without the component of interest (e.g.
zero_partner = TRUE vs. FALSE), form the likelihood-ratio
statistic from each fit's fit["reml_loglik"]
(LRT = -2(\ell_{restricted} - \ell_{full})), and compute a
ONE-SIDED p-value:
p <- 0.5 * pchisq(LRT, df = 1, lower.tail = FALSE)
Testing TWO variance components jointly at their boundary (e.g. actor and partner both zero) is NOT a simple halving of the df = 2 chi-square, because both parameters are boundary-constrained; it requires the three-part mixture (Self & Liang, 1987):
p <- 0.25 * pchisq(LRT, df = 0, lower.tail = FALSE) +
0.50 * pchisq(LRT, df = 1, lower.tail = FALSE) +
0.25 * pchisq(LRT, df = 2, lower.tail = FALSE)
(the df = 0 term is always 0 for any LRT > 0). Applying the
plain, uncorrected pchisq p-value, or halving the df = 2 joint
test the same way as a single-component test, both misstate
significance and are not valid inferential procedures for this model.
create_cp_dummies
# Prepare dummies using create_cp_dummies(), bind onto data, then call
# cpsrm_run(). See create_cp_dummies() documentation for a full example.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.