Setup
FITM <- c("chisq", "df", "nPar", "cfi", "rmsea", "rmsea.ci.lower", "rmsea.ci.upper", "aic", "bic")
# Renaming the SubjectTag columns in CNLSY for merging
CNLSY_S1 <- CNLSY %>% rename_with(~paste0(., "_1"), -SubjectTag)
CNLSY_S2 <- CNLSY %>% rename_with(~paste0(., "_2"), -SubjectTag)
# Merging Links79PairExpanded with CNLSY twice: once for SubjectTag_S1 and once for SubjectTag_S2
merged_df <- Links79PairExpanded %>%
left_join(CNLSY_S1, by = c("SubjectTag_S1" = "SubjectTag")) %>%
left_join(CNLSY_S2, by = c("SubjectTag_S2" = "SubjectTag"))
# Creating a 'Relationship' column with distinct categories for DZTs, DZAs, FSTs, and FSAs
merged_df <- merged_df %>%
mutate(Relationship = case_when(
RelationshipPath == "Gen2Siblings" & RFull == 1 & EverSharedHouse == FALSE ~ "MZA",
RelationshipPath == "Gen2Siblings" & RFull == 1 & EverSharedHouse == TRUE ~ "MZT",
RelationshipPath == "Gen2Siblings" & RFull == 0.5 & CYRB_1 == CYRB_2 & EverSharedHouse == TRUE ~ "DZT",
RelationshipPath == "Gen2Siblings" & RFull == 0.5 & CYRB_1 == CYRB_2 & EverSharedHouse == FALSE ~ "DZA",
RelationshipPath == "Gen2Siblings" & RFull == 0.5 & CYRB_1 != CYRB_2 & EverSharedHouse == TRUE ~ "FST",
RelationshipPath == "Gen2Siblings" & RFull == 0.5 & CYRB_1 != CYRB_2 & EverSharedHouse == FALSE ~ "FSA",
RelationshipPath == "Gen2Siblings" & RFull == 0.25 & EverSharedHouse == TRUE ~ "HST",
RelationshipPath == "Gen2Siblings" & RFull == 0.25 & EverSharedHouse == FALSE ~ "HSA",
RelationshipPath == "Gen2Cousins" & RFull == 0.125 & EverSharedHouse == TRUE ~ "CZT",
RelationshipPath == "Gen2Cousins" & RFull == 0.125 & EverSharedHouse == FALSE ~ "CZA",
RelationshipPath == "Gen2Cousins" & RFull == 0.0625 & EverSharedHouse == TRUE ~ "HCZT",
RelationshipPath == "Gen2Cousins" & RFull == 0.0625 & EverSharedHouse == FALSE ~ "HCZA",
RelationshipPath == "Gen2Cousins" & RFull == 0 & EverSharedHouse == TRUE ~ "ADT",
RelationshipPath == "Gen2Cousins" & RFull == 0 & EverSharedHouse == FALSE ~ "ADA",
RelationshipPath == "Gen2Cousins" & RFull == 0.25 & EverSharedHouse == TRUE ~ "HSCT",
RelationshipPath == "Gen2Cousins" & RFull == 0.25 & EverSharedHouse == FALSE ~ "HSCA",
RelationshipPath == "AuntNiece" & RFull == 0.125 & EverSharedHouse == TRUE ~ "HNT",
RelationshipPath == "AuntNiece" & RFull == 0.125 & EverSharedHouse == FALSE ~ "HNA",
RelationshipPath == "AuntNiece" & RFull == 0 & EverSharedHouse == TRUE ~ "ADTT",
RelationshipPath == "AuntNiece" & RFull == 0 & EverSharedHouse == FALSE ~ "ADTA",
RelationshipPath == "ParentChild" & RFull == 0.5 & EverSharedHouse == FALSE ~ "PCA",
RelationshipPath == "ParentChild" & RFull == 0.5 & EverSharedHouse == TRUE ~ "PCT",
RelationshipPath == "AuntNiece" & RFull == 0.25 & EverSharedHouse == FALSE ~ "ANA",
RelationshipPath == "AuntNiece" & RFull == 0.25 & EverSharedHouse == TRUE ~ "ANT",
TRUE ~ NA_character_
)) %>%
# Dropping rows for unlikely or ambiguous relationships
filter(!(RelationshipPath == "AuntNiece" & RFull == 0.5) &
!R %in% c(0.375, 0.75))
merged_df