Learn R Programming

NlsyLinks (version 1.003)

CleanSemAceDataset: Produces a cleaned dataset that works well with when using SEM to estimate a univariate ACE model.

Description

This function takes a 'GroupSummary' data.frame (which is created by the RGroupSummary function) and returns a data.frame that is used by the Ace function.

Usage

CleanSemAceDataset(dsDirty, dsGroupSummary, oName_1, oName_2, rName = "R")

Arguments

dsDirty
This is the data.frame to be cleaned.
dsGroupSummary
The data.frame containing information about which groups should be included in the analyses. It should be created by the RGroupSummary function.
oName_1
The name of the manifest variable (in dsDirty) for the first subject in each pair.
oName_2
The name of the manifest variable (in dsDirty) for the second subject in each pair.
rName
The name of the variable (in dsDirty) indicating the pair's relatedness coefficient.

Value

  • A data.frame with one row per subject pair. The data.frame contains the following variables (which can NOT be changed by the user):
  • RThe pair's R value.
  • M1The manifest variable for the first subject in each pair.
  • M2The manifest variable for the second subject in each pair.
  • GroupIDIndicates the pair's group membership.

Details

The function takes dsDirty and produces a new data.frame with the following features:
  1. Only three existing columns are retained:M1,M2, andR. They assigned these names.
  2. A new column calledGroupIDis created to reflect their group membership (which is based on theRvalue). These valuesa re sequential integers, starting at 1. The group with the weakestRis 1. The group with the strongestRhas the largestGroupID(this is typically the MZ tiwns).
  3. Any row is excluded if it has a missing data point forM1,M2, orR.
  4. Thedata.frameis sorted by theRvalue. This helps program against the multiple-group SEM API sometimes.

Examples

Run this code
dsFull <- Links79PairExpanded #Start with the built-in data.frame in NlsyLinks
oName_1 <- "MathStandardized_1" #Stands for Manifest1
oName_2 <- "MathStandardized_2" #Stands for Manifest2
dsGroupSummary <- RGroupSummary(dsFull, oName_1, oName_2)

dsClean <- CleanSemAceDataset( dsDirty=dsFull, dsGroupSummary, oName_1, oName_2, rName="R" )
summary(dsClean)

dsClean$AbsDifference <- abs(dsClean$O1 - dsClean$O2)
plot(jitter(dsClean$R), dsClean$AbsDifference, col="gray70")

Run the code above in your browser using DataLab