# =========================
# = Load and Process Data =
# =========================
if (FALSE) {
require(umx)
data("us_skinfold_data")
# Rescale vars
us_skinfold_data[, c('bic_T1', 'bic_T2')] = us_skinfold_data[, c('bic_T1', 'bic_T2')]/3.4
us_skinfold_data[, c('tri_T1', 'tri_T2')] = us_skinfold_data[, c('tri_T1', 'tri_T2')]/3
us_skinfold_data[, c('caf_T1', 'caf_T2')] = us_skinfold_data[, c('caf_T1', 'caf_T2')]/3
us_skinfold_data[, c('ssc_T1', 'ssc_T2')] = us_skinfold_data[, c('ssc_T1', 'ssc_T2')]/5
us_skinfold_data[, c('sil_T1', 'sil_T2')] = us_skinfold_data[, c('sil_T1', 'sil_T2')]/5
# Data for each of the 5 twin-type groups
mzmData = subset(us_skinfold_data, zyg == 1)
mzfData = subset(us_skinfold_data, zyg == 2)
dzmData = subset(us_skinfold_data, zyg == 3)
dzfData = subset(us_skinfold_data, zyg == 4)
dzoData = subset(us_skinfold_data, zyg == 5)
umxSummarizeTwinData(us_skinfold_data, selVars="bic",zyg="zyg", sep="_T",
MZFF=2, DZFF=4, MZMM=1, DZMM=3, DZOS=5
)
# ==========================
# = Run univariate example =
# ==========================
m1 = umxSexLim(selDVs = "bic", sep = "_T", A_or_C = "A", tryHard = "yes",
mzmData = mzmData, dzmData = dzmData,
mzfData = mzfData, dzfData = dzfData,
dzoData = dzoData
)
# Drop qualitative sex limitation
m1a = umxModify(m1, regex = "^Rao_", value=1, name = "no_qual", comparison = TRUE)
# Equate a, ac, and try ace across m & f in scalar model
m1b = umxModify(m1a, regex = "^a[fm]_", newlabels="a_", name = "eq_a_no_qual", comparison = TRUE)
m1c = umxModify(m1b, regex = "^c[fm]_", newlabels="c_", name = "eq_ac_no_qual", comparison = TRUE)
m1d = umxModify(m1c, regex = "^e[fm]_", newlabels="e_", name = "eq_ace_no_qual", comparison = TRUE)
umxCompare(m1, c(m1a, m1b, m1c, m1d))
# ============================
# = Scalar Sex Limitation =
# ============================
m2 = umxSexLim(selDVs = "bic", sep = "_T", sexlim = "Scalar", tryHard = "yes",
mzmData = mzmData, dzmData = dzmData,
mzfData = mzfData, dzfData = dzfData,
dzoData = dzoData
)
# Show our manual drop of qualitative is the same as umxSexLim with sexlim= "scalar"s
umxCompare(m1a, m2)
# ===============
# = Homogeneity =
# ===============
m3 = umxSexLim(selDVs = "bic", sep = "_T", sexlim = "Homogeneity", tryHard = "yes",
mzmData = mzmData, dzmData = dzmData,
mzfData = mzfData, dzfData = dzfData,
dzoData = dzoData
)
umxCompare(m1, c(m2, m3))
# ===========================================
# = Bivariate example with manual reduction =
# ===========================================
m1 = umxSexLim(selDVs = c("bic", "tri"), sep = "_T", A_or_C = "A", tryHard="yes",
mzmData = mzmData, dzmData = dzmData,
mzfData = mzfData, dzfData = dzfData,
dzoData = dzoData
)
# Scalar sex limitation (same correlation among components for m and f)
m2 = umxSexLim(selDVs = c("bic", "tri"), sep = "_T",
A_or_C = "A", tryHard="yes", sexlim="Scalar",
mzmData = mzmData, dzmData = dzmData,
mzfData = mzfData, dzfData = dzfData,
dzoData = dzoData
)
# Drop qualitative sex limitation
# Distinct af and am (& c & e), but shared Ra (& Rc & Re) between variables
# i.e., same correlations for males and females.
m1a = umxModify(m1 , regex = "^Ra[mfo]_", newlabels="^Ra_", name = "no_qual_a", comparison = TRUE)
m1b = umxModify(m1a, regex = "^Rc[mfo]_", newlabels="^Rc_", name = "no_qual_ac", comparison = TRUE)
m1c = umxModify(m1b, regex = "^Re[mfo]_", newlabels="^Re_", name = "no_qual_ace", comparison = TRUE)
umxCompare(m1, c(m1a, m1b, m1c, m2))
# In one smart regular expression
m2 = umxModify(m1, regex = "^R([ace])[fmo]_", newlabels = "R\\1_",
name = "scalar", comparison = TRUE)
# Equate a, ac, and try ace across m & f in scalar model
m2a = umxModify(m2 , regex = "^a[fm]_", newlabels="a_", name = "eq_a_no_qual" , comparison = TRUE)
m2b = umxModify(m2a, regex = "^c[fm]_", newlabels="c_", name = "eq_ac_no_qual" , comparison = TRUE)
m2c = umxModify(m2b, regex = "^e[fm]_", newlabels="e_", name = "eq_ace_no_qual", comparison = TRUE)
umxCompare(m1, c(m1a, m1b, m1c, m1d))
# =============================
# = Run multi-variate example =
# =============================
# Variables for Analysis
selDVs = c('ssc','sil','caf','tri','bic')
selDVs = c('ssc','tri','bic')
m1 = umxSexLim(selDVs = selDVs, sep = "_T", A_or_C = "A", tryHard = "yes",
mzmData = mzmData, dzmData = dzmData,
mzfData = mzfData, dzfData = dzfData, dzoData = dzoData
)
m2 = umxSexLim(selDVs = selDVs, sep = "_T", A_or_C = "A", sexlim = "Nonscalar",
tryHard = "yes",
mzmData = mzmData, dzmData = dzmData,
mzfData = mzfData, dzfData = dzfData, dzoData = dzoData
)
# umxSummary(m1)
# summary(m1)
# summary(m1)$Mi
}
Run the code above in your browser using DataLab