Learn R Programming

NlsyLinks (version 1.003)

RGroupSummary: Calculates summary statistics for each Relatedness Group in the sample.

Description

Before and after running ACE Models, it is important to examine the characteristics of the different groups. When the ACE is estimated with an SEM using multiple groups, it is even even more important. Groups may contain too few subjects to have a well-behaved covariance matrix. If a group's covariance matrix is not Positive Definite (or it's misbehaving in some other way), it's typically recommended to exclude that group from the SEM.

Usage

RGroupSummary(ds, oName_1, oName_2, rName, determinantThreshold=1e-5)

Arguments

ds
The data.frame containing the following variables:
oName_1
The name of the manifest variable corresponding to the first subject in the pair.
oName_2
The name of the manifest variable corresponding to the first subject in the pair.
rName
The name of the variable specifying the pair's Relatedness coefficient.
determinantThreshold
The minimum value the covariance matrix's determinant (for the group) should exceed to be considered Positive Definite.

Value

  • A data.frame with one row per group. The data.frame contains the following variables:
  • RThe group's R value. Note the name of this variable can be changed by the user, by specifying a non-default value to the rName argument.
  • IncludedIndicates if the group should be included in a multiple-group SEM.
  • PairCountThe number of pairs in the group with complete data for R and the two manifest variables.
  • M1VarianceThe variance (of the manifest variable) among the group's first members.
  • M2VarianceThe variance (of the manifest variable) among the group's second members.
  • M1M2CovarianceThe covariance (of the manifest variable) across the group's first and second members.
  • CorrelationThe correlation (of the manifest variable) across the group's first and second members.
  • DeterminantThe determinant of the group's covariance matrix.
  • PosDefiniteIndicates if the group's covariance matrix is positive definite.

Details

This function doesn't specific to an ACE model and groups defined by R. It could be applied to any multiple-group SEM with two manifest variables. In the future, we may generalize it beyond two manifest variables. To get summary stats for the entire sample, create a dummy indicator variable that assigns everyone to the same group. See the second example below. The default determinantThreshold value is nonzero, in order to forgive slight numerical inaccuracies caused by fixed-precision arithmetic.

References

Please see ZZZ (200?) for more information about SEM with multiple groups. TODO: refs for determinant & positive definite.

Examples

Run this code
library(NlsyLinks) #Load the package into the current R session.
ds <- Links79PairExpanded  #Load the dataset from the NlsyLinks package.
oName_1 <- "MathStandardized_1" #Stands for Manifest1
oName_2 <- "MathStandardized_2" #Stands for Manifest2
dsGroupSummary <- RGroupSummary(ds, oName_1, oName_2)
dsGroupSummary

#Should return: 
#      R Included PairCount M1Variance M2Variance M1M2Covariance Correlation Determinant PosDefinite
#1 0.250     TRUE      2719   169.1291   207.0233       40.66048   0.2172970    33360.38        TRUE
#2 0.375     TRUE        43   187.7209   220.9302       28.66334   0.1407482    40651.64        TRUE
#3 0.500     TRUE      5508   230.9663   233.3492      107.59822   0.4634764    42318.42        TRUE
#4 0.750    FALSE         2   220.5000    18.0000       63.00000   1.0000000        0.00       FALSE
#5 1.000     TRUE        22   319.1948   343.1169      277.58874   0.8387893    32465.62        TRUE


#To get summary stats for the whole sample, create one large inclusive group.
ds$Dummy <- 1
(dsSampleSummary <- RGroupSummary(ds, oName_1, oName_2, rName="Dummy"))

#Should return:
# Dummy Included PairCount M1Variance M2Variance M1M2Covariance Correlation Determinant PosDefinite
#1    1     TRUE      8392    216.466   229.2988       90.90266   0.4080195     41372.1        TRUE

Run the code above in your browser using DataLab