umx_make_TwinData: Simulate twin data with control over A, C, and E (and D)...

umx_make_TwinDataR Documentation

Simulate twin data with control over A, C, and E (and D) parameters

Description

Makes MZ and DZ twin data for standard ACE/ADE, fixed MZ/DZ correlations, thresholds, or bivariate GxE (umxGxEbiv()). By default, variance components must sum to 1.

For univariate Purcell GxE data for umxGxE(), use umx_make_GxE_data() instead (path form \(a + a_m M\), ground-truth attributes, optional age covariate phenotype). Passing the old univariate style AA = c(avg = ..., min = ..., max = ...) to this function is an error and points you to that helper.

See examples for how to use this: it is pretty flexible.

If you provide 2 varNames, they will be used for twin 1 and twin 2. If you provide one, it will be expanded to var_T1 and var_T2. note: the function was designed around nSib = 2 and var names = var_T1. It isn't yet smart enough to do, for instance scaling or shifting to make the min value 0 (normal for most traits we analyse) for nonstandard varNames and nSib.

Note, if you want a power calculator, see power.ACE.test() and umxPower().

Usage

You must supply nMZpairs (you can omit nDZpairs). You can give any two of A, C, or E and the function deduces the missing parameter so A+C+E == 1.

Bivariate GxE Data (for umxGxEbiv())

To simulate data with a moderator that is not shared by both twins. Moderated heritability is specified via the bivariate relationship (AA, CC, EE) and two moderators in each component. AA = list(a11 = .4, a12 = .1, a22 = .15) CC = list(c11 = .2, c12 = .1, c22 = .10) EE = list(e11 = .4, e12 = .3, e22 = .25) Amod = list(Beta_a1 = .025, Beta_a2 = .025) Cmod = list(Beta_c1 = .025, Beta_c2 = .025) Emod = list(Beta_e1 = .025, Beta_e2 = .025)

Usage

umx_make_TwinData(
  nMZpairs,
  nDZpairs = nMZpairs,
  AA = NULL,
  CC = NULL,
  EE = NULL,
  DD = NULL,
  varNames = "var",
  MZr = NULL,
  DZr = MZr,
  nSib = 2,
  dzAr = 0.5,
  scale = FALSE,
  mean = 0,
  sd = 1,
  nThresh = NULL,
  sum2one = TRUE,
  bivAmod = NULL,
  bivCmod = NULL,
  bivEmod = NULL,
  seed = NULL,
  empirical = FALSE
)

Arguments

nMZpairs

Number of MZ pairs to simulate

nDZpairs

Number of DZ pairs to simulate (defaults to nMZpairs)

AA

value for A variance (scalar). For bivariate GxE, a list of Cholesky elements (see details).

CC

value for C variance.

EE

value for E variance.

DD

value for D variance (univariate ACE/ADE only).

varNames

name for variables (defaults to 'var')

MZr

If MZr and DZr are set (default = NULL), the function returns dataframes of the request n and correlation.

DZr

Set to return dataframe using MZr and Dzr (Default NULL)

nSib

Number of siblings in a family (default = 2). "3" = extra sib.

dzAr

DZ Ar (default .5)

scale

Whether to scale output to var=1 mean=0 (Default FALSE)

mean

mean for traits (default = 0) (not applied to bivariate GxE)

sd

sd of traits (default = 1) (not applied to bivariate GxE)

nThresh

If supplied, use as thresholds and return mxFactor output? (default is not to)

sum2one

Whether to enforce AA + CC + EE summing the one (default = TRUE)

bivAmod

Used for Bivariate GxE data: list(Beta_a1 = .025, Beta_a2 = .025)

bivCmod

Used for Bivariate GxE data: list(Beta_c1 = .025, Beta_c2 = .025)

bivEmod

Used for Bivariate GxE data: list(Beta_e1 = .025, Beta_e2 = .025)

seed

Allows user to set.seed() if wanting reproducible dataset

empirical

Passed to mvrnorm

Value

  • data.frame with twin columns and zygosity (plus moderator columns for bivariate GxE)

References

https://github.com/tbates/umx, https://tbates.github.io

See Also

  • umxACE(), umx_make_GxE_data(), umxGxE(), umxGxEbiv()

Other Twin Data functions: umx, umx_long2wide(), umx_make_twin_data_nice(), umx_residualize(), umx_scale_wide_twin_data(), umx_wide2longTwinData(), umx_yj_wide_twin_data()

Other Data Functions: noNAs(), prolific_anonymize(), prolific_check_ID(), prolific_read_demog(), prolific_scoring_stub(), umx, umxFactor(), umxGSEM_sim_snps(), umxHetCor(), umx_as_numeric(), umx_cont_2_quantiles(), umx_lower2full(), umx_make_GxE_data(), umx_make_MR_data(), umx_make_fake_data(), umx_make_raw_from_cov(), umx_merge_randomized_columns(), umx_polychoric(), umx_polypairwise(), umx_polytriowise(), umx_read_lower(), umx_rename(), umx_reorder(), umx_score_scale(), umx_select_valid(), umx_stack(), umx_strings2numeric()

Examples

# =====================================================================
# = Basic Example, with all elements of std univariate data specified =
# =====================================================================
tmp = umx_make_TwinData(nMZpairs = 10000, AA = .30, CC = .00, EE = .70)
# Show dataframe with 20,000 rows and 3 variables: var_T1, var_T2, and zygosity
str(tmp)

# ===============================
# = How to consume the datasets =
# ===============================

mzData = tmp[tmp$zygosity == "MZ", ]
dzData = tmp[tmp$zygosity == "DZ", ]
str(mzData); str(dzData);
cov(mzData[, c("var_T1", "var_T2")])
cov(dzData[, c("var_T1", "var_T2")])
umxAPA(mzData[, c("var_T1", "var_T2")])

# Prefer to work in path coefficient values? (little a?)
tmp    = umx_make_TwinData(2000, AA = .7^2, CC = .0)
mzData = tmp[tmp$zygosity == "MZ", ]
dzData = tmp[tmp$zygosity == "DZ", ]
m1 = umxACE(selDVs="var", sep="_T", mzData= mzData, dzData= dzData)

# Examine correlations
cor(mzData[,c("var_T1","var_T2")])
cor(dzData[,c("var_T1","var_T2")])

# Example with D (left un-modeled in ACE)
tmp = umx_make_TwinData(nMZpairs = 500, AA = .4, DD = .2, CC = .2)
m1 = umxACE(selDVs="var", data = tmp, mzData= "MZ", dzData= "DZ")
# |    |   a1|   c1|   e1|
# |:---|----:|----:|----:|
# |var | 0.86| 0.24| 0.45|

m1 = umxACE(selDVs="var", data = tmp, mzData= "MZ", dzData= "DZ", dzCr=.25)
# |    |  a1|d1 |   e1|
# |:---|---:|:--|----:|
# |var | 0.9|.  | 0.44|


# =============
# = Shortcuts =
# =============

# Omit nDZpairs (equal numbers of both by default)
tmp = umx_make_TwinData(100, AA = 0.5, CC = 0.3) # omit any one of A, C, or E (sums to 1)
cov(tmp[tmp$zygosity == "DZ", c("var_T1","var_T2")])

# Not limited to unit variance
tmp = umx_make_TwinData(100, AA = 3, CC = 2, EE = 3, sum2one = FALSE)
cov(tmp[tmp$zygosity == "MZ", c("var_T1","var_T2")])

# Output can be scaled (mean=0, std=1)
tmp = umx_make_TwinData(100, AA = .7, CC = .1, scale = TRUE)
cov(tmp[tmp$zygosity == "MZ", c("var_T1","var_T2")])

# Univariate GxE for umxGxE: use umx_make_GxE_data() (not umx_make_TwinData)
# df = umx_make_GxE_data(nMZpairs = 500, nDZpairs = 500, am = 0.15)
# m1 = umxGxE(selDVs = "outcome", selDefs = "mod", sep = "_T",
#   data = df, mzData = "MZ", dzData = "DZ")

## Not run: 

# =====================
# = Threshold Example =
# =====================
tmp = umx_make_TwinData(100, AA = .6, CC = .2, nThresh = 3)
str(tmp)
umx_polychoric(subset(tmp, zygosity=="MZ", c("var_T1", "var_T2")))$polychorics
# Running model with 7 parameters
#           var_T1    var_T2
# var_T1 1.0000000 0.7435457
# var_T2 0.7435457 1.0000000


# =================================================
# = Just use MZr and DZr (also works with nSib>2) =
# =================================================
tmp = umx_make_TwinData(100, MZr = .86, DZr = .60, nSib= 3, varNames = "IQ")
umxAPA(subset(tmp, zygosity == "MZ", paste0("IQ_T", 1:2)))
umxAPA(subset(tmp, zygosity == "DZ", paste0("IQ_T", 1:2)))
m1 = umxACE(selDVs= "IQ", data = tmp)
m1 = umxACE(selDVs= "IQ", data = tmp, nSib=3)
# TODO tmx_ examples of unmodeled D etc.

# Bivariate GxSES example (see umxGxEbiv)

AA   = list(a11 = .4, a12 = .1, a22 = .15)
CC   = list(c11 = .2, c12 = .1, c22 = .10)
EE   = list(e11 = .4, e12 = .3, e22 = .25)
Amod = list(Beta_a1 = .025, Beta_a2 = .025)
Cmod = list(Beta_c1 = .025, Beta_c2 = .025)
Emod = list(Beta_e1 = .025, Beta_e2 = .025)
tmp = umx_make_TwinData(5000, AA =AA, CC = CC, EE = EE,
			bivAmod = Amod, bivCmod =Cmod, bivEmod =Emod)
str(tmp)
# 'data.frame':	10000 obs. of  7 variables:
#  $ defM_T1 : num  0.171 0.293 -0.173 0.238 -0.73 ...
#  $ defM_T2 : num  0.492 -0.405 -0.696 -0.829 -0.858 ...
#  $ M_T1    : num  0.171 0.293 -0.173 0.238 -0.73 ...
#  $ var_T1  : num  0.011 0.1045 0.5861 0.0583 1.0225 ...
#  $ M_T2    : num  0.492 -0.405 -0.696 -0.829 -0.858 ...
#  $ var_T2  : num  -0.502 -0.856 -0.154 0.065 -0.268 ...
#  $ zygosity: Factor w/ 2 levels "MZ","DZ": 1 1 1 1 1 1 1 1 1 1 ...

## End(Not run)

umx documentation built on Oct. 11, 2026, 5:07 p.m.