| Title: | Manipulate and Analyze Round Robin Dyadic Data |
|---|---|
| Description: | Provides utilities for processing and analyzing dyadic data collected using a round-robin design, in which each person in a group rates or interacts with every other person on at least one variable. Data manipulation functions prepare datasets for dyadic data analysis by creating the actor and partner dummy variables required by the social relations model (SRM). Analysis functions implement the SRM using multilevel modeling via a custom 'nlme' covariance class ('pdSRM'), following the approach of Snijders and Kenny (1999) <doi:10.1111/j.1475-6811.1999.tb00204.x> and Knight and Humphrey (2019) <doi:10.1037/0000115-019>. The package estimates group, actor, partner, and relationship variance components along with generalized and dyadic reciprocity correlations, and supports both null and fixed-effects models. |
| Authors: | Andrew Knight [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-6700-1903>) |
| Maintainer: | Andrew Knight <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1 |
| Built: | 2026-05-22 08:45:47 UTC |
| Source: | https://github.com/andrewpknight/roundrobinr |
Internal method called by coef.pdMat to extract the
three underlying SRM parameters: actor standard deviation, partner
standard deviation, and actor-partner correlation.
## S3 method for class 'pdSRM' coef(object, unconstrained = TRUE, ...)## S3 method for class 'pdSRM' coef(object, unconstrained = TRUE, ...)
object |
an object inheriting from |
unconstrained |
logical; if |
... |
additional arguments (currently unused) |
a named numeric vector with elements std. dev-a,
std. dev-p, and corr.
d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )
Internal method called by corMatrix to reconstruct
the correlation matrix from the compressed SRM parameters.
## S3 method for class 'pdSRM' corMatrix(object, ...)## S3 method for class 'pdSRM' corMatrix(object, ...)
object |
an object inheriting from |
... |
additional arguments (currently unused) |
the correlation matrix corresponding to the positive-definite
matrix represented by object, with a "stdDev" attribute
giving the standard deviations
d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )
Generates the actor and partner dummy variables required to fit the Social Relations Model (SRM) using multilevel modeling, following the approach of Snijders and Kenny (1999). The function produces N actor dummies and N partner dummies, where N is the maximum group size in the dataset.
createDummies( group.id, act.id, part.id, d, include.self = FALSE, merge.original = FALSE )createDummies( group.id, act.id, part.id, d, include.self = FALSE, merge.original = FALSE )
group.id |
string; name of the group identifier variable |
act.id |
string; name of the actor identifier variable |
part.id |
string; name of the partner identifier variable |
d |
a |
include.self |
logical; if |
merge.original |
logical; if |
a data.frame containing:
pdSRM_act_idinteger internal actor identifier
pdSRM_part_idinteger internal partner identifier
pdSRM_act_numinteger actor slot number within group
pdSRM_part_numinteger partner slot number within group
pdSRM_dyad_idinteger undirected dyad identifier
a1, a2, ...actor dummy variables
p1, p2, ...partner dummy variables
If merge.original = TRUE, all original variables are appended.
Snijders, T. A. B., & Kenny, D. A. (1999). The social relations model for family data: A multilevel approach. Personal Relationships, 6, 471–486. doi:10.1111/j.1475-6811.1999.tb00204.x
d_out <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData ) head(d_out)d_out <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData ) head(d_out)
Internal method called by pdConstruct to initialize
a pdSRM object. Enforces the SRM constraint of equal actor
variances, equal partner variances, and a single actor-partner covariance.
## S3 method for class 'pdSRM' pdConstruct( object, value = numeric(0), form = stats::formula(object), nam = nlme::Names(object), data = sys.frame(sys.parent()), ... )## S3 method for class 'pdSRM' pdConstruct( object, value = numeric(0), form = stats::formula(object), nam = nlme::Names(object), data = sys.frame(sys.parent()), ... )
object |
an object inheriting from |
value |
an optional initialization value |
form |
an optional one-sided linear formula |
nam |
an optional vector of character strings |
data |
an optional data frame in which to evaluate the variables |
... |
optional arguments passed to other methods |
a pdSRM object representing the SRM positive-definite matrix
d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )
Internal method called by pdMatrix to reconstruct the
full covariance matrix from the three stored SRM parameters (actor SD,
partner SD, actor-partner correlation).
## S3 method for class 'pdSRM' pdMatrix(object, factor = FALSE)## S3 method for class 'pdSRM' pdMatrix(object, factor = FALSE)
object |
an object inheriting from |
factor |
logical; if |
if factor is FALSE, the positive-definite matrix
represented by object; if TRUE, an upper triangular
Cholesky factor with a logDet attribute
d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )
Creates the positive-definite matrix class used to specify the
actor-partner covariance structure of the Social Relations Model within
lme. This class enforces the SRM constraint that all
actors share a single variance, all partners share a single variance, and
a single actor-partner covariance (generalized reciprocity) is estimated.
pdSRM( value = numeric(0), form = NULL, nam = NULL, data = sys.frame(sys.parent()) )pdSRM( value = numeric(0), form = NULL, nam = NULL, data = sys.frame(sys.parent()) )
value |
an optional initialization value, inherited from
|
form |
an optional one-sided linear formula specifying the row/column names for the matrix |
nam |
an optional vector of character strings specifying the row/column names for the matrix |
data |
inherited from the surrounding |
a pdMat object representing a positive-definite matrix
conforming to the SRM covariance structure
Knight, A. P., & Humphrey, S. E. (2019). Dyadic data analysis. In S. E. Humphrey & J. M. LeBreton (Eds.), The Handbook for Multilevel Theory, Measurement, and Analysis (pp. 423–447). American Psychological Association. doi:10.1037/0000115-019
Snijders, T. A. B., & Kenny, D. A. (1999). The social relations model for family data: A multilevel approach. Personal Relationships, 6, 471–486. doi:10.1111/j.1475-6811.1999.tb00204.x
d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )
A simulated directed dyadic dataset in long format, suitable for demonstrating the functions in this package. The dataset contains observations from a round-robin design in which each person in a group rated every other person. Ratings were collected at two time points.
sampleDyadDatasampleDyadData
A data frame with 1548 rows and 16 variables:
integer; group identification variable
integer; actor (rater) identification variable
integer; partner (ratee) identification variable
integer; time point identifier (1 or 2)
integer; directed dyad-level measure of contact frequency
integer; directed dyad-level measure of liking
numeric; actor-level measure of extraversion
numeric; actor-level measure of agreeableness
integer; actor-level binary gender indicator (1 = male)
integer; actor-level age in years
numeric; partner-level measure of extraversion
numeric; partner-level measure of agreeableness
integer; partner-level binary gender indicator (1 = male)
integer; partner-level age in years
numeric; group-level measure of cohesion
numeric; group-level measure of efficacy
Simulated data created for package demonstration purposes.
Computes pseudo R-squared values for each SRM variance component by
comparing a null model (intercept only) with a predictor model (with
fixed effects). The pseudo R-squared for each component is
(null - predicted) / null, reflecting the proportion of each
variance component explained by the fixed effects.
srmPseudoRSq(null.model, predict.model)srmPseudoRSq(null.model, predict.model)
null.model |
an |
predict.model |
an |
a data.frame with three columns and four rows (Group,
Actor, Partner, Dyad):
nullvariance component from the null model
predictvariance component from the predictor model
pseudoR2pseudo R-squared: (null - predict) / null
d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) null_mod <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit ) pred_mod <- nlme::lme( liking ~ actEx + partEx + contact, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit ) srmPseudoRSq(null.model = null_mod, predict.model = pred_mod)d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) null_mod <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit ) pred_mod <- nlme::lme( liking ~ actEx + partEx + contact, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit ) srmPseudoRSq(null.model = null_mod, predict.model = pred_mod)
A wrapper function that fits the Social Relations Model (SRM) on a
directed dyadic dataset using restricted maximum likelihood via
lme. The function creates the necessary actor and
partner dummy variables, constructs the SRM covariance structure using
pdSRM, and returns both the raw lme output and a
formatted variance decomposition table.
srmRun(dv, groupId, actId, partId, feVars = NULL, data)srmRun(dv, groupId, actId, partId, feVars = NULL, data)
dv |
string; name of the directed dyadic criterion (outcome) variable |
groupId |
string; name of the group identifier variable |
actId |
string; name of the actor identifier variable |
partId |
string; name of the partner identifier variable |
feVars |
character vector of fixed-effect predictor variable names,
or |
data |
a |
a named list with two elements:
lme.outputthe full lme model object
srm.outputa data.frame from srmVarPct
giving variances, percentages, and reciprocity correlations
Knight, A. P., & Humphrey, S. E. (2019). Dyadic data analysis. In S. E. Humphrey & J. M. LeBreton (Eds.), The Handbook for Multilevel Theory, Measurement, and Analysis (pp. 423–447). American Psychological Association. doi:10.1037/0000115-019
Snijders, T. A. B., & Kenny, D. A. (1999). The social relations model for family data: A multilevel approach. Personal Relationships, 6, 471–486. doi:10.1111/j.1475-6811.1999.tb00204.x
o <- srmRun( dv = "liking", groupId = "groupId", actId = "actId", partId = "partId", feVars = c("actEx", "partEx", "contact"), data = sampleDyadData[sampleDyadData$timeId == 1, ] ) o$srm.outputo <- srmRun( dv = "liking", groupId = "groupId", actId = "actId", partId = "partId", feVars = c("actEx", "partEx", "contact"), data = sampleDyadData[sampleDyadData$timeId == 1, ] ) o$srm.output
Extracts and formats the variance components and reciprocity correlations
from an lme object fitted with the
pdSRM covariance structure. Returns group, actor, partner,
and dyadic (relationship) variances as both raw values and percentages of
total variance, along with generalized reciprocity (actor-partner
correlation) and dyadic reciprocity.
srmVarPct(object)srmVarPct(object)
object |
an |
a data.frame with two columns and six rows:
variances.and.covariancesGroup, Actor, Partner, and Dyad variances; Generalized Reciprocity covariance; Dyadic Reciprocity covariance
percents.and.correlationsvariance percentages for the four components; Generalized Reciprocity correlation; Dyadic Reciprocity correlation
Kenny, D. A., Kashy, D. A., & Cook, W. L. (2006). Dyadic Data Analysis. Guilford Press.
d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit ) srmVarPct(o)d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit ) srmVarPct(o)
Internal method that produces a summary.pdMat representation of
a pdSRM object, used by lme when printing
model output.
## S3 method for class 'pdSRM' summary(object, structName = "Social Relations Model", ...)## S3 method for class 'pdSRM' summary(object, structName = "Social Relations Model", ...)
object |
an object inheriting from |
structName |
a character string describing the covariance structure;
defaults to |
... |
optional arguments passed to other methods |
an object of class summary.pdMat with additional attributes
structName and noCorrelation
d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )d <- createDummies( group.id = "groupId", act.id = "actId", part.id = "partId", d = sampleDyadData[sampleDyadData$timeId == 1, ], merge.original = TRUE ) o <- nlme::lme( liking ~ 1, random = list(groupId = nlme::pdBlocked(list( nlme::pdIdent(~1), pdSRM(~ -1 + a1 + a2 + a3 + a4 + p1 + p2 + p3 + p4) ))), correlation = nlme::corCompSymm(form = ~1 | groupId / pdSRM_dyad_id), data = d, na.action = stats::na.omit )