makeCrossCorDyadic: Calculates cross-correlations for a variable that is nested...

View source: R/rtiesShared.R

makeCrossCorDyadicR Documentation

Calculates cross-correlations for a variable that is nested by person within dyad (e.g. it is the same variable for both partners). It returns a dataframe with either: 1) if "time_lag" is null, the largest absolute cross-correlation and its lag added for each dyad (e.g., it returns either the most negative or most positive cross-correlation, whichever is larger in absolute terms – the sign is retained), or 2) if "time_lag is specified, the cross-correlations for each dyad at that lag.

Description

Calculates cross-correlations for a variable that is nested by person within dyad (e.g. it is the same variable for both partners). It returns a dataframe with either: 1) if "time_lag" is null, the largest absolute cross-correlation and its lag added for each dyad (e.g., it returns either the most negative or most positive cross-correlation, whichever is larger in absolute terms – the sign is retained), or 2) if "time_lag is specified, the cross-correlations for each dyad at that lag.

Usage

makeCrossCorDyadic(
  basedata,
  dyadId,
  personId,
  obs_name,
  dist_name,
  time_lag = NULL,
  lagMax = NULL
)

Arguments

basedata

The original dataframe provided by the user that includes all variables needed for an rties analysis, including potential system and control variables, etc.

dyadId

The name of the column in the dataframe that has the couple-level identifier.

personId

The name of the column in the dataframe that has the person-level identifier.

obs_name

The name of the column in the dataframe that has the time-varying observable (e.g., the variable for which dynamics will be assessed).

dist_name

The name of the column in the dataframe that has a variable that distinguishes the partners (e.g., sex, mother/daughter, etc) that is numeric and scored 0/1.

time_lag

If null (the default), the maximum absolute value cross-correlation and its corresponding lag are returned. Otherwise, the cross-correlation at the specified time lag is returned.

lagMax

Maximum lag at which to calculate the acf if time_lag is null. Default is 10*log10(N/m) where N is the number of observations and m the number of series.

Value

A cross-sectional version of the original dataframe with maximal absolute-value cross-correlations and their lags added for each dyad.

Examples

data <- rties_ExampleDataShort
newData <- makeCrossCorr(basedata=data, dyadId="couple", personId="person", 
obs_name="dial", dist_name="female")
head(newData)


ebmtnprof/rties documentation built on Aug. 25, 2022, 7:47 p.m.