pkgname <- "umx" source(file.path(R.home("share"), "R", "examples-header.R")) options(warn = 1) library('umx') base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') cleanEx() nameEx("Fischbein_wt") ### * Fischbein_wt flush(stderr()); flush(stdout()) ### Name: Fischbein_wt ### Title: Weight data across time. ### Aliases: Fischbein_wt ### Keywords: datasets ### ** Examples ## Not run: ##D data(Fischbein_wt) # load the data ##D str(Fischbein_wt) # data.frame ##D as.matrix(Fischbein_wt) # convert to matrix ## End(Not run) cleanEx() nameEx("FishersMethod") ### * FishersMethod flush(stderr()); flush(stdout()) ### Name: FishersMethod ### Title: Fishers Method of combining p-values. ### Aliases: FishersMethod ### ** Examples FishersMethod(c(.041, .378)) cleanEx() nameEx("GFF") ### * GFF flush(stderr()); flush(stdout()) ### Name: GFF ### Title: Twin data: General Family Functioning, divorce, and well-being. ### Aliases: GFF ### Keywords: datasets ### ** Examples ## Not run: ##D # Twin 1 variables (end in '_T1') ##D data(GFF) ##D umx_names(GFF, "1$") # Just variables ending in 1 (twin 1) ##D str(GFF) # first few rows ##D ##D ##D m1 = umxACE(selDVs= "gff", sep = "_T", ##D mzData = subset(GFF, zyg_2grp == "MZ"), ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D ) ## End(Not run) cleanEx() nameEx("RMSEA.MxModel") ### * RMSEA.MxModel flush(stderr()); flush(stdout()) ### Name: RMSEA.MxModel ### Title: RMSEA function for MxModels ### Aliases: RMSEA.MxModel ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D RMSEA(m1) ##D ##D x = RMSEA(m1) ##D x$RMSEA # 0.0309761 ##D ##D # Raw: needs to be run by umx to get RMSEA ##D m2 = umxRAM("One Factor", data = demoOneFactor, ##D umxPath("G", to = manifests), ##D umxPath(v.m. = manifests), ##D umxPath(v1m0 = "G") ##D ) ##D RMSEA(m2) ## End(Not run) cleanEx() nameEx("RMSEA.summary.mxmodel") ### * RMSEA.summary.mxmodel flush(stderr()); flush(stdout()) ### Name: RMSEA.summary.mxmodel ### Title: RMSEA function for MxModels ### Aliases: RMSEA.summary.mxmodel ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("One Factor", data = demoOneFactor[1:100,], type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1.0) ##D ) ##D tmp = summary(m1) ##D RMSEA(tmp) ## End(Not run) cleanEx() nameEx("SE_from_p") ### * SE_from_p flush(stderr()); flush(stdout()) ### Name: SE_from_p ### Title: Compute an SE from a beta and p value ### Aliases: SE_from_p ### ** Examples SE_from_p(beta = .0020, p = .780) SE_from_p(beta = .0020, p = .01) SE_from_p(beta = .0020, SE = 0.01) umxAPA(.0020, p = .01) cleanEx() nameEx("bucks") ### * bucks flush(stderr()); flush(stdout()) ### Name: bucks ### Title: Print a money object ### Aliases: bucks print ### ** Examples bucks(100 * 1.05^32) fin_interest(deposits = 20e3, interest = 0.07, yrs = 20) cleanEx() nameEx("deg2rad") ### * deg2rad flush(stderr()); flush(stdout()) ### Name: deg2rad ### Title: Convert Degrees to Degrees ### Aliases: deg2rad ### ** Examples deg2rad(180) == pi # TRUE! cleanEx() nameEx("dl_from_dropbox") ### * dl_from_dropbox flush(stderr()); flush(stdout()) ### Name: dl_from_dropbox ### Title: dl_from_dropbox ### Aliases: dl_from_dropbox ### ** Examples ## Not run: ##D dl_from_dropbox("https://dl.dropboxusercontent.com/s/7kauod48r9cfhwc/tinytwinData.rda") ##D dl_from_dropbox("tinytwinData.rda", key = "7kauod48r9cfhwc") ## End(Not run) cleanEx() nameEx("docData") ### * docData flush(stderr()); flush(stdout()) ### Name: docData ### Title: Twin data for Direction of causation modelling ### Aliases: docData ### Keywords: datasets ### ** Examples data(docData) str(docData) mzData = subset(docData, zygosity %in% c("MZFF", "MZMM")) dzData = subset(docData, zygosity %in% c("DZFF", "DZMM")) par(mfrow = c(1, 2)) # 1 rows and 3 columns plot(varA1_T2 ~varA1_T1, ylim = c(-4, 4), data = mzData, main="MZ") tmp = round(cor.test(~varA1_T1 + varA1_T2, data = mzData)$estimate, 2) text(x=-4, y=3, labels = paste0("r = ", tmp)) plot(varA1_T2 ~varA1_T1, ylim = c(-4, 4), data = dzData, main="DZ") tmp = round(cor.test(~varA1_T1 + varA1_T2, data = dzData)$estimate, 2) text(x=-4, y=3, labels = paste0("r = ", tmp)) par(mfrow = c(1, 1)) # back to as it was graphics::par(get("par.postscript", pos = 'CheckExEnv')) cleanEx() nameEx("extractAIC.MxModel") ### * extractAIC.MxModel flush(stderr()); flush(stdout()) ### Name: extractAIC.MxModel ### Title: Extract AIC from MxModel ### Aliases: extractAIC.MxModel ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D extractAIC(m1) ##D # -2.615998 ##D AIC(m1) ## End(Not run) cleanEx() nameEx("fin_NI") ### * fin_NI flush(stderr()); flush(stdout()) ### Name: fin_NI ### Title: Compute NI given annual Earnings. ### Aliases: fin_NI ### ** Examples fin_NI(42e3) fin_NI(142000) cleanEx() nameEx("fin_interest") ### * fin_interest flush(stderr()); flush(stdout()) ### Name: fin_interest ### Title: Compute the value of a principal & annual deposits at a compound ### interest over a number of years ### Aliases: fin_interest ### ** Examples ## Not run: ##D # 1. Value of a principal after yrs years at 5% return, compounding monthly. ##D # Report in browser as a nice table of annual returns and formatted totals. ##D fin_interest(principal = 5000, interest = 0.05, rep= "html") ## End(Not run) # Report as a nice markdown table fin_interest(principal = 5000, interest = 0.05, yrs = 10) umx_set_dollar_symbol("£") # 2 What rate is needed to increase principal to final value in yrs time? fin_interest(final = 1.4, yrs=5) fin_interest(principal = 50, final=200, yrs = 5) # 3. What's the value of deposits of $100/yr after 10 years at 7% return? fin_interest(deposits = 100, interest = 0.07, yrs = 10, n = 12) # 4. What's the value of $20k + $100/yr over 10 years at 7% return? fin_interest(principal= 20e3, deposits= 100, interest= .07, yrs= 10, symbol="$") # 5. What is $10,000 invested at the end of each year for 5 years at 6%? fin_interest(deposits = 10e3, interest = 0.06, yrs = 5, n=1, when= "end") # 6. What will $20k be worth after 10 years at 15% annually (n=1)? fin_interest(deposits=20e3, interest = 0.15, yrs = 10, n=1, baseYear=1) # $466,986 # manual equivalent sum(20e3*(1.15^(10:1))) # 466985.5 # 7. Annual (rather than monthly) compounding (n=1) fin_interest(deposits = 100, interest = 0.07, yrs = 10, n=1) # 8 Interest needed to increase principal to final value in yrs time. fin_interest(principal = 100, final=200, yrs = 5) cleanEx() nameEx("fin_percent") ### * fin_percent flush(stderr()); flush(stdout()) ### Name: fin_percent ### Title: Compute the percent change needed to return to the original ### value after percent off (or on). ### Aliases: fin_percent ### ** Examples # Percent needed to return to original value after 10% taken off fin_percent(-10) # Percent needed to return to original value after 10% added on fin_percent(10) # Percent needed to return to original value after 50% off 34.50 fin_percent(-50, value = 34.5) cleanEx() nameEx("fin_valuation") ### * fin_valuation flush(stderr()); flush(stdout()) ### Name: fin_valuation ### Title: Work the valuation of a company ### Aliases: fin_valuation ### ** Examples fin_valuation(rev=7e9, opmargin=.1, PE=33) # Market cap = $18,480,000,000 # (Based on PE= 33, operating Income of $0.70 B, and net income =$0.56B cleanEx() nameEx("geometric_mean") ### * geometric_mean flush(stderr()); flush(stdout()) ### Name: geometric_mean ### Title: Geometric Mean ### Aliases: geometric_mean ### ** Examples geometric_mean(c(50, 100)) # For a given sum, geometric mean is maximised with equality geometric_mean(c(75,75)) v = c(1, 149); c(sum(v), geometric_mean(v), mean(v), median(v)) # 150.00000 12.20656 75.00000 75.00000 # Underlying logic sqrt(50 * 100) # Alternate form using logs exp(mean(log(c(50 *100)))) # Reciprocal duality 1/geometric_mean(c(100, 50)) geometric_mean(c(1/100, 1/50)) cleanEx() nameEx("harmonic_mean") ### * harmonic_mean flush(stderr()); flush(stdout()) ### Name: harmonic_mean ### Title: Harmonic Mean ### Aliases: harmonic_mean ### ** Examples # Harmonic means are suitable for ratios tmp = c(33/1, 23/1) harmonic_mean(tmp) geometric_mean(tmp) mean(tmp) # Example with weights harmonic_mean(c(33/1, 23/1), weights= c(.2, .8)) # If Jack travels outbound at 1 mph, and returns at 10 miles an hour, what is his average speed? harmonic_mean(c(1,10)) # 1.81 mph cleanEx() nameEx("install.OpenMx") ### * install.OpenMx flush(stderr()); flush(stdout()) ### Name: install.OpenMx ### Title: Install OpenMx, with choice of builds ### Aliases: install.OpenMx umx_update_OpenMx ### ** Examples ## Not run: ##D install.OpenMx() # gets the NPSOL version ##D install.OpenMx("NPSOL") # gets the NPSOL version explicitly ##D install.OpenMx("CRAN") # Get the latest CRAN version ##D install.OpenMx("open travis build page") # Open web page of travis builds ## End(Not run) cleanEx() nameEx("iqdat") ### * iqdat flush(stderr()); flush(stdout()) ### Name: iqdat ### Title: Twin data: IQ measured longitudinally across 4 ages. ### Aliases: iqdat ### Keywords: datasets ### ** Examples ## Not run: ##D data(iqdat) ##D str(iqdat) ##D par(mfrow = c(1, 3)) # 1 rows and 3 columns ##D plot(IQ_age4_T1 ~ IQ_age4_T2, ylim = c(50, 150), data = subset(iqdat, zygosity == "MZ")) ##D plot(IQ_age4_T1 ~ IQ_age4_T2, ylim = c(50, 150), data = subset(iqdat, zygosity == "DZ")) ##D plot(IQ_age1_T1 ~ IQ_age4_T2, data = subset(iqdat, zygosity == "MZ")) ##D par(mfrow = c(1, 1)) # back to as it was ## End(Not run) cleanEx() nameEx("libs") ### * libs flush(stderr()); flush(stdout()) ### Name: libs ### Title: load libraries ### Aliases: libs ### ** Examples ## Not run: ##D libs("umx", "OpenMx", "car") ##D libs("umx", c("OpenMx", "car")) ##D remove.packages() ## End(Not run) cleanEx() nameEx("loadings.MxModel") ### * loadings.MxModel flush(stderr()); flush(stdout()) ### Name: loadings.MxModel ### Title: Extract factor loadings from an EFA (factor analysis). ### Aliases: loadings.MxModel ### ** Examples ## Not run: ##D myVars = c("mpg", "disp", "hp", "wt", "qsec") ##D m1 = umxEFA(name = "test", factors = 2, data = mtcars[, myVars]) ##D loadings(m1) ## End(Not run) cleanEx() nameEx("noNAs") ### * noNAs flush(stderr()); flush(stdout()) ### Name: noNAs ### Title: Succinctly select complete rows from a dataframe ### Aliases: noNAs ### ** Examples tmp = mtcars tmp[2,1] = NA noNAs(tmp, cols="mpg") noNAs(tmp, cols="mpg", drop = FALSE) noNAs(tmp) # no Mazda RX4 Wag cleanEx() nameEx("oddsratio") ### * oddsratio flush(stderr()); flush(stdout()) ### Name: oddsratio ### Title: Compute odds ratio (OR) ### Aliases: oddsratio ### ** Examples oddsratio(grp1 = c(1, 10), grp2 = c(3, 10)) oddsratio(grp1 = 0.111, grp2 = 0.429) oddsratio(grp1 = c(3, 10), grp2 = c(1, 10)) oddsratio(grp1 = c(3, 10), grp2 = c(1, 10), alpha = .01) cleanEx() nameEx("plot.MxLISRELModel") ### * plot.MxLISRELModel flush(stderr()); flush(stdout()) ### Name: plot.MxLISRELModel ### Title: Create and display a graphical path diagram for a LISREL model. ### Aliases: plot.MxLISRELModel ### ** Examples # plot() # TODO get LISREL example model # Figure out how to map its matrices to plot. Don't do without establishing demand. cleanEx() nameEx("plot.MxModel") ### * plot.MxModel flush(stderr()); flush(stdout()) ### Name: plot.MxModel ### Title: Create and display a graphical path diagram for a model. ### Aliases: plot.MxModel plot ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D plot(m1) ##D plot(m1, std = TRUE, resid = "line", digits = 3, strip_zero = FALSE) ##D ##D # ============================================================ ##D # = With a growth model, demonstrate splines= false to force = ##D # = straight lines, and move "rank" of intercept object = ##D # ============================================================ ##D ##D m1 = umxRAM("grow", data = myGrowthMixtureData, ##D umxPath(var = manifests, free = TRUE), ##D umxPath(means = manifests, fixedAt = 0), ##D umxPath(v.m. = c("int","slope")), ##D umxPath("int", with = "slope"), ##D umxPath("int", to = manifests, fixedAt = 1), ##D umxPath("slope", to = manifests, arrows = 1, fixedAt = c(0,1,2,3,4)) ##D ) ##D ##D plot(m1, means=FALSE, strip=TRUE, splines="FALSE", max="int") ## End(Not run) # end dontrun cleanEx() nameEx("plot.MxModelTwinMaker") ### * plot.MxModelTwinMaker flush(stderr()); flush(stdout()) ### Name: plot.MxModelTwinMaker ### Title: Create and display a graphical path diagram for a path-based ### twin model. ### Aliases: plot.MxModelTwinMaker umxPlotMxModelTwinMaker ### ** Examples ## Not run: ##D require(umx) ##D # ##D # ===================== ##D # = Make an ACE model = ##D # ===================== ##D # 1. Clean data: Add separator and scale ##D data(twinData) ##D tmp = umx_make_twin_data_nice(data=twinData, sep="", zygosity="zygosity", numbering=1:2) ##D tmp = umx_scale_wide_twin_data(varsToScale= c("wt", "ht"), sep= "_T", data= tmp) ##D mzData = subset(tmp, zygosity %in% c("MZFF", "MZMM")) ##D dzData = subset(tmp, zygosity %in% c("DZFF", "DZMM")) ##D ##D # 2. Define paths: You only need the paths for one person: ##D paths = c( ##D umxPath(v1m0 = c("a1", 'c1', "e1")), ##D umxPath(means = c("wt")), ##D umxPath(c("a1", 'c1', "e1"), to = "wt", values=.2) ##D ) ##D m1 = umxTwinMaker("test", paths, mzData = mzData, dzData= dzData) ##D plot(m1, std= TRUE, means= FALSE) ##D plot(m1, means=FALSE, std=TRUE, strip=TRUE, splines="FALSE", max="intercept") ## End(Not run) # end dontrun # ================= # = An ACEv model = # ================= # Not complete paths = c( umxPath(v1m0 = c("A1", 'C1', "E1")), umxPath(v1m0 = c("A2", 'C2', "E2")), umxPath(v.m0 = c("l1", 'l2')), umxPath(v.m. = c("wt", "ht")), umxPath(c("A1", 'C1', "E1"), to = "l1", values= .2), umxPath(c("A2", 'C2', "E2"), to = "l2", values= .2), umxPath(c("l1", 'l2'), to = c("wt", "ht"), values= .2) ) cleanEx() nameEx("plot.percent") ### * plot.percent flush(stderr()); flush(stdout()) ### Name: plot.percent ### Title: Plot a percent change graph ### Aliases: plot.percent ### ** Examples # Percent needed to return to original value after 10% off fin_percent(-10) # Percent needed to return to original value after 10% on tmp = fin_percent(10) plot(tmp) # Percent needed to return to original value after 50% off 34.50 fin_percent(-50, value = 34.5, logY = FALSE) cleanEx() nameEx("power.ACE.test") ### * power.ACE.test flush(stderr()); flush(stdout()) ### Name: power.ACE.test ### Title: Test the power of an ACE model to detect paths of interest. ### Aliases: power.ACE.test ### ** Examples # ===================================================== # = N for .8 power to detect a^2 = .5 equal MZ and DZ = # ===================================================== power.ACE.test(AA = .5, CC = 0, update = "a") # Suggests n = 84 MZ and 94 DZ pairs. ## Not run: ##D # ================================ ##D # = Show power across range of N = ##D # ================================ ##D power.ACE.test(AA= .5, CC= 0, update = "a", search = TRUE) ##D ##D # Salutary note: You need well fitting models with correct betas in the data ##D # for power to be valid. ##D # tryHard helps ensure this, as does the default nSim= 4000 pair data. ##D # Power is important to get right, so I recommend using tryHard = "yes" (the default) ##D ##D # ===================== ##D # = Power to detect C = ##D # ===================== ##D ##D # 102 of each of MZ and DZ pairs for 80% power (default). ##D power.ACE.test(AA= .5, CC= .3, update = "c") ##D ##D # ========================================== ##D # = Set 'a' to a fixed, but non-zero value = ##D # ========================================== ##D ##D power.ACE.test(update= "a", value= sqrt(.2), AA= .5, CC= 0) ##D ##D # ======================================== ##D # = Drop More than one parameter (A & C) = ##D # ======================================== ##D # E vs AE: the hypothesis that twins show no familial similarity. ##D power.ACE.test(update = "a_after_dropping_c", AA= .5, CC= .3) ##D ##D # =================================================== ##D # = More power to detect A > 0 when more C present = ##D # =================================================== ##D ##D power.ACE.test(update = "a", AA= .5, CC= .0) ##D power.ACE.test(update = "a", AA= .5, CC= .3) ##D ##D # ==================================================== ##D # = More power to detect C > 0 when more A present? = ##D # ==================================================== ##D ##D power.ACE.test(update = "c", AA= .0, CC= .5) ##D power.ACE.test(update = "c", AA= .3, CC= .5) ##D ##D ##D # =================================== ##D # = Power with more DZs or more MZs = ##D # =================================== ##D ##D # Power about the same: total pairs with 2 MZs per DZ ##D power.ACE.test(MZ_DZ_ratio= 2/1, update= "a", AA= .3, CC= 0, method="ncp", tryHard="yes") ##D power.ACE.test(MZ_DZ_ratio= 1/2, update= "a", AA= .3, CC= 0, method="ncp", tryHard="yes") ##D power.ACE.test(update= "a", AA= .3, CC= 0, method="ncp", tryHard="yes") ##D ##D ##D # ===================================== ##D # = Compare ncp and empirical methods = ##D # ===================================== ##D ##D power.ACE.test(update= "a", AA= .5, CC= 0, method = "ncp") ##D # method = "ncp": For 80% power, you need 166 MZ and 166 DZ pairs ##D power.ACE.test(update= "a", AA= .5, CC= 0, method= "empirical") ##D # method= "empirical": For 80% power, you need 154 MZ and 154 DZ pairs ##D ##D # ==================== ##D # = Show off options = ##D # ==================== ##D # 1. tryHard ##D ##D power.ACE.test(update = "a", AA= .5, CC= 0, tryHard= "no") ##D ##D # 2. toggle optimizer ##D ##D power.ACE.test(update= "a", AA= .5, CC= 0, optimizer= "SLSQP") ##D ##D # 3. You can raise or lower the number of pairs used in the true model ##D # by varying nSim (twin pairs in the simulated data). ##D ##D power.ACE.test(update = "a", AA= .5, CC= 0, nSim= 20) ##D ## End(Not run) cleanEx() nameEx("print.RMSEA") ### * print.RMSEA flush(stderr()); flush(stdout()) ### Name: print.RMSEA ### Title: Print a RMSEA object ### Aliases: print.RMSEA ### ** Examples ## Not run: ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("One Factor", data = demoOneFactor, type= "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1.0) ##D ) ##D tmp = summary(m1) ##D RMSEA(tmp) ## End(Not run) cleanEx() nameEx("print.oddsratio") ### * print.oddsratio flush(stderr()); flush(stdout()) ### Name: print.oddsratio ### Title: Print a scale "oddsratio" object ### Aliases: print.oddsratio ### ** Examples oddsratio(grp1 = c(1, 10), grp2 = c(3, 10)) oddsratio(grp1 = c(3, 10), grp2 = c(1, 10)) oddsratio(grp1 = c(3, 10), grp2 = c(1, 10), alpha = .01) cleanEx() nameEx("print.percent") ### * print.percent flush(stderr()); flush(stdout()) ### Name: print.percent ### Title: Print a percent object ### Aliases: print.percent ### ** Examples # Percent needed to return to original value after 10% off fin_percent(-10) # Percent needed to return to original value after 10% on fin_percent(10) # Percent needed to return to original value after 50% off 34.50 fin_percent(-50, value = 34.5) cleanEx() nameEx("print.reliability") ### * print.reliability flush(stderr()); flush(stdout()) ### Name: print.reliability ### Title: Print a scale "reliability" object ### Aliases: print.reliability ### ** Examples # treat vehicle aspects as items of a test data(mtcars) reliability(cov(mtcars)) cleanEx() nameEx("prolific_check_ID") ### * prolific_check_ID flush(stderr()); flush(stdout()) ### Name: prolific_check_ID ### Title: Return PIDs in df ### Aliases: prolific_check_ID ### ** Examples # IDs = c("59d0ec2446447f00011edb063","5a08c9a7f2e3460001edb063f0254") # prolific_check_ID(IDs, df) cleanEx() nameEx("qm") ### * qm flush(stderr()); flush(stdout()) ### Name: qm ### Title: qm ### Aliases: qm ### ** Examples # simple example qm(0, 1 | 2, NA) ## Not run: ##D # clever example ##D M1 = M2 = diag(2) ##D qm(M1,c(4,5) | c(1,2),M2 | t(1:3)) ## End(Not run) cleanEx() nameEx("rad2deg") ### * rad2deg flush(stderr()); flush(stdout()) ### Name: rad2deg ### Title: Convert Radians to Degrees ### Aliases: rad2deg ### ** Examples rad2deg(pi) #180 degrees cleanEx() nameEx("reliability") ### * reliability flush(stderr()); flush(stdout()) ### Name: reliability ### Title: Report coefficient alpha (reliability) ### Aliases: reliability ### ** Examples # treat car data as items of a test data(mtcars) reliability(cov(mtcars)) cleanEx() nameEx("residuals.MxModel") ### * residuals.MxModel flush(stderr()); flush(stdout()) ### Name: residuals.MxModel ### Title: Get residuals from an MxModel ### Aliases: residuals.MxModel ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1.0) ##D ) ##D ##D # =================================== ##D # = Show the residuals of the model = ##D # =================================== ##D residuals(m1) ##D # | |x1 |x2 |x3 |x4 |x5 | ##D # |:--|:----|:-----|:----|:-----|:--| ##D # |x1 |. |. |0.01 |. |. | ##D # |x2 |. |. |0.01 |-0.01 |. | ##D # |x3 |0.01 |0.01 |. |. |. | ##D # |x4 |. |-0.01 |. |. |. | ##D # |x5 |. |. |. |. |. | ##D # [1] "nb: You can zoom in on bad values with, e.g. suppress = .01, which ##D # will hide values smaller than this. Use digits = to round" ##D ##D residuals(m1, digits = 3) ##D residuals(m1, digits = 3, suppress = .005) ##D # residuals are returned as an invisible object you can capture in a variable ##D a = residuals(m1); a ## End(Not run) cleanEx() nameEx("tmx_genotypic_effect") ### * tmx_genotypic_effect flush(stderr()); flush(stdout()) ### Name: tmx_genotypic_effect ### Title: Graphical display of genotypic effects. ### Aliases: tmx_genotypic_effect ### ** Examples library(umx); cleanEx() nameEx("tmx_is.identified") ### * tmx_is.identified flush(stderr()); flush(stdout()) ### Name: tmx_is.identified ### Title: Test if a factor model is identified ### Aliases: tmx_is.identified ### ** Examples tmx_is.identified(nVariables = 2, nFactors = 1) # FALSE tmx_is.identified(nVariables = 3, nFactors = 1) # TRUE tmx_is.identified(nVariables = 4, nFactors = 2) # FALSE tmx_is.identified(nVariables = 5, nFactors = 2) # TRUE cleanEx() nameEx("tmx_show.MxModel") ### * tmx_show.MxModel flush(stderr()); flush(stdout()) ### Name: tmx_show.MxModel ### Title: Show matrices of RAM models in a easy-to-learn-from format. ### Aliases: tmx_show.MxModel ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("tmx_sh", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D ##D # ============================================= ##D # = Show smart table on the web (the default) = ##D # ============================================= ##D tmx_show(m1, report = "html") ##D tmx_show(m1, what = "free", matrices = "thresholds") ##D tmx_show(m1, zero.print = "-") ##D ##D tmx_show(m1, report = "markdown") ##D tmx_show(m1, digits = 3, report = "markdown") ##D tmx_show(m1, matrices = "S", report = "markdown") ##D tmx_show(m1, what = "free" , report = "markdown") ##D tmx_show(m1, what = "labels", report = "markdown") ##D tmx_show(m1, what = "free", matrices = "A", report= "markdown") ## End(Not run) cleanEx() nameEx("umx") ### * umx flush(stderr()); flush(stdout()) ### Name: umx ### Title: Functions for Structural Equation Modeling in OpenMx ### Aliases: umx ### ** Examples ## Not run: ##D require("umx") ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type="cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G" , fixedAt= 1) ##D ) ##D ##D # umx added informative labels, created starting values, ##D # Ran your model (if autoRun is on), and displayed a brief summary ##D # including a comparison if you modified a model...! ##D ##D # umxSummary generates journal-ready fit information. ##D # We can choose std=T for standardized parameters and can also ##D # filter out some types of parameter (e.g. means or residuals) ##D ##D umxSummary(m1, std = TRUE, residuals=FALSE) ##D ##D # parameters() flexibly retrieves model coefficients. ##D # For example just G-loadings greater than |.3| and rounded to 2-digits. ##D parameters(m1, thresh="above", b=.3, pattern = "G_to.*", digits = 2) ##D ##D # (The built-in coef works as for lm etc.) ##D coef(m1) ##D ##D # ================== ##D # = Model updating = ##D # ================== ##D # umxModify modifies, renames, re-runs, and compares a model ##D # Can we set the loading of x1 on G to zero? (nope...) ##D m2 = umxModify(m1, "G_to_x1", name = "no_effect_of_g_on_X1", comparison = TRUE) ##D ##D # note1: umxSetParameters can do this with some additional flexibility ##D # note2 "comparison = TRUE" above is the same as calling ##D # umxCompare, like this ##D umxCompare(m1, m2) ##D ##D ##D # ======================== ##D # = Confidence intervals = ##D # ======================== ##D ##D # umxSummary() will show these, but you can also use the confint() function ##D confint(m1) # OpenMx's SE-based confidence intervals ##D ##D ##D # umxConfint formats everything you need nicely, and allows adding CIs (with parm=) ##D umxConfint(m1, parm = 'all', run = TRUE) # likelihood-based CIs ##D ##D # And make a Figure and open in browser ##D plot(m1, std = TRUE) ##D ##D # If you just want the .dot code returned set file = NA ##D plot(m1, std = TRUE, file = NA) ## End(Not run) cleanEx() nameEx("umxACE") ### * umxACE flush(stderr()); flush(stdout()) ### Name: umxACE ### Title: Build and run a 2-group Cholesky ACE twin model (univariate or ### multivariate) ### Aliases: umxACE ### ** Examples cleanEx() nameEx("umxACEcov") ### * umxACEcov flush(stderr()); flush(stdout()) ### Name: umxACEcov ### Title: Run a Cholesky with covariates that are random (in the expected ### covariance matrix) ### Aliases: umxACEcov ### ** Examples ## Not run: ##D # ============================================ ##D # = BMI, can't use Age as a random covariate = ##D # ============================================ ##D require(umx) ##D data(twinData) ##D # Replicate age to age1 & age2 ##D twinData$age1 = twinData$age2 = twinData$age ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D ##D # ===================================================================== ##D # = Trying to use identical var (like age) as a random cov is ILLEGAL = ##D # ===================================================================== ##D m1 = umxACEcov(selDVs = "bmi", selCovs = "age", dzData = dzData, mzData = mzData, sep = "") ##D ##D # ======================================================== ##D # = Use an lm-based age-residualisation approach instead = ##D # ======================================================== ##D ##D resid_data = umx_residualize("bmi", "age", suffixes = 1:2, twinData) ##D mzData = subset(resid_data, zygosity == "MZFF") ##D dzData = subset(resid_data, zygosity == "DZFF") ##D m2 = umxACE("resid", selDVs = "bmi", dzData = dzData, mzData = mzData, sep = "") ##D ##D # Univariate BMI without covariate of age for comparison ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D m3 = umxACE("raw_bmi", selDVs = "bmi", dzData = dzData, mzData = mzData, sep = "") ##D ##D # =========================================================================== ##D # = A bivariate example (need a dataset with a VIABLE COVARIATE to do this) = ##D # =========================================================================== ##D selDVs = "wt" # Set the DVs ##D selCovs = "ht" # Set the COV ##D selVars = umx_paste_names(selDVs, covNames = selCovs, sep = "", sep = 1:2) ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D m1 = umxACEcov(selDVs = selDVs, selCovs = selCovs, ##D dzData = dzData, mzData = mzData, sep = "", autoRun = TRUE ##D ) ## End(Not run) cleanEx() nameEx("umxACEv") ### * umxACEv flush(stderr()); flush(stdout()) ### Name: umxACEv ### Title: Build and run 2-group uni- or multi-variate ACE models based on ### VARIANCE (not paths). ### Aliases: umxACEv ### ** Examples ## Not run: ##D ##D # ============================== ##D # = Univariate model of weight = ##D # ============================== ##D require(umx) ##D data(twinData) # ?twinData from Australian twins. ##D ##D # Things to note: ACE model of weight will return a NEGATIVE variance in C. ##D # This is exactly why we have ACEv! It suggests we need a different model ##D # In this case: ADE. ##D # Other things to note: ##D # 1. umxACEv can figure out variable names: provide "sep", and selVars. ##D # Function generates: "wt" -> "wt1" "wt2" ##D # 2. umxACEv picks the variables it needs from the data. ##D ##D mzData = twinData[twinData$zygosity %in% "MZFF", ] ##D dzData = twinData[twinData$zygosity %in% "DZFF", ] ##D m1 = umxACEv(selDVs = "wt", sep = "", dzData = dzData, mzData = mzData) ##D ##D # A short cut (which is even shorter for "_T" twin data with "MZ"/"DZ" data in zygosity column is: ##D m1 = umxACEv(selDVs = "wt", sep = "", dzData = "MZFF", mzData = "DZFF", data = twinData) ##D # ======================================================== ##D # = Evidence for dominance ? (DZ correlation set to .25) = ##D # ======================================================== ##D m2 = umxACEv("ADE", selDVs = "wt", sep = "", dzData = dzData, mzData = mzData, dzCr = .25) ##D # note: the underlying matrices are still called A, C, and E. ##D # I catch this in the summary table, so columns are labeled A, D, and E. ##D # However, currently, the plot will say A, C, E. ##D ##D # We can modify this model, dropping dominance component (still called C), ##D # and see a comparison: ##D m3 = umxModify(m2, update = "C_r1c1", comparison = TRUE, name="AE") ##D # ========================================================= ##D # = Well done! Now you can make modify twin models in umx = ##D # ========================================================= ##D ##D # ============================ ##D # = How heritable is height? = ##D # ============================ ##D # ##D # Note: Height has a small variance. umx can typically picks good starts, ##D # but scaling is advisable. ##D # ##D require(umx) ##D # Load data and rescale height to cm (var in m too small) ##D data(twinData) # ?twinData from Australian twins. ##D twinData[,c("ht1", "ht2")]= twinData[,c("ht1", "ht2")]*100 ##D ##D mzData = twinData[twinData$zygosity %in% "MZFF", ] ##D dzData = twinData[twinData$zygosity %in% "DZFF", ] ##D m1 = umxACEv(selDVs = "ht", sep = "", dzData = dzData, mzData = mzData) ##D ##D umxSummary(m1, std = FALSE) # unstandardized ##D plot(m1) ##D ##D # tip: with report = "html", umxSummary can print the table to your browser! ##D # tip: You can turn off auto-plot with umx_set_auto_plot(FALSE) ##D ##D # ======================================================== ##D # = Evidence for dominance ? (DZ correlation set to .25) = ##D # ======================================================== ##D m2 = umxACEv("ADE", selDVs = "ht", dzCr = .25, sep="", dzData = dzData, mzData = mzData) ##D umxCompare(m2, m1) # Is ADE better? ##D umxSummary(m2, comparison = m1) # nb: though this is ADE, matrices are still called A,C,E ##D ##D # We can modify this model, dropping shared environment, and see a comparison: ##D m3 = umxModify(m2, update = "C_r1c1", comparison = TRUE, name = "AE") ##D ##D # ===================================== ##D # = Bivariate height and weight model = ##D # ===================================== ##D ##D data(twinData) ##D twinData[,c("ht1", "ht2")]= twinData[,c("ht1", "ht2")]*100 ##D mzData = twinData[twinData$zygosity %in% c("MZFF", "MZMM"), ] ##D dzData = twinData[twinData$zygosity %in% c("DZFF", "DZMM", "DZOS"), ] ##D m1 = umxACEv(selDVs = c("ht", "wt"), sep = '', dzData = dzData, mzData = mzData) ##D ##D # =================== ##D # = Ordinal example = ##D # =================== ##D require(umx) ##D data(twinData) ##D ##D # Cut bmi column to form ordinal obesity variables ##D cutPoints = quantile(twinData[, "bmi1"], probs = c(.5, .2), na.rm = TRUE) ##D obesityLevels = c('normal', 'overweight', 'obese') ##D twinData$obese1 = cut(twinData$bmi1, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) ##D twinData$obese2 = cut(twinData$bmi2, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) ##D ##D # Make the ordinal variables into mxFactors (ensure ordered is TRUE, and require levels) ##D twinData[, c("obese1", "obese2")] = umxFactor(twinData[, c("obese1", "obese2")]) ##D mzData = twinData[twinData$zygosity %in% "MZFF", ] ##D dzData = twinData[twinData$zygosity %in% "DZFF", ] ##D m2 = umxACEv(selDVs = "obese", dzData = dzData, mzData = mzData, sep = '') ##D ##D # FYI: Show mz, dz, and t1 and t2 have the same levels! ##D str(mzData) ##D ##D # ============================================ ##D # = Bivariate continuous and ordinal example = ##D # ============================================ ##D data(twinData) ##D # Cut bmi column to form ordinal obesity variables ##D ordDVs = c("obese1", "obese2") ##D obesityLevels = c('normal', 'overweight', 'obese') ##D cutPoints = quantile(twinData[, "bmi1"], probs = c(.5, .2), na.rm = TRUE) ##D twinData$obese1 = cut(twinData$bmi1, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) ##D twinData$obese2 = cut(twinData$bmi2, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) ##D ##D # Make the ordinal variables into ordered mxFactors ##D twinData[, ordDVs] = umxFactor(twinData[, ordDVs]) ##D ##D # umxACEv can trim out unused variables on its own ##D mzData = twinData[twinData$zygosity %in% "MZFF", ] ##D dzData = twinData[twinData$zygosity %in% "DZFF", ] ##D ##D m1 = umxACEv(selDVs = c("wt", "obese"), dzData = dzData, mzData = mzData, sep = '') ##D plot(m1) ##D ##D # ======================================= ##D # = Mixed continuous and binary example = ##D # ======================================= ##D require(umx) ##D data(twinData) ##D # Cut to form category of 20% obese subjects ##D # and make into mxFactors (ensure ordered is TRUE, and require levels) ##D cutPoints = quantile(twinData[, "bmi1"], probs = .2, na.rm = TRUE) ##D obesityLevels = c('normal', 'obese') ##D twinData$obese1 = cut(twinData$bmi1, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) ##D twinData$obese2 = cut(twinData$bmi2, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) ##D ordDVs = c("obese1", "obese2") ##D twinData[, ordDVs] = umxFactor(twinData[, ordDVs]) ##D ##D selDVs = c("wt", "obese") ##D mzData = twinData[twinData$zygosity %in% "MZFF", ] ##D dzData = twinData[twinData$zygosity %in% "DZFF", ] ##D m1 = umxACEv(selDVs = selDVs, dzData = dzData, mzData = mzData, sep = '') ##D umxSummary(m1) ##D ##D # =================================== ##D # Example with covariance data only = ##D # =================================== ##D ##D require(umx) ##D data(twinData) ##D selDVs = c("wt") ##D mz = cov(twinData[twinData$zygosity %in% "MZFF", tvars(selDVs, "")], use = "complete") ##D dz = cov(twinData[twinData$zygosity %in% "DZFF", tvars(selDVs, "")], use = "complete") ##D m1 = umxACEv(selDVs = selDVs, sep= "", dzData = dz, mzData= mz, numObsDZ= 569, numObsMZ= 351) ##D umxSummary(m1, std = FALSE) ## End(Not run) cleanEx() nameEx("umxAPA") ### * umxAPA flush(stderr()); flush(stdout()) ### Name: umxAPA ### Title: Creates nicely formatted journal-style summaries of models, ### p-values, data-frames and much more. ### Aliases: umxAPA summaryAPA ### ** Examples # ======================================== # = Report lm (regression/anova) results = # ======================================== umxAPA(lm(mpg ~ wt + disp, mtcars)) # Report all parameters umxAPA(lm(mpg ~ wt + disp, mtcars), "wt") # Just effect of weight umxAPA(lm(mpg ~ wt + disp, mtcars), std = TRUE) # Standardize model! ############### # GLM example # ############### df = mtcars df$mpg_thresh = 0 df$mpg_thresh[df$mpg > 16] = 1 m1 = glm(mpg_thresh ~ wt + gear,data = df, family = binomial) umxAPA(m1) ############### # A t-Test # ############### umxAPA(t.test(x = 1:10, y = c(7:20))) umxAPA(t.test(extra ~ group, data = sleep)) # ====================================================== # = Summarize DATA FRAME: Correlations + Means and SDs = # ====================================================== umxAPA(mtcars[,1:3]) umxAPA(mtcars[,1:3], digits = 3) umxAPA(mtcars[,1:3], lower = FALSE) ## Not run: ##D umxAPA(mtcars[,1:3], report = "html") ## End(Not run) # ========================================== # = CONFIDENCE INTERVAL from effect and se = # ========================================== umxAPA(.4, .3) # parameter 2 interpreted as SE # Input beta and CI, and back out the SE umxAPA(-0.030, c(-0.073, 0.013), digits = 3) # ==================== # = Format a p-value = # ==================== umxAPA(.0182613) # 0.02 umxAPA(.00018261) # < 0.001 umxAPA(.00018261, addComparison = FALSE) # 0.001 # ======================== # = Report a correlation = # ======================== data(twinData) tmp = subset(twinData, zygosity %in% c("MZFF", "MZMM")) m1 = cor.test(~ wt1 + wt2, data = tmp) umxAPA(m1) cleanEx() nameEx("umxAlgebra") ### * umxAlgebra flush(stderr()); flush(stdout()) ### Name: umxAlgebra ### Title: A simple wrapper for mxAlgebra with name as the first parameter ### for more readable compact code. ### Aliases: umxAlgebra ### ** Examples ## Not run: ##D A = umxMatrix("A", "Full", nrow = 3, ncol = 3, values=2) ##D B = umxAlgebra("B", A) ##D C = umxAlgebra(A + B, name = "C") ##D D = umxAlgebra(sin(C), name = "D") ##D m1 = mxRun(mxModel("AlgebraExample", A, B, C, D )) ##D mxEval(D, m1) ##D ##D x = umxAlgebra("circ", expression = 2 * pi) ##D class(x$formula) ##D x = mxAlgebra(name = "circ", 2 * pi) ##D class(x$formula) # "call" ## End(Not run) cleanEx() nameEx("umxBrownie") ### * umxBrownie flush(stderr()); flush(stdout()) ### Name: umxBrownie ### Title: A recipe Easter-egg for umx ### Aliases: umxBrownie ### ** Examples umxBrownie() cleanEx() nameEx("umxCI") ### * umxCI flush(stderr()); flush(stdout()) ### Name: umxCI ### Title: Add (and, optionally, run) confidence intervals to a structural ### model. ### Aliases: umxCI ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D m1$intervals # none yet - empty list() ##D m1 = umxCI(m1) ##D m1$intervals # $G_to_x1... ##D m1 = umxCI(m1, remove = TRUE) # remove CIs from the model and return it ##D m1$intervals # none again ##D ##D # Add CIs by name ##D parameters(m1, patt="_with_") ##D m1 = umxCI(m1, which = "x1_with_x1") ##D m1 = umxCI(m1, which = c("x1_with_x1", "x2_with_x2")) ##D m1 = umxCI(m1, regex = "x1_with_", run= "yes") ##D # lbound estimate ubound lbound Code ubound Code ##D # x1_with_x1 0.036 0.041 0.047 0 0 ##D ##D # ======================== ##D # = A twin model example = ##D # ======================== ##D data(twinData) ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D m1 = umxACE(selDVs = c("bmi1","bmi2"), dzData = dzData, mzData = mzData) ##D umxCI(m1, run = "show") # show what will be requested ##D umxCI(m1, run = "yes") # actually compute the CIs ##D # Don't force update of CIs, but if they were just added, then calculate them ##D umxCI(m1, run = "if necessary") ##D m1 = umxCI(m1, remove = TRUE) # remove them all ##D m1$intervals # none! ##D # Show what parameters are available to get CIs on ##D umxParameters(m1) ##D # Request a CI by label: ##D m1 = umxCI(m1, which = "a_r1c1", run = "yes") ## End(Not run) cleanEx() nameEx("umxCI_boot") ### * umxCI_boot flush(stderr()); flush(stdout()) ### Name: umxCI_boot ### Title: umxCI_boot ### Aliases: umxCI_boot ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1.0) ##D ) ##D ##D umxCI_boot(m1, type = "par.expected") ## End(Not run) cleanEx() nameEx("umxCP") ### * umxCP flush(stderr()); flush(stdout()) ### Name: umxCP ### Title: umxCP: Build and run a Common Pathway twin model ### Aliases: umxCP ### ** Examples ## Not run: ##D # ======================================================== ##D # = Run a 3-factor Common pathway twin model of 6 traits = ##D # ======================================================== ##D require(umx) ##D data(GFF) ##D mzData = subset(GFF, zyg_2grp == "MZ") ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D selDVs = c("gff", "fc", "qol", "hap", "sat", "AD") ##D m1 = umxCP(selDVs = selDVs, sep = "_T", nFac = 3, tryHard = "yes", ##D dzData = dzData, mzData = mzData) ##D ##D # Shortcut using "data =" ##D selDVs = c("gff", "fc", "qol", "hap", "sat", "AD") ##D m1 = umxCP(selDVs= selDVs, nFac= 3, data=GFF, zyg="zyg_2grp") ##D ##D # =================== ##D # = Do it using WLS = ##D # =================== ##D m2 = umxCP("new", selDVs = selDVs, sep = "_T", nFac = 3, optimizer = "SLSQP", ##D dzData = dzData, mzData = mzData, tryHard = "ordinal", ##D type= "DWLS", allContinuousMethod='marginals' ##D ) ##D ##D # ================================================= ##D # = Find and test dropping of shared environment = ##D # ================================================= ##D # Show all labels for C parameters ##D umxParameters(m1, patt = "^c") ##D # Test dropping the 9 specific and common-factor C paths ##D m2 = umxModify(m1, regex = "(cs_.*$)|(c_cp_)", name = "dropC", comp = TRUE) ##D umxSummaryCP(m2, comparison = m1, file = NA) ##D umxCompare(m1, m2) ##D ##D # ======================================= ##D # = Mixed continuous and binary example = ##D # ======================================= ##D data(GFF) ##D # Cut to form umxFactor 20% depressed DEP ##D cutPoints = quantile(GFF[, "AD_T1"], probs = .2, na.rm = TRUE) ##D ADLevels = c('normal', 'depressed') ##D GFF$DEP_T1 = cut(GFF$AD_T1, breaks = c(-Inf, cutPoints, Inf), labels = ADLevels) ##D GFF$DEP_T2 = cut(GFF$AD_T2, breaks = c(-Inf, cutPoints, Inf), labels = ADLevels) ##D ordDVs = c("DEP_T1", "DEP_T2") ##D GFF[, ordDVs] = umxFactor(GFF[, ordDVs]) ##D ##D selDVs = c("gff","fc","qol","hap","sat","DEP") ##D mzData = subset(GFF, zyg_2grp == "MZ") ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D ##D # umx_set_optimizer("NPSOL") ##D # umx_set_optimization_options("mvnRelEps", .01) ##D m1 = umxCP(selDVs = selDVs, sep = "_T", nFac = 3, dzData = dzData, mzData = mzData) ##D m2 = umxModify(m1, regex = "(cs_r[3-5]|c_cp_r[12])", name = "dropC", comp= TRUE) ##D ##D # Do it using WLS ##D m3 = umxCP(selDVs = selDVs, sep = "_T", nFac = 3, dzData = dzData, mzData = mzData, ##D tryHard = "ordinal", type= "DWLS") ##D # TODO umxCPL fix WLS here ##D # label at row 1 and column 1 of matrix 'top.binLabels'' in model 'CP3fac' : object 'Vtot' ##D ##D # ============================== ##D # = Correlated factors example = ##D # ============================== ##D # ==================== ##D # = DON'T USE THIS!!! = ##D # ==================== ##D data(GFF) ##D mzData = subset(GFF, zyg_2grp == "MZ") ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D selDVs = c("gff", "fc", "qol", "hap", "sat", "AD") ##D m1 = umxCP("base_model", selDVs = selDVs, sep = "_T", correlatedACE = TRUE, ##D dzData = dzData, mzData = mzData, nFac = 3, tryHard = "yes") ##D ##D # What are the ace covariance labels? (two ways to get) ##D umx_lower.tri(m1$top$a_cp$labels) ##D parameters(m1, patt = "[ace]_cp") ##D ##D # 1. Now allow a1 and a2 to correlate ##D m2=umxModify(m1,regex="a_cp_r2c1",name="a2_a1_cov",free=TRUE,tryHard="yes") ##D umxCompare(m2, m1) ##D ##D # 2. Drop all (a|c|e) correlations from a model ##D tmp= namez(umx_lower.tri(m2$top$a_cp$labels), "a_cp", replace= "[ace]_cp") ##D m3 = umxModify(m2, regex= tmp, comparison = TRUE) ## End(Not run) # end dontrun cleanEx() nameEx("umxCompare") ### * umxCompare flush(stderr()); flush(stdout()) ### Name: umxCompare ### Title: Print a comparison table of one or more 'mxModel()'s, formatted ### nicely. ### Aliases: umxCompare ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D ##D m2 = umxModify(m1, update = "G_to_x2", name = "drop_path_2_x2") ##D umxCompare(m1, m2) ##D umxCompare(m1, m2, report = "inline") # Add English-sentence descriptions ##D umxCompare(m1, m2, report = "html") # Open table in browser ##D ##D # Two comparison models ##D m3 = umxModify(m2, update = "G_to_x3", name = "drop_path_2_x2_and_3") ##D ##D umxCompare(m1, c(m2, m3)) ##D umxCompare(m1, c(m2, m3), compareWeightedAIC = TRUE) ##D umxCompare(c(m1, m2), c(m2, m3), all = TRUE) ##D ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("WLS", data = demoOneFactor, type = "DWLS", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D ##D m2 = umxModify(m1, update = "G_to_x2", name = "drop_path_2_x2") ##D umxCompare(m1, m2) ##D umxCompare(m1, m2, report = "inline") # Add English-sentence descriptions ##D umxCompare(m1, m2, report = "html") # Open table in browser ## End(Not run) cleanEx() nameEx("umxConfint") ### * umxConfint flush(stderr()); flush(stdout()) ### Name: umxConfint ### Title: Get confidence intervals from a umx model ### Aliases: umxConfint ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("OneFactor", data = demoOneFactor, type = "cov", ##D umxPath(from = "G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D ##D m1 = umxConfint(m1, run = TRUE) # There are no existing CI requests... ##D ##D # Add a CI request for "G_to_x1", run, and report. Save with this CI computed ##D m2 = umxConfint(m1, parm = "G_to_x1", run = TRUE) ##D ##D # Just print out any existing CIs ##D umxConfint(m2) ##D ##D # CI requests added for free matrix parameters. User prompted to set run = TRUE ##D m3 = umxConfint(m1, "all") ##D ##D # Run the requested CIs ##D m3 = umxConfint(m3, run = TRUE) ##D ##D # Run CIs for free one-headed (asymmetric) paths in RAM model. ##D # note: Deletes other existing requests, ##D tmp = umxConfint(m1, parm = "A", run = TRUE) ##D ##D # Wipe existing CIs, add G_to_x1 ##D tmp = umxConfint(m1, parm = "G_to_x1", run = TRUE, wipeExistingRequests = TRUE) ##D ##D # For some twin models, a "smart" mode is implemented ##D # note: only implemented for umxCP so far ##D m2 = umxConfint(m1, "smart") ## End(Not run) cleanEx() nameEx("umxCov2cor") ### * umxCov2cor flush(stderr()); flush(stdout()) ### Name: umxCov2cor ### Title: Convert a covariance matrix into a correlation matrix ### Aliases: umxCov2cor ### ** Examples umxCov2cor(cov(mtcars[,1:5])) cleanEx() nameEx("umxDiagnose") ### * umxDiagnose flush(stderr()); flush(stdout()) ### Name: umxDiagnose ### Title: Diagnose problems in a model - this is a work in progress. ### Aliases: umxDiagnose ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("OneFactor", data = demoOneFactor, type= "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D m1 = mxRun(m1) ##D umxSummary(m1, std = TRUE) ##D umxDiagnose(m1) ## End(Not run) cleanEx() nameEx("umxDiffMZ") ### * umxDiffMZ flush(stderr()); flush(stdout()) ### Name: umxDiffMZ ### Title: MZ differences method for testing evidence for causality. ### Aliases: umxDiffMZ ### ** Examples data(twinData) umxDiffMZ(x="ht", y="wt", labxy = c(-.5, 3), data = twinData, sep = "") umxDiffMZ(x="ht", y="wt", xylim = c( -2, 2), data = twinData, sep = "") cleanEx() nameEx("umxDiscTwin") ### * umxDiscTwin flush(stderr()); flush(stdout()) ### Name: umxDiscTwin ### Title: Intra-pair association in MZ, DZ twin models. (ALPHA quality!) ### Aliases: umxDiscTwin ### ** Examples ## Not run: ##D data(twinData) ##D # add to test must set FAMID umxDiscTwin(x = "ht", y = "wt", data = twinData, sep="") ##D tmp = umxDiscTwin(x = "ht", y = "wt", data = twinData, sep="", FAMID = "fam") ##D print(tmp, digits = 3) ## End(Not run) cleanEx() nameEx("umxDoC") ### * umxDoC flush(stderr()); flush(stdout()) ### Name: umxDoC ### Title: Build and run a 2-group Direction of Causation twin models. ### Aliases: umxDoC ### ** Examples ## Not run: ##D ##D # ======================== ##D # = Does Rain cause Mud? = ##D # ======================== ##D ##D # ================ ##D # = 1. Load Data = ##D # ================ ##D data(docData) ##D docData = umx_scale_wide_twin_data(c(var1, var2), docData, sep= "_T") ##D mzData = subset(docData, zygosity %in% c("MZFF", "MZMM")) ##D dzData = subset(docData, zygosity %in% c("DZFF", "DZMM")) ##D ##D # ======================================= ##D # = 2. Define manifests for var 1 and 2 = ##D # ======================================= ##D var1 = paste0("varA", 1:3) ##D var2 = paste0("varB", 1:3) ##D ##D # ======================================================= ##D # = 3. Make the non-causal (Cholesky) and causal models = ##D # ======================================================= ##D Chol = umxDoC(var1= var1, var2= var2, mzData= mzData, dzData= dzData, causal= FALSE) ##D # nb: DoC initially has causal paths fixed @0 ##D DoC = umxDoC(var1= var1, var2= var2, mzData= mzData, dzData= dzData, causal= TRUE) ##D a2b = umxModify(DoC, "a2b", free = TRUE, name = "a2b"); summary(a2b) ##D b2a = umxModify(DoC, "b2a", free = TRUE, name = "b2a"); summary(b2a) ##D Recip = umxModify(DoC, c("a2b", "b2a"), free = TRUE, name = "Recip"); summary(Recip) ##D ##D # Compare fits ##D umxCompare(Chol, c(a2b, b2a, Recip)) ##D ##D # ========================================== ##D # = Alternative call with data in one file = ##D # ========================================== ##D data(docData) ##D docData = umx_scale_wide_twin_data(c(var1, var2), docData, sep= "_T") ##D DoC = umxDoC(var1= paste0("varA", 1:3), var2= paste0("varB", 1:3), ##D mzData= c("MZFF", "MZMM"), dzData= c("DZFF", "DZMM"), data = docData ##D ) ## End(Not run) cleanEx() nameEx("umxDoCp") ### * umxDoCp flush(stderr()); flush(stdout()) ### Name: umxDoCp ### Title: Make a direction of causation model based on umxPath statements ### Aliases: umxDoCp ### ** Examples ## Not run: ##D # ================ ##D # = 1. Load Data = ##D # ================ ##D data(docData) ##D var1 = paste0("varA", 1:3) ##D var2 = paste0("varB", 1:3) ##D tmp = umx_scale_wide_twin_data(varsToScale= c(var1, var2), sep= "_T", data= docData) ##D mzData = subset(docData, zygosity %in% c("MZFF", "MZMM")) ##D dzData = subset(docData, zygosity %in% c("DZFF", "DZMM")) ##D m1 = umxDoCp(var1, var2, mzData= mzData, dzData= dzData, sep = "_T", causal= TRUE) ##D ## End(Not run) cleanEx() nameEx("umxEFA") ### * umxEFA flush(stderr()); flush(stdout()) ### Name: umxEFA ### Title: FIML-based Exploratory Factor Analysis (EFA) ### Aliases: umxEFA umxFactanal ### ** Examples ## Not run: ##D myVars = c("mpg", "disp", "hp", "wt", "qsec") ##D m1 = umxEFA(mtcars[, myVars], factors = 2, rotation = "promax") ##D # By default, returns the model ##D umx_is_MxModel(m1) # TRUE ##D # The loadings are stashed in the model: ##D loadings(m1) ##D ##D # Formula interface in umxEFA ##D m2 = umxEFA(~ mpg + disp + hp + wt + qsec, factors = 2, rotation = "promax", data = mtcars) ##D loadings(m2) ##D ##D # base-R factanal Formula interface for comparison ##D m2 = factanal(~ mpg + disp + hp + wt + qsec, factors = 2, rotation = "promax", data = mtcars) ##D loadings(m2) ##D ##D # Return the loadings object ##D x = umxEFA(mtcars[, myVars], factors = 2, return = "loadings") ##D names(x) # "loadings" "rotmat" ##D ##D # scores requested, so these will be returned ##D x = umxEFA(name = "score", factors = "g", data = mtcars[, myVars], scores= "Regression") ##D head(x) ##D # g ##D # 1 -0.48059346 ##D # 2 -0.42354000 ##D # 3 -0.87078110 ##D ##D m1 = umxEFA(myVars, factors = 2, data = mtcars, rotation = "promax") ##D m1 = umxEFA(name = "named", factors = "g", data = mtcars[, myVars]) ##D m1 = umxEFA(name = "by_number", factors = 2, rotation = "promax", data = mtcars[, myVars]) ##D ## End(Not run) cleanEx() nameEx("umxEquate") ### * umxEquate flush(stderr()); flush(stdout()) ### Name: umxEquate ### Title: umxEquate: Equate two or more paths ### Aliases: umxEquate ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D # By default, umxEquate just equates master and slave labels: doesn't run model ##D m2 = umxEquate(m1, a = "G_to_x1", b = "G_to_x2", name = "Eq x1 x2 loadings") ##D ##D # Set autoRun = TRUE and comparison = TRUE to run and output a comparison ##D m2 = umxEquate(m1, autoRun = TRUE, comparison = TRUE, name = "Eq_x1_x2", ##D a = "G_to_x1", b = "G_to_x2" ##D ) ##D ##D # rename the equated paths ##D m2 = umxEquate(m1, autoRun = TRUE, comparison = TRUE, name = "Eq_x1_x2", ##D a = "G_to_x1", b = "G_to_x2", newlabels = c("equated") ##D ) ##D parameters(m2) ## End(Not run) cleanEx() nameEx("umxExamples") ### * umxExamples flush(stderr()); flush(stdout()) ### Name: umxExamples ### Title: Example code from Twin Research and Human Genetics Paper on umx ### Aliases: umxExamples umxExampleCode_TRHGpaper ### ** Examples ## Not run: ##D ##D # ========================================================================== ##D # = Example code from Twin Research and Human Genetics Paper on umx(model) = ##D # ========================================================================== ##D ##D # Installing umx can be done using the R-code: ##D install.packages("umx") ##D # load as usual ##D library("umx") ##D ##D # The current package version can be shown with: ##D umxVersion("umx") ##D ##D # Get the latest NPSOL and multi-core build of OpenMx ##D install.OpenMx("NPSOL") ##D ##D # Bleeding edge version of OpenMx for MacOS ##D install.OpenMx("travis") ##D ##D # ============ ##D # = CFA Code = ##D # ============ ##D ##D # Load the umx library (this is assumed in subsequent examples ##D library("umx") ##D ##D # Load demo data consisting of 5 correlated variables, x1:x5 ##D data(demoOneFactor) ##D ##D # Create a list of the manifest variables for use in specifying the model ##D manifests = paste0("x", 1:5) # 'x1', 'x2', ...'x5' ##D ##D # Create model cfa1, with name 'CFA', data demoOneFactor, and the CFA paths. ##D ##D cfa1 = umxRAM("CFA", data = demoOneFactor, ##D # Create latent variable 'G', with fixed variance of 1 and mean of 0 ##D umxPath(v1m0 = "G"), ##D # Create 5 manifest variables, x1:x5, with free variance and mean ##D umxPath(v.m. = manifests), ##D # Create 1-headed paths from G to each of the manifests ##D umxPath("G", to = manifests) ##D ) ##D ##D # ==================== ##D # = Parameter labels = ##D # ==================== ##D ##D x = xmuLabel(mxMatrix(name="means", "Full", ncol = 2, nrow = 2)) ##D x$labels ##D ##D # ======== ##D # = Plot = ##D # ======== ##D ##D plot(cfa1, means = FALSE, fixed = TRUE) ##D plot(cfa1, std = TRUE, digits = 3, resid= 'line') ##D ##D ##D m1 = umxRAM("play", data = c("A", "B", "C"), ##D umxPath(unique.pairs = c("A", "B", "C")) ##D ) ##D ##D # ============================================== ##D # = Inspecting model parameters and residuals. = ##D # ============================================== ##D ##D # Show parameters, below .1, with label containing `x2' ##D parameters(cfa1, "above", .5, pattern= "x2") ##D ##D residuals(cfa1, suppress = .005) ##D ##D # ================================== ##D # = Modifying and comparing models = ##D # ================================== ##D ##D # Variable names in the Duncan data ##D dimnames = c("RespOccAsp", "RespEduAsp", "RespParAsp", "RespIQ", "RespSES", ##D "FrndOccAsp", "FrndEduAsp", "FrndParAsp", "FrndIQ", "FrndSES") ##D # lower-triangle of correlations among these variables ##D tmp = c( ##D 0.6247, ##D 0.2137, 0.2742, ##D 0.4105, 0.4043, 0.1839, ##D 0.3240, 0.4047, 0.0489, 0.2220, ##D 0.3269, 0.3669, 0.1124, 0.2903, 0.3054, ##D 0.4216, 0.3275, 0.0839, 0.2598, 0.2786, 0.6404, ##D 0.0760, 0.0702, 0.1147, 0.1021, 0.0931, 0.2784, 0.1988, ##D 0.2995, 0.2863, 0.0782, 0.3355, 0.2302, 0.5191, 0.5007, 0.2087, ##D 0.2930, 0.2407, 0.0186, 0.1861, 0.2707, 0.4105, 0.3607, -0.0438, 0.2950 ##D ) ##D ##D # Use the umx_lower2full function to create a full correlation matrix ##D duncanCov = umx_lower2full(tmp, diag = FALSE, dimnames = dimnames) ##D ##D # Turn the duncan data into an mxData object for the model ##D duncanCov = mxData(duncanCov, type = "cov", numObs = 300) ##D ##D respondentFormants = c("RespSES", "FrndSES", "RespIQ", "RespParAsp") ##D friendFormants = c("FrndSES", "RespSES", "FrndIQ", "FrndParAsp") ##D latentAspiration = c("RespLatentAsp", "FrndLatentAsp") ##D respondentOutcomeAsp = c("RespOccAsp", "RespEduAsp") ##D friendOutcomeAsp = c("FrndOccAsp", "FrndEduAsp") ##D ##D ##D duncan1 = umxRAM("Duncan", data = duncanCov, ##D # Working from the left of the model, as laid out in the figure, to right... ##D ##D # 1. Add all distinct paths between variables to allow the ##D # exogenous manifests to covary with each other. ##D umxPath(unique.bivariate = c(friendFormants, respondentFormants)), ##D ##D # 2. Add variances for the exogenous manifests, ##D # These are assumed to be error-free in this model, ##D # and are fixed at their known value). ##D umxPath(var = c(friendFormants, respondentFormants), fixedAt = 1), ##D ##D # 3. Paths from IQ, SES, and parental aspiration ##D # to latent aspiration for Respondents: ##D umxPath(respondentFormants, to = "RespLatentAsp"), ##D # And same for friends ##D umxPath(friendFormants, to = "FrndLatentAsp"), ##D ##D # 4. Add residual variance for the two aspiration latent traits. ##D umxPath(var = latentAspiration), ##D ##D # 5. Allow the latent traits each influence the other. ##D # This is done using fromEach, and the values are ##D # bounded to improve stability. ##D # note: Using one-label would equate these 2 influences ##D umxPath(fromEach = latentAspiration, lbound = 0, ubound = 1), ##D ##D # 6. Allow latent aspiration to affect respondent's ##D # occupational & educational aspiration. ##D # note: firstAt = 1 is used to provide scale to the latent variables. ##D umxPath("RespLatentAsp", to = respondentOutcomeAsp, firstAt = 1), ##D ##D # And their friends ##D umxPath("FrndLatentAsp", to = friendOutcomeAsp, firstAt = 1), ##D ##D # 7. Finally, on the right hand side of figure, we add ##D # residual variance for the endogenous manifests. ##D umxPath(var = c(respondentOutcomeAsp, friendOutcomeAsp)) ##D ) ##D ##D # ==================== ##D # = Modifying models = ##D # ==================== ##D ##D # Collect a list of paths to drop ##D pathList = c("RespLatentAsp_to_FrndLatentAsp", "FrndLatentAsp_to_RespLatentAsp") ##D ##D # Modify the model duncan1, requesting a comparison table: ##D duncan2 = umxModify(duncan1, update = pathList, name = "No_influence", comparison = TRUE) ##D ##D # An example using regex, to drop all paths beginning "G_to_" ##D cfa2 = umxModify(cfa1, regex = "^G_to.*") ##D ##D # ==================== ##D # = Comparing models = ##D # ==================== ##D ##D umxCompare(duncan1, duncan2, report = "inline") ##D ##D # To open the output as an html table in a browser, say: ##D umxCompare(duncan1, duncan2, report = "html") ##D ##D # ============================= ##D # = Equating model parameters = ##D # ============================= ##D ##D parameters(duncan1, pattern = "IQ_to_") ##D ##D ##D duncan3 = umxModify(duncan1, name = "Equate IQ effect", comparison = TRUE, ##D master = "RespIQ_to_RespLatentAsp", ##D update = "FrndIQ_to_FrndLatentAsp" ##D ) ##D ##D # ================ ##D # = ACE examples = ##D # ================ ##D ##D require(umx); ##D # open the built in dataset of Australian height and weight twin data ##D data("twinData") ##D selDVs = c("wt") ##D dz = twinData[twinData$zygosity == "DZFF", ] ##D mz = twinData[twinData$zygosity == "MZFF", ] ##D ##D ACE1 = umxACE(selDVs = selDVs, dzData = dz, mzData = mz, sep = "") ##D ACE2 = umxModify(ACE1, update = "c_r1c1", name = "dropC") ##D umxSummary(ACE1, std = FALSE, report = 'html', digits = 3, comparison = ACE2) ##D parameters(ACE1) ##D ##D ACE2 = umxModify(ACE1, update = "c_r1c1", name = "dropC") ##D ##D # ================================ ##D # = Example Common Pathway model = ##D # ================================ ##D ##D # load twin data built into umx ##D data("twinData") ##D ##D # Selecting the 'ht' and 'wt' variables ##D selDVs = c("ht", "wt") ##D mzData = subset(twinData, zygosity == "MZFF",) ##D dzData = subset(twinData, zygosity == "DZFF",) ##D ##D # Run and report a common-pathway model ##D CP1 = umxCP(selDVs = selDVs, dzData = dzData, mzData = mzData, suffix = "") ##D ##D paths = c("c_cp_r1c1", "cs_r1c1", "cs_r2c2") ##D CP2 = umxModify(CP1, update = paths, name = "dropC", comparison = TRUE) ##D ##D CP2 = umxModify(CP1, regex = "(^cs_)|(^c_cp_)", name = "dropC") ##D umxSummary(CP2, comparison = CP1) ##D ##D # ==================================== ##D # = Example Gene x environment model = ##D # ==================================== ##D ##D data("twinData") ##D twinData$age1 = twinData$age2 = twinData$age ##D # Define the DV and definition variables ##D selDVs = c("bmi1", "bmi2") ##D selDefs = c("age1", "age2") ##D selVars = c(selDVs, selDefs) ##D ##D # Create datasets ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D ##D # Build, run and report the GxE model using selected DV and moderator ##D # umxGxE will remove and report rows with missing data in definition variables. ##D GE1 = umxGxE(selDVs = selDVs, selDefs = selDefs, ##D dzData = dzData, mzData = mzData, dropMissingDef = TRUE) ##D ##D # Shift the legend to the top right ##D umxSummary(GE1, location = "topright") ##D ##D # plot standardized and raw output in separate graphs ##D umxSummary(GE1, separateGraphs = TRUE) ##D ##D GE2 = umxModify(GE1, update = "am_r1c1", comparison = TRUE) ##D umxReduce(GE1) ##D ##D # ================================= ##D # = Example GxE windowed analysis = ##D # ================================= ##D ##D require(umx); ##D data("twinData") ##D mod = "age" ##D selDVs = c("bmi1", "bmi2") ##D ##D # select the younger cohort of twins ##D tmpTwin = twinData[twinData$cohort == "younger", ] ##D # Drop twins with missing moderator ##D tmpTwin = tmpTwin[!is.na(tmpTwin[mod]), ] ##D mzData = subset(tmpTwin, zygosity == "MZFF", c(selDVs, mod)) ##D dzData = subset(tmpTwin, zygosity == "DZFF", c(selDVs, mod)) ##D # toggle autoplot off, so we don't plot every level of the moderator ##D umx_set_auto_plot(FALSE) ##D umxGxE_window(selDVs = selDVs, moderator = mod, mzData = mzData, dzData = dzData) ##D umx_set_auto_plot(TRUE) ##D ## End(Not run) cleanEx() nameEx("umxExpCov") ### * umxExpCov flush(stderr()); flush(stdout()) ### Name: umxExpCov ### Title: Get the expected vcov matrix ### Aliases: umxExpCov vcov.MxModel ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D )#' ##D vcov(m1) # supplied by OpenMx ##D umxExpCov(m1, digits = 3) ##D ## End(Not run) cleanEx() nameEx("umxExpMeans") ### * umxExpMeans flush(stderr()); flush(stdout()) ### Name: umxExpMeans ### Title: Extract the expected means matrix from an 'mxModel()' ### Aliases: umxExpMeans ### ** Examples ## Not run: ##D ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, ##D umxPath("G", to = manifests), ##D umxPath(v.m. = manifests), ##D umxPath(v1m0 = "G") ##D ) ##D ##D umxExpMeans(m1) ##D umxExpMeans(m1, digits = 3) ## End(Not run) cleanEx() nameEx("umxFactor") ### * umxFactor flush(stderr()); flush(stdout()) ### Name: umxFactor ### Title: umxFactor ### Aliases: umxFactor umx_factor ### ** Examples umxFactor(letters) umxFactor(letters, verbose = TRUE) # report coercions umxFactor(letters, ordered = FALSE) # non-ordered factor like factor(x) # Dataframe example: x = umx_factor(mtcars[,c("cyl", "am")], ordered = FALSE); str(x) # ================= # = Twin example: = # ================= data(twinData) tmp = twinData[, c("bmi1", "bmi2")] tmp$bmi1[tmp$bmi1 <= 22] = 22 tmp$bmi2[tmp$bmi2 <= 22] = 22 # remember to factor _before_ breaking into MZ and DZ groups x = umxFactor(tmp, sep = ""); str(x) xmu_check_levels_identical(x, "bmi", sep="") # Simple example to check behavior x = round(10 * rnorm(1000, mean = -.2)) y = round(5 * rnorm(1000)) x[x < 0] = 0; y[y < 0] = 0 jnk = umxFactor(x); str(jnk) df = data.frame(x = x, y = y) jnk = umxFactor(df); str(jnk) cleanEx() nameEx("umxFactorScores") ### * umxFactorScores flush(stderr()); flush(stdout()) ### Name: umxFactorScores ### Title: Return factor scores from a model as an easily consumable ### dataframe. ### Aliases: umxFactorScores ### ** Examples ## Not run: ##D m1 = umxEFA(mtcars, factors = 2) ##D x = umxFactorScores(m1, type = 'Regression', minManifests = 3) ##D ##D # ========================================================================= ##D # = histogram of F1 and plot of F1 against F2 showing they are orthogonal = ##D # ========================================================================= ##D hist(x$F1) ##D plot(F1 ~ F2, data = x) ##D ##D m1 = umxEFA(mtcars, factors = 1) ##D x = umxFactorScores(m1, type = 'Regression', minManifests = 3) ##D x ## End(Not run) cleanEx() nameEx("umxFitIndices") ### * umxFitIndices flush(stderr()); flush(stdout()) ### Name: umxFitIndices ### Title: Get additional fit-indices for a model with umxFitIndices ### Aliases: umxFitIndices ### ** Examples ## Not run: ##D library(umx) ##D data(demoOneFactor) ##D latents = c("G") ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", ##D data = mxData(cov(demoOneFactor), type = "cov", numObs = 500), ##D umxPath(latents, to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = latents, fixedAt = 1) ##D ) ##D umxFitIndices(m1) ##D ##D # And with raw data ##D m2 = umxRAM("m1", data = demoOneFactor, ##D umxPath(latents, to = manifests), ##D umxPath(v.m. = manifests), ##D umxPath(v1m0 = latents) ##D ) ##D umxFitIndices(m1, refModels = mxRefModels(m2, run = TRUE)) ## End(Not run) cleanEx() nameEx("umxFixAll") ### * umxFixAll flush(stderr()); flush(stdout()) ### Name: umxFixAll ### Title: umxFixAll: Fix all free parameters ### Aliases: umxFixAll ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("OneFactor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D m2 = umxFixAll(m1, run = TRUE, verbose = TRUE) ##D mxCompare(m1, m2) ##D ## End(Not run) cleanEx() nameEx("umxGetLatents") ### * umxGetLatents flush(stderr()); flush(stdout()) ### Name: umxGetLatents ### Title: Get the latentVars from a RAM model ### Aliases: umxGetLatents ### ** Examples ## Not run: ##D library(umx) ##D # Create two sets of data in which X & Y correlate ~ .4 in both datasets. ##D manifests = c("x", "y") ##D tmp = umx_make_TwinData(nMZpairs = 100, nDZpairs = 150, ##D AA = 0, CC = .4, EE = .6, varNames = manifests) ##D ##D grp1 = tmp[tmp$zygosity == "MZ", manifests] ##D g1Data = mxData(cov(grp1), type = "cov", numObs = nrow(grp1), means=umx_means(grp1)) ##D ##D grp2 = tmp[tmp$zygosity == "DZ", manifests] ##D g2Data = mxData(cov(grp2), type = "cov", numObs = nrow(grp2), means=umx_means(grp2)) ##D # Model 1 (could add autoRun = FALSE if you don't want to run this as it is being built) ##D m1 = umxRAM("m1", data = g1Data, ##D umxPath("x", to = "y", labels = "beta"), ##D umxPath(var = manifests, labels = c("Var_x", "Resid_y_grp1")), ##D umxPath(means = manifests, labels = c("Mean_x", "Mean_y")) ##D ) ##D ##D # Model 2 ##D m2 = umxRAM("m2", data = g2Data, ##D umxPath("x", to = "y", labels = "beta"), ##D umxPath(var = manifests, labels=c("Var_x", "Resid_y_grp2")), ##D umxPath(means = manifests, labels=c("Mean_x", "Mean_y")) ##D ) ##D ##D m3 = umxSuperModel('top', m1, m2) ##D umxGetLatents(m3) ##D umxGetLatents(m3, targetModel = "m1") ## End(Not run) cleanEx() nameEx("umxGetManifests") ### * umxGetManifests flush(stderr()); flush(stdout()) ### Name: umxGetManifests ### Title: Get the manifestVars from a RAM model ### Aliases: umxGetManifests ### ** Examples ## Not run: ##D library(umx) ##D # Create two sets of data in which X & Y correlate ~ .4 in both datasets. ##D manifests = c("x", "y") ##D tmp = umx_make_TwinData(nMZpairs = 100, nDZpairs = 150, ##D AA = 0, CC = .4, EE = .6, varNames = manifests) ##D ##D grp1 = tmp[tmp$zygosity == "MZ", manifests] ##D g1Data = mxData(cov(grp1), type = "cov", numObs = nrow(grp1), means=umx_means(grp1)) ##D ##D grp2 = tmp[tmp$zygosity == "DZ", manifests] ##D g2Data = mxData(cov(grp2), type = "cov", numObs = nrow(grp2), means=umx_means(grp2)) ##D # Model 1 (could add autoRun = FALSE if you don't want to run this as it is being built) ##D m1 = umxRAM("m1", data = g1Data, ##D umxPath("x", to = "y", labels = "beta"), ##D umxPath(var = manifests, labels = c("Var_x", "Resid_y_grp1")), ##D umxPath(means = manifests, labels = c("Mean_x", "Mean_y")) ##D ) ##D ##D # Model 2 ##D m2 = umxRAM("m2", data = g2Data, ##D umxPath("x", to = "y", labels = "beta"), ##D umxPath(var = manifests, labels=c("Var_x", "Resid_y_grp2")), ##D umxPath(means = manifests, labels=c("Mean_x", "Mean_y")) ##D ) ##D ##D m3 = umxSuperModel('top', m1, m2) ##D umxGetManifests(m3) ##D umxGetManifests(m3, targetModel = "m1") ## End(Not run) cleanEx() nameEx("umxGetModel") ### * umxGetModel flush(stderr()); flush(stdout()) ### Name: umxGetModel ### Title: Used to get a RAM submodel by name ### Aliases: umxGetModel ### ** Examples ## Not run: ##D library(umx) ##D # Create two sets of data in which X & Y correlate ~ .4 in both datasets. ##D manifests = c("x", "y") ##D tmp = umx_make_TwinData(nMZpairs = 100, nDZpairs = 150, ##D AA = 0, CC = .4, EE = .6, varNames = manifests) ##D ##D grp1 = tmp[tmp$zygosity == "MZ", manifests] ##D g1Data = mxData(cov(grp1), type = "cov", numObs = nrow(grp1), means=umx_means(grp1)) ##D ##D grp2 = tmp[tmp$zygosity == "DZ", manifests] ##D g2Data = mxData(cov(grp2), type = "cov", numObs = nrow(grp2), means=umx_means(grp2)) ##D # Model 1 (could add autoRun = FALSE if you don't want to run this as it is being built) ##D m1 = umxRAM("m1", data = g1Data, ##D umxPath("x", to = "y", labels = "beta"), ##D umxPath(var = manifests, labels = c("Var_x", "Resid_y_grp1")), ##D umxPath(means = manifests, labels = c("Mean_x", "Mean_y")) ##D ) ##D ##D # Model 2 ##D m2 = umxRAM("m2", data = g2Data, ##D umxPath("x", to = "y", labels = "beta"), ##D umxPath(var = manifests, labels = c("Var_x", "Resid_y_grp2")), ##D umxPath(means = manifests, labels = c("Mean_x", "Mean_y")) ##D ) ##D ##D m3 = umxSuperModel('top', m1, m2) ##D umxGetModel(m3) ##D umxGetModel(m3, targetModel = "m1") ## End(Not run) cleanEx() nameEx("umxGetParameters") ### * umxGetParameters flush(stderr()); flush(stdout()) ### Name: umxGetParameters ### Title: Get parameters from a model, with support for pattern matching! ### Aliases: umxGetParameters ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D ##D # Show all parameters ##D umxGetParameters(m1) ##D umxGetParameters(m1, free = TRUE) # Only free parameters ##D umxGetParameters(m1, free = FALSE) # Only fixed parameters ##D # Complex regex pattern ##D umxGetParameters(m1, regex = "x[1-3]_with_x[2-5]", free = TRUE) ## End(Not run) cleanEx() nameEx("umxGxE") ### * umxGxE flush(stderr()); flush(stdout()) ### Name: umxGxE ### Title: umxGxE: Implements ACE models with moderation of paths, e.g. by ### SES. ### Aliases: umxGxE ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D twinData$age1 = twinData$age2 = twinData$age ##D selDVs = "bmi" ##D selDefs = "age" ##D mzData = subset(twinData, zygosity == "MZFF")[1:100,] ##D dzData = subset(twinData, zygosity == "DZFF")[1:100,] ##D m1 = umxGxE(selDVs= "bmi", selDefs= "age", sep= "", dzData= dzData, mzData= mzData, tryHard= "yes") ##D ##D # Select the data on the fly with data= and zygosity levels ##D m1 = umxGxE(selDVs= "bmi", selDefs= "age", sep="", dzData= "DZFF", mzData= "MZFF", data= twinData) ##D ##D # =============================================================== ##D # = example with Twins having different values of the moderator = ##D # =============================================================== ##D ##D twinData$age1 = twinData$age2 = twinData$age ##D tmp = twinData ##D tmp$age2 = tmp$age2 +rnorm(n=length(tmp$age2)) ##D selDVs = "bmi" ##D selDefs = "age" ##D mzData = subset(tmp, zygosity == "MZFF") ##D dzData = subset(tmp, zygosity == "DZFF") ##D m1 = umxGxE(selDVs= "bmi", selDefs= "age", sep= "", dzData= dzData, mzData= mzData, tryHard= "yes") ##D ##D # ==================================== ##D # = Controlling output of umxSummary = ##D # ==================================== ##D umxSummaryGxE(m1) ##D umxSummary(m1, location = "topright") ##D umxSummary(m1, separateGraphs = TRUE) ##D ##D m2 = umxModify(m1, regex = "am_.*", comparison = TRUE, tryHard = "yes") ##D ##D # umxReduce knows how to test all relevant hypotheses for GxE models, ##D # reporting these in a nice table. ##D umxReduce(m1) ## End(Not run) cleanEx() nameEx("umxGxE_window") ### * umxGxE_window flush(stderr()); flush(stdout()) ### Name: umxGxE_window ### Title: Implement the moving-window form of GxE analysis. ### Aliases: umxGxE_window ### ** Examples ## Not run: ##D library(umx); ##D ##D # ============================== ##D # = 1. Open and clean the data = ##D # ============================== ##D # umxGxE_window takes a data.frame consisting of a moderator and two DV columns: one for each twin. ##D # The model assumes two groups (MZ and DZ). Moderator can't be missing ##D mod = "age" # The full name of the moderator column in the dataset ##D selDVs = c("bmi1", "bmi2") # The DV for twin 1 and twin 2 ##D data(twinData) # Dataset of Australian twins, built into OpenMx ##D # The twinData consist of two cohorts: "younger" and "older". ##D # zygosity is a factor. levels = MZFF, MZMM, DZFF, DZMM, DZOS. ##D ##D # Delete missing moderator rows ##D twinData = twinData[!is.na(twinData[mod]), ] ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D ##D # ======================== ##D # = 2. Run the analyses! = ##D # ======================== ##D # Run and plot for specified windows (in this case just 1927) ##D umxGxE_window(selDVs = selDVs, moderator = mod, mzData = mzData, dzData = dzData, ##D target = 40, plotWindow = TRUE) ##D ##D umxGxE_window(selDVs = "bmi", sep="", moderator = mod, mzData = mzData, dzData = dzData, ##D target = 40, plotWindow = TRUE, tryHard = "yes") ##D ##D # Run with FIML (default) uses all information ##D umxGxE_window(selDVs = "bmi", sep="", moderator = "age", mzData = mzData, dzData = dzData) ##D umxGxE_window(selDVs="bmi", sep="", moderator="age", mzData=mzData, dzData=dzData, tryHard="yes") ##D ##D # Run creating weighted covariance matrices (excludes missing data) ##D umxGxE_window(selDVs = "bmi", sep="", moderator= "age", mzData = mzData, dzData = dzData, ##D weightCov = TRUE) ## End(Not run) cleanEx() nameEx("umxGxEbiv") ### * umxGxEbiv flush(stderr()); flush(stdout()) ### Name: umxGxEbiv ### Title: Purcell (2002) Bivariate GxE model: Suitable when twins differ ### on the moderator. ### Aliases: umxGxEbiv ### ** Examples require(umx) data(twinData) selDVs = "wt" selDefs = "ht" df = umx_scale_wide_twin_data(twinData, varsToScale = c("ht", "wt"), sep = "") mzData = subset(df, zygosity %in% c("MZFF", "MZMM")) dzData = subset(df, zygosity %in% c("DZFF", "DZMM", "DZOS")) ## Not run: ##D m1 = umxGxEbiv(selDVs = selDVs, selDefs = selDefs, ##D dzData = dzData, mzData = mzData, sep = "", dropMissingDef = TRUE) ##D ##D # Plot Moderation ##D umxSummaryGxEbiv(m1) ##D umxSummary(m1, location = "topright") ##D umxSummary(m1, separateGraphs = FALSE) ##D m2 = umxModify(m1, update = c("cBeta2_r1c1", "eBeta1_r1c1", "eBeta2_r1c1"), comparison = TRUE) ##D ##D # TODO: teach umxReduce to test all relevant hypotheses for umxGxEbiv ##D umxReduce(m1) ## End(Not run) cleanEx() nameEx("umxHetCor") ### * umxHetCor flush(stderr()); flush(stdout()) ### Name: umxHetCor ### Title: Create a matrix of correlations for variables of diverse types ### (binary, ordinal, continuous) ### Aliases: umxHetCor ### ** Examples umxHetCor(mtcars[,c("mpg", "am")]) umxHetCor(mtcars[,c("mpg", "am")], treatAllAsFactor = TRUE, verbose = TRUE) cleanEx() nameEx("umxIP") ### * umxIP flush(stderr()); flush(stdout()) ### Name: umxIP ### Title: umxIP: Build and run an Independent Pathway twin model ### Aliases: umxIP ### ** Examples ## Not run: ##D require(umx) ##D data(GFF) ##D mzData = subset(GFF, zyg_2grp == "MZ") ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D selDVs = c("gff","fc","qol","hap","sat","AD") # These will be expanded into "gff_T1" "gff_T2" etc. ##D m1 = umxIP(selDVs = selDVs, sep = "_T", dzData = dzData, mzData = mzData) ##D ##D # WLS example: Use "marginals" method to enable all continuous data with missingness. ##D m3 = umxIP(selDVs = selDVs, sep = "_T", dzData = dzData, mzData = mzData, ##D type = "DWLS", allContinuousMethod='marginals') ##D # omit missing to enable default WLS method to work on all continuous data ##D dzD = na.omit(dzData[, tvars(selDVs, "_T")]) ##D mzD = na.omit(dzData[, tvars(selDVs, "_T")]) ##D m4 = umxIP(selDVs = selDVs, sep = "_T", dzData = dzD, mzData = mzD, type = "DWLS") ##D ##D # ==================================================================== ##D # = Try with a non-default number of a, c, and e independent factors = ##D # ==================================================================== ##D nFac = c(a = 2, c = 1, e = 1) ##D m2 = umxIP(selDVs = selDVs, sep = "_T", dzData = dzData, mzData = mzData, nFac = nFac, ##D tryHard = "yes") ##D umxCompare(m1, m2) ## End(Not run) cleanEx() nameEx("umxJiggle") ### * umxJiggle flush(stderr()); flush(stdout()) ### Name: umxJiggle ### Title: umxJiggle ### Aliases: umxJiggle ### ** Examples ## Not run: ##D mat1 = umxJiggle(mat1) ## End(Not run) cleanEx() nameEx("umxLav2RAM") ### * umxLav2RAM flush(stderr()); flush(stdout()) ### Name: umxLav2RAM ### Title: Convert lavaan string to a umxRAM model ### Aliases: umxLav2RAM ### ** Examples ## Not run: ##D ##D # auto-data, print table, return umxRAM model ##D m1 = umxLav2RAM("y ~ x", printTab= TRUE) ##D ##D lav = "y ~ x1 + 2.4*x2 + x3" ##D tmp = umxLav2RAM(lav, data = "auto", printTab= FALSE) ##D ##D # Add labels to parameters, e.g. "x3_loading" as a loading for x3->x1 ##D tmp = umxLav2RAM("x1 ~ x3_loading*x3") ##D umx_print(tmp$A$labels) ##D # | |x1 |x3 | ##D # |:--|:--------|:----------| ##D # |x1 |x1_to_x1 |x3_loading | ##D # |x3 |x1_to_x3 |x3_to_x3 | ##D ##D # Fix values, e.g. x2 -> y fixed at 2.4 ##D tmp = umxLav2RAM("y ~ x1 + 2.4*x2; s =~ 0*y11 + 1*y12 + 2*y13 + 3*y14") ##D ##D tmp = umxLav2RAM("L =~ X1 + X2; L ~ Y") ##D plot(tmp, min=c("L", "Y")) ##D ##D # Factor model showing auto-addition of correlations among exogenous latents ##D # and auto-residuals on manifests ##D data("HS.ability.data", package = "OpenMx") ##D ##D cov(HS.ability.data[, c("visual" , "cubes" , "flags")]) ##D cov(HS.ability.data[, c("paragrap", "sentence", "wordm")]) ##D cov(HS.ability.data[, c("addition", "counting", "straight")]) ##D ##D HS = "spatial =~ visual + cubes + flags ##D verbal =~ paragrap + sentence + wordm ##D speed =~ addition + counting + straight" ##D ##D m1 = umxRAM(HS, data = umx_scale(HS.ability.data)) ##D ##D # Multiple groups ##D m1 = umxRAM(HS, data = umx_scale(HS.ability.data), group = "school") ##D ##D # More examples ##D ##D lav = " # Moderated mediation ##D gnt ~ a*cb ##D INT ~ b1*gnt + b2*cn + b3*cngn + c*cb ##D ##D indirect := a*b1 ##D direct := c ##D ##D ab3 := a * b3 ##D loCN := a * b1 + ab3 * -0.5 ##D hiCN := a * b1 + ab3 * 0.5 ##D " ##D tmp = umxRAM(lav) ##D # plot showing ability to influence layout with max min same groupings ##D plot(tmp, max = c("cb", "cn", "cngn"), same = "gnt", min= "INT") ##D ##D # Algebra: e.g. b1^2 ##D m1 = umxRAM("x1~b1*x2; B1_sq := b1^2", data = demoOneFactor) ##D m1$B1_sq$result # = 0.47 ##D ##D # Model with constraints and labeled parameters ##D lav = " ##D y ~ b1*x1 + b2*x2 + b3*x3 ##D # constraints ##D b1 == (b2 + b3)^2 ##D b1 > exp(b2 + b3)" ##D ##D tmp = umxLav2RAM(lav) ##D ##D namedModel = " # my name ##D y ~x" ##D m1 = umxRAM(namedModel) ##D ##D # Formative factor ##D # lavaanify("f5 <~ z1 + z2 + z3 + z4") ## End(Not run) cleanEx() nameEx("umxMI") ### * umxMI flush(stderr()); flush(stdout()) ### Name: umxMI ### Title: Report modifications which would improve fit. ### Aliases: umxMI ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D umxMI(m1, full = FALSE) ## End(Not run) cleanEx() nameEx("umxMatrix") ### * umxMatrix flush(stderr()); flush(stdout()) ### Name: umxMatrix ### Title: Make a mxMatrix with automatic labels. Also takes name as the ### first parameter for more readable code. ### Aliases: umxMatrix ### ** Examples ## Not run: ##D # ================================================================================== ##D # = 1. Showing how name is first parameter, and how cells are labelled by default. = ##D # ================================================================================== ##D umxMatrix("test", "Full", 2, 2)$labels ##D # [,1] [,2] ##D # [1,] "test_r1c1" "test_r1c2" ##D # [2,] "test_r2c1" "test_r2c2" ##D ##D # =========================================================== ##D # = 2. Over-ride default (matrix name) as prefix for labels = ##D # =========================================================== ##D umxMatrix("test", "Full", 2, 2, baseName = "bob")$labels # bob_r1c1 ##D ##D ##D # ========================================== ##D # = 3. User-provided labels are left as-is = ##D # ========================================== ##D umxMatrix("foo", "Lower", nrow=2, ncol=2, labels= c(NA, "beta1", NA)) ##D # [,1] [,2] ##D # [1,] NA NA ##D # [2,] "beta1" NA ##D ## End(Not run) cleanEx() nameEx("umxModel") ### * umxModel flush(stderr()); flush(stdout()) ### Name: umxModel ### Title: Catches users typing umxModel instead of umxRAM. ### Aliases: umxModel ### ** Examples ## Not run: ##D umxModel() ## End(Not run) cleanEx() nameEx("umxModelNames") ### * umxModelNames flush(stderr()); flush(stdout()) ### Name: umxModelNames ### Title: Return names of models found within a model ### Aliases: umxModelNames ### ** Examples ## Not run: ##D data(GFF) ##D mzData = subset(GFF, zyg_2grp == "MZ") ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D selDVs = c("gff", "fc", "qol") ##D m1 = umxCP(selDVs= selDVs, nFac= 1, dzData= dzData, mzData= mzData, sep= "_T", autoRun= TRUE) ##D m2 = mxRename(m1, "model2") ##D umxModelNames(m1) # "top" "MZ" "DZ" ##D umxModelNames(m2) # "top" "MZ" "DZ" ##D ##D super = umxSuperModel("myModel", m1, m2, autoRun = TRUE) ##D umxModelNames(super) ##D ##D plot(super$CP1fac) ## End(Not run) cleanEx() nameEx("umxModify") ### * umxModify flush(stderr()); flush(stdout()) ### Name: umxModify ### Title: umxModify: Add, set, or drop model paths by label. ### Aliases: umxModify ### ** Examples ## Not run: ##D require(umx) ##D # First we'll just build a 1-factor model ##D umx_set_optimizer("SLSQP") ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D ##D # 1. Drop the path to x1 (also updating the name so it's ##D # self-explanatory, and get a fit comparison ##D m2 = umxModify(m1, update = "G_to_x1", name = "drop_X1", comparison = TRUE) ##D ##D # 2. Add the path back (setting free = TRUE) ##D m2 = umxModify(m1, update = "G_to_x1", free= TRUE, name = "addback_X1", comparison = TRUE) ##D # 3. Fix a value at a non-zero value ##D m3 = umxModify(m1, update = "G_to_x1", value = .35, name = "fix_G_x1_at_35", comp = TRUE) ##D # You can add objects to models. For instance this would add a path (overwriting the existing one) ##D # (thanks Johannes!) ##D m3 = umxModify(m1, umxPath("G", with = "x1"), name= "addedPath") ##D ##D # Use regular expression to drop multiple paths: e.g. G to x3, x4, x5 ##D m3 = umxModify(m1, regex = "^G_to_x[3-5]", name = "tried_hard", comp = TRUE, tryHard="yes") ##D ##D # Same, but don't autoRun ##D m2 = umxModify(m1, regex = "^G_to_x[3-5]", name = "no_G_to_x3_5", autoRun = FALSE) ##D ##D # Re-write a label ##D newLabel = "A_rose_by_any_other_name" ##D newModelName = "model_doth_smell_as_sweet" ##D m2 = umxModify(m1, update = "G_to_x1", newlabels= newLabel, name = newModelName, comparison = TRUE) ##D # Change labels in 2 places ##D labsToUpdate = c("G_to_x1", "G_to_x2") ##D newLabel = "G_to_1_or_2" ##D m2 = umxModify(m1, update = labsToUpdate, newlabels= newLabel, name = "equated", comparison = TRUE) ##D ##D # Advanced! ##D # Regular expressions let you use pieces of the old names in creating new ones! ##D searchString = "G_to_x([0-9])" ##D newLabel = "loading_for_path\\1" # use value in regex group 1 ##D m2 = umxModify(m1, regex = searchString, newlabels= newLabel, name = "grep", comparison = TRUE) ## End(Not run) # end dontrun cleanEx() nameEx("umxParameters") ### * umxParameters flush(stderr()); flush(stdout()) ### Name: umxParameters ### Title: Display path estimates from a model, filtering by name and ### value. ### Aliases: umxParameters parameters ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("OneFactor", data = demoOneFactor, ##D umxPath(from = "G", to = manifests), # factor loadings ##D umxPath(v.m. = manifests), # residual variance ##D umxPath(v1m0 = "G") # standardized latent ##D ) ##D # Parameters with values below .1 ##D umxParameters(m1, "below", .1) ##D # Parameters with values above .5 ##D umxParameters(m1, "above", .5) ##D # Parameters with values below .1 and containing "_to_" in their label ##D umxParameters(m1, "below", .1, "_to_") ## End(Not run) cleanEx() nameEx("umxParan") ### * umxParan flush(stderr()); flush(stdout()) ### Name: umxParan ### Title: A wrapper to make paran easier to use. Just automates applying ### 'complete.cases()' ### Aliases: umxParan ### ** Examples library(psych) library(psychTools) data(bfi) umxParan(bfi[, paste0("A", 1:5)]) umxParan(bfi, cols= paste0("A", 1:5)) # umxParan(bfi, paste0("AB", 1)) cleanEx() nameEx("umxPath") ### * umxPath flush(stderr()); flush(stdout()) ### Name: umxPath ### Title: Easier (and powerful) specification of paths in SEM. ### Aliases: umxPath ### ** Examples # ========================================== # = Examples of each path type, and option = # ========================================== umxPath("A", to = "B") # One-headed path from A to B umxPath("A", to = "B", fixedAt = 1) # same, with value fixed @1 umxPath("A", to = c("B", "C"), fixedAt = 1:2) # same, with more than 1 value umxPath("A", to = c("B","C"), firstAt = 1) # Fix only the first path, others free umxPath(var = "A") # Give a variance to A umxPath(var = "A", fixedAt = 1) # Give A variance, fixed at 1 umxPath(means = c("A","B")) # Create a means model for A: from = "one", to = "A" umxPath(v1m0 = "A") # Give "A" variance and a mean, fixed at 1 and 0 respectively umxPath(v.m. = "A") # Give "A" variance and a mean, leaving both free. umxPath(v0m0 = "W", label = c(NA, "data.W")) umxPath("A", with = "B") # using with: same as "to = B, arrows = 2" umxPath("A", with = "B", fixedAt = .5) # 2-head path fixed at .5 umxPath("A", with = c("B", "C"), firstAt = 1) # first covariance fixed at 1 umxPath(cov = c("A", "B")) # Covariance A <-> B umxPath(defn = "mpg") # create latent called def_mpg, with 0 mean * var, and label = "data.mpg" umxPath(fromEach = c('a','b'), to = c('c','d')) # a->c, a<->d, b<->c, b<->d umxPath(unique.bivariate = c('a','b','c')) # bivariate paths a<->b, a<->c, b<->c etc. umxPath(unique.pairs = letters[1:3]) # all distinct pairs: a<->a, a<->b, a<->c, b<->b, etc. umxPath(Cholesky = c("A1","A2"), to = c("m1", "m2")) # Cholesky ## Not run: ##D # A worked example ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type= "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1.0) ##D ) ##D umxSummary(m1, std = TRUE) ##D require(umx) ##D ##D ##D # ==================== ##D # = Cholesky example = ##D # ==================== ##D # ====================================================================== ##D # = 3-factor Cholesky (A component of a 5-variable 3-factor ACE model) = ##D # ====================================================================== ##D latents = paste0("A", 1:3) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("Chol", data = demoOneFactor, type = "cov", ##D umxPath(Cholesky = latents, to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = latents, fixedAt = 1) ##D ) ##D plot(m1, splines= FALSE) ##D ##D # ========================================================= ##D # = Definition variable example.Not much use at present, = ##D # = as def vars are not readily used in RAM models... = ##D # = Working on something rational and intuitive. = ##D # ========================================================= ##D data(mtcars) ##D m1 = umxRAM("manifest", data = mtcars, ##D umxPath(v.m. = "mpg"), ##D umxPath(defn = "mpg") ##D ) ##D ## End(Not run) cleanEx() nameEx("umxPlot") ### * umxPlot flush(stderr()); flush(stdout()) ### Name: umxPlot ### Title: Quickly plot y ~ x with a regression line and R^2, and nice ### labels. ### Aliases: umxPlot ### ** Examples data(mtcars) umxPlot(mpg ~ wt, data = mtcars, fitx = 2, fity = 10) umxPlot(x = "wt", y = "mpg", mtcars, fitx = 2, fity = 10) cleanEx() nameEx("umxPlotACE") ### * umxPlotACE flush(stderr()); flush(stdout()) ### Name: umxPlotACE ### Title: Make a graphical display of an ACE model ### Aliases: umxPlotACE plot.MxModelACE ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D m1 = umxACE("plotACE example", selDVs = "bmi", dzData = dzData, mzData = mzData, sep = "") ##D plot(m1, std = FALSE) # don't standardize ## End(Not run) cleanEx() nameEx("umxPlotACEcov") ### * umxPlotACEcov flush(stderr()); flush(stdout()) ### Name: umxPlotACEcov ### Title: Make a graphical display of an ACE model with covariates. ### Aliases: umxPlotACEcov plot.MxModelACEcov ### ** Examples ## Not run: ##D require(umx) ##D # BMI ?twinData from Australian twins. ##D # Cohort 1 Zygosity 1 == MZ females 3 == DZ females ##D data(twinData) ##D ##D # Pick the variables. We will use base names (i.e., "bmi") and set suffix. ##D selDVs = c("bmi") ##D selCovs = c("ht") ##D selVars = umx_paste_names(c(selDVs, selCovs), sep = "", suffixes= 1:2) ##D # Just top few pairs so example runs quickly ##D mzData = subset(twinData, zygosity == "MZFF", selVars)[1:100, ] ##D dzData = subset(twinData, zygosity == "DZFF", selVars)[1:100, ] ##D m1 = umxACEcov(selDVs= selDVs, selCovs= selCovs, dzData= dzData, mzData= mzData, sep= "") ##D plot(m1) ##D plot(m1, std = FALSE) # don't standardize ## End(Not run) cleanEx() nameEx("umxPlotACEv") ### * umxPlotACEv flush(stderr()); flush(stdout()) ### Name: umxPlotACEv ### Title: Produce a graphical display of an ACE variance-components twin ### model ### Aliases: umxPlotACEv plot.MxModelACEv ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D m1 = umxACEv(selDVs = "bmi", dzData = dzData, mzData = mzData, sep = "") ##D umxSummary(m1) ##D umxPlotACEv(m1, std = FALSE) # Don't standardize ##D plot(m1, std = FALSE) # don't standardize ## End(Not run) cleanEx() nameEx("umxPlotCP") ### * umxPlotCP flush(stderr()); flush(stdout()) ### Name: umxPlotCP ### Title: Draw and display a graphical figure of Common Pathway model ### Aliases: umxPlotCP plot.MxModelCP ### ** Examples ## Not run: ##D require(umx) ##D umx_set_optimizer("SLSQP") ##D data(GFF) ##D mzData = subset(GFF, zyg_2grp == "MZ") ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D selDVs = c("gff", "fc", "qol", "hap", "sat", "AD") ##D m1 = umxCP("new", selDVs = selDVs, sep = "_T", ##D dzData = dzData, mzData = mzData, nFac = 3 ##D ) ##D # m1 = mxTryHardOrdinal(m1) ##D umxPlotCP(m1) ##D plot(m1) # No need to remember a special name: plot works fine! ## End(Not run) cleanEx() nameEx("umxPlotDoC") ### * umxPlotDoC flush(stderr()); flush(stdout()) ### Name: umxPlotDoC ### Title: Plot a Direction of Causation Model. ### Aliases: umxPlotDoC plot.MxModelDoC ### ** Examples ## Not run: ##D # ================ ##D # = 1. Load Data = ##D # ================ ##D data(docData) ##D mzData = subset(docData, zygosity %in% c("MZFF", "MZMM")) ##D dzData = subset(docData, zygosity %in% c("DZFF", "DZMM")) ##D ##D # ======================================= ##D # = 2. Define manifests for var 1 and 2 = ##D # ======================================= ##D var1 = paste0("varA", 1:3) ##D var2 = paste0("varB", 1:3) ##D ##D # ======================================================= ##D # = 2. Make the non-causal (Cholesky) and causal models = ##D # ======================================================= ##D Chol= umxDoC(var1= var1, var2= var2, mzData= mzData, dzData= dzData, causal= FALSE) ##D DoC = umxDoC(var1= var1, var2= var2, mzData= mzData, dzData= dzData, causal= TRUE) ##D ##D # ================================================ ##D # = Make the directional models by modifying DoC = ##D # ================================================ ##D a2b = umxModify(DoC, "a2b", free = TRUE, name = "A2B") ##D plot(a2b) ##D ## End(Not run) cleanEx() nameEx("umxPlotFun") ### * umxPlotFun flush(stderr()); flush(stdout()) ### Name: umxPlotFun ### Title: Easily plot functions in R ### Aliases: umxPlotFun ### ** Examples ## Not run: ##D # Uses fonts not available on CRAN ##D umxPlotFun(sin, max= 2*pi) ##D umxPlotFun("sqrt(1/x)", max= 2*pi) ##D umxPlotFun(sin, max= 2*pi, ylab="Output of sin", title="My Big Graph") ##D p = umxPlotFun(function(x){x^2}, max= 100, title="Supply and demand") ##D umxPlotFun(function(x){100^2-x^2}, p = p) ##D ##D # Controlling other plot features ##D umxPlotFun(c("sin(x)", "x^3")) + ylim(c(-1,5)) ## End(Not run) cleanEx() nameEx("umxPlotGxE") ### * umxPlotGxE flush(stderr()); flush(stdout()) ### Name: umxPlotGxE ### Title: Plot the results of a GxE univariate test for moderation of ACE ### components. ### Aliases: umxPlotGxE plot.MxModelGxE ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D twinData$age1 = twinData$age2 = twinData$age ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D m1= umxGxE(selDVs= "bmi", selDefs= "age", dzData= dzData, mzData= mzData, sep="", tryHard="yes") ##D plot(m1) ##D # Directly call umxPlotGxE ##D umxPlotGxE(m1, xlab = "Age", separateGraphs = TRUE, gg = FALSE) ##D umxPlotGxE(m1, moderatorValues=18:67) ## End(Not run) cleanEx() nameEx("umxPlotGxEbiv") ### * umxPlotGxEbiv flush(stderr()); flush(stdout()) ### Name: umxPlotGxEbiv ### Title: Plot the results of a GxE univariate test for moderation of ACE ### components. ### Aliases: umxPlotGxEbiv plot.MxModelGxEbiv ### ** Examples require(umx) data(twinData) ## Not run: ##D selDVs = "wt"; selDefs = "ht" ##D df = umx_scale_wide_twin_data(twinData, varsToScale = c("ht", "wt"), suffix = "") ##D mzData = subset(df, zygosity %in% c("MZFF", "MZMM")) ##D dzData = subset(df, zygosity %in% c("DZFF", "DZMM", "DZOS")) ##D ##D m1 = umxGxEbiv(selDVs = selDVs, selDefs = selDefs, ##D dzData = dzData, mzData = mzData, sep = "", dropMissingDef = TRUE) ##D # Plot Moderation ##D plot(m1) ##D umxPlotGxEbiv(m1, xlab = "wt", separateGraphs = TRUE, location = "topleft") ## End(Not run) cleanEx() nameEx("umxPlotIP") ### * umxPlotIP flush(stderr()); flush(stdout()) ### Name: umxPlotIP ### Title: Draw a graphical figure for a Independent Pathway model ### Aliases: umxPlotIP plot.MxModelIP ### ** Examples ## Not run: ##D require(umx) ##D data(GFF) ##D mzData = subset(GFF, zyg_2grp == "MZ") ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D selDVs = c("gff","fc","qol","hap","sat","AD") # These will be expanded into "gff_T1" "gff_T2" etc. ##D m1 = umxIP(selDVs = selDVs, sep = "_T", dzData = dzData, mzData = mzData) ##D plot(model) ##D umxPlotIP(model, file = NA) ## End(Not run) cleanEx() nameEx("umxPlotSexLim") ### * umxPlotSexLim flush(stderr()); flush(stdout()) ### Name: umxPlotSexLim ### Title: Draw and display a graphical figure of a Sex limitation model ### Aliases: umxPlotSexLim plot.MxModelSexLim ### ** Examples ## Not run: ##D require(umx) ##D umx_set_optimizer("SLSQP") ##D data("us_skinfold_data") ##D # Rescale vars ##D us_skinfold_data[, c('bic_T1', 'bic_T2')] = us_skinfold_data[, c('bic_T1', 'bic_T2')]/3.4 ##D us_skinfold_data[, c('tri_T1', 'tri_T2')] = us_skinfold_data[, c('tri_T1', 'tri_T2')]/3 ##D us_skinfold_data[, c('caf_T1', 'caf_T2')] = us_skinfold_data[, c('caf_T1', 'caf_T2')]/3 ##D us_skinfold_data[, c('ssc_T1', 'ssc_T2')] = us_skinfold_data[, c('ssc_T1', 'ssc_T2')]/5 ##D us_skinfold_data[, c('sil_T1', 'sil_T2')] = us_skinfold_data[, c('sil_T1', 'sil_T2')]/5 ##D ##D # Data for each of the 5 twin-type groups ##D mzmData = subset(us_skinfold_data, zyg == 1) ##D mzfData = subset(us_skinfold_data, zyg == 2) ##D dzmData = subset(us_skinfold_data, zyg == 3) ##D dzfData = subset(us_skinfold_data, zyg == 4) ##D dzoData = subset(us_skinfold_data, zyg == 5) ##D ##D # ========================== ##D # = Run univariate example = ##D # ========================== ##D m1 = umxSexLim(selDVs = "bic", sep = "_T", A_or_C = "A", autoRun= FALSE, ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, ##D dzoData = dzoData ##D ) ##D m1 = mxTryHard(m1) ##D umxPlotSexLim(m1) ##D plot(m1) # no need to remember a special name: plot works fine! ## End(Not run) cleanEx() nameEx("umxPlotSimplex") ### * umxPlotSimplex flush(stderr()); flush(stdout()) ### Name: umxPlotSimplex ### Title: Draw and display a graphical figure of a simplex model ### Aliases: umxPlotSimplex plot.MxModelSimplex ### ** Examples ## Not run: ##D data(iqdat) ##D mzData = subset(iqdat, zygosity == "MZ") ##D dzData = subset(iqdat, zygosity == "DZ") ##D selDVs = c("IQ_age1", "IQ_age2", "IQ_age3", "IQ_age4") ##D m1 = umxSimplex(selDVs = selDVs, sep = "_T", dzData = dzData, mzData = mzData) ##D # plot(m1) ## End(Not run) cleanEx() nameEx("umxPower") ### * umxPower flush(stderr()); flush(stdout()) ### Name: umxPower ### Title: Test power to detect specified path values in a model. ### Aliases: umxPower ### ** Examples ## Not run: ##D # =================================================== ##D # = Power to detect correlation of .3 in 200 people = ##D # =================================================== ##D ##D # 1 Make some data ##D tmp = umx_make_raw_from_cov(qm(1, .3| .3, 1), n=2000, varNames= c("X", "Y"), empirical= TRUE) ##D ##D # 2. Make model of true XY correlation of .3 ##D m1 = umxRAM("corXY", data = tmp, ##D umxPath("X", with = "Y"), ##D umxPath(var = c("X", "Y")) ##D ) ##D # 3. Test power to detect .3 versus 0, with n= 90 subjects ##D umxPower(m1, "X_with_Y", n= 90) ##D ##D # #################### ##D # # Estimating power # ##D # #################### ##D # ##D # method = ncp ##D # n = 90 ##D # power = 0.83 ##D # sig.level = 0.05 ##D # statistic = LRT ##D ##D # ================================================= ##D # = Tabulate Power across a range of values of n = ##D # ================================================= ##D umxPower(m1, "X_with_Y", explore = TRUE) ##D ##D # ===================================== ##D # = Examples with method = empirical = ##D # ===================================== ##D ##D # Power to detect r = .3 given n=90 ##D umxPower(m1, "X_with_Y", n = 90, method = "empirical") ##D # power is .823 ##D # Test using cor.test doing the same thing. ##D pwr::pwr.r.test(r = .3, n = 90) ##D # n = 90 ##D # r = 0.3 ##D # sig.level = 0.05 ##D # power = 0.827 ##D # alternative = two.sided ##D ##D # Power search for detectable effect size, given n = 90 ##D umxPower(m1, "X_with_Y", explore = TRUE) ##D umxPower(m1, "X_with_Y", n= 90, explore = TRUE) ##D umxPower(m1, "X_with_Y", n= 90, method = "empirical", explore = TRUE) ##D ##D ##D data(twinData) # ?twinData from Australian twins. ##D twinData[, c("ht1", "ht2")] = twinData[, c("ht1", "ht2")] * 10 ##D mzData = twinData[twinData$zygosity %in% "MZFF", ] ##D dzData = twinData[twinData$zygosity %in% "DZFF", ] ##D m1 = umxACE(selDVs = "ht", selCovs = "age", sep = "", dzData = dzData, mzData = mzData) ##D ##D # drop more than 1 path ##D umxPower(m1, update = c("c_r1c1", "age_b_Var1"), method = 'ncp', n=90, explore = TRUE) ##D ##D # Specify only 1 parameter (not 'age_b_Var1' and 'c_r1c1' ) to search a parameter:power relationship ##D # note: Can't use method = "ncp" with search) ##D umxPower(m1, update = c("c_r1c1", "age_b_Var1"), method = 'empirical', n=90, explore = TRUE) ##D umxPower(m1, update = c("c_r1c1"), method = 'empirical', n=90, explore = TRUE) ##D ## End(Not run) cleanEx() nameEx("umxRAM") ### * umxRAM flush(stderr()); flush(stdout()) ### Name: umxRAM ### Title: Build and run path-based SEM models ### Aliases: umxRAM ### ** Examples ## Not run: ##D ##D # ============================================ ##D # = 1. Here's a simple example with raw data = ##D # ============================================ ##D mtcars$litres = mtcars$disp/61.02 ##D m1 = umxRAM("tim", data = mtcars, ##D umxPath(c("wt", "litres"), to = "mpg"), ##D umxPath("wt", with = "litres"), ##D umxPath(v.m. = c("wt", "litres", "mpg")) ##D ) ##D ##D # 2. Use parameters to see the parameter estimates and labels ##D parameters(m1) ##D ##D # And umxSummary to get standardized parameters, CIs etc from the run model. ##D umxSummary(m1, std=TRUE) ##D # |name | Std.Estimate| Std.SE|CI | ##D # |:--------------|------------:|------:|:--------------------| ##D # |wt_to_mpg | -0.54| 0.17|-0.54 [-0.89, -0.2] | ##D # |disp_to_mpg | -0.36| 0.18|-0.36 [-0.71, -0.02] | ##D # |mpg_with_mpg | 0.22| 0.07|0.22 [0.08, 0.35] | ##D # |wt_with_wt | 1.00| 0.00|1 [1, 1] | ##D # |b1 | 0.89| 0.04|0.89 [0.81, 0.96] | ##D # |disp_with_disp | 1.00| 0.00|1 [1, 1] | ##D ##D # 3. Of course you can plot the model ##D plot(m1) ##D plot(m1, std=TRUE, means=FALSE) ##D plot(m1, std = TRUE, means=FALSE, strip= TRUE, resid = "line") ##D ##D # =============================================== ##D # = lavaan string example (more at ?umxLav2RAM) = ##D # =============================================== ##D m1 = umxRAM(data = mtcars, "#modelName ##D mpg ~ wt + disp") ##D ##D ##D # ======================= ##D # = A multi-group model = ##D # ======================= ##D ##D mtcars$litres = mtcars$disp/61.02 ##D m1 = umxRAM("tim", data = mtcars, group = "am", ##D umxPath(c("wt", "litres"), to = "mpg"), ##D umxPath("wt", with = "litres"), ##D umxPath(v.m. = c("wt", "litres", "mpg")) ##D ) ##D # In this model, all parameters are free across the two groups. ##D ##D # ==================================== ##D # = A cov model, with steps laid out = ##D # ==================================== ##D ##D # *note*: The variance of displacement is in cubic inches and is very large. ##D # to help the optimizer, one might, say, multiply disp *.016 to work in litres ##D tmp = mtcars; tmp$disp= tmp$disp *.016 ##D ##D # We can just give the raw data and ask for it to be made into type cov: ##D m1 = umxRAM("tim", data = tmp, type="cov", ##D umxPath(c("wt", "disp"), to = "mpg"), ##D umxPath("wt", with = "disp"), ##D umxPath(var = c("mpg", "wt", "disp")) ##D ) ##D ##D # (see ?umxPath for more nifty options making paths...) ##D ##D # ========================================= ##D # = umxRAM can also accept mxData as data = ##D # ========================================= ##D # For convenience, list up the manifests you will be using ##D ##D selVars = c("mpg", "wt", "disp") ##D tmp = mtcars; tmp$disp= tmp$disp *.016 ##D myCov = mxData(cov(tmp[, selVars]), type = "cov", numObs = nrow(mtcars) ) ##D ##D m1 = umxRAM("tim", data = myCov, ##D umxPath(c("wt", "disp"), to = "mpg"), ##D umxPath("wt", with = "disp"), ##D umxPath(var = selVars) ##D ) ##D ##D ##D # ======================= ##D # = umxRAM supports WLS = ##D # ======================= ##D ##D # 1. Run an all-continuous WLS model ##D mw = umxRAM("raw", data = mtcars[, c("mpg", "wt", "disp")], ##D type = "WLS", allContinuousMethod = "cumulants", ##D umxPath(var = c("wt", "disp", "mpg")), ##D umxPath(c("wt", "disp"), to = "mpg"), ##D umxPath("wt", with = "disp"), ##D umxPath(var = c("wt", "disp", "mpg")) ##D ) ##D # 2. Switch to marginals to support means ##D mw = umxRAM("raw", data = mtcars[, c("mpg", "wt", "disp")], ##D type = "WLS", allContinuousMethod= "marginals", ##D umxPath(var = c("wt", "disp", "mpg")), ##D umxPath(c("wt", "disp"), to = "mpg"), ##D umxPath("wt", with = "disp"), ##D umxPath(var = c("wt", "disp", "mpg")) ##D ) ##D ##D ##D # =============================== ##D # = Using umxRAM in Sketch mode = ##D # =============================== ##D # No data needed: just list variable names! ##D # Resulting model will be plotted automatically ##D m1 = umxRAM("what does unique pairs do, I wonder", data = c("A", "B", "C"), ##D umxPath(unique.pairs = c("A", "B", "C")) ##D ) ##D ##D m1 = umxRAM("ring around the rosey", data = c("B", "C"), ##D umxPath(fromEach = c("A", "B", "C")) ##D ) ##D ##D m1 = umxRAM("fromEach with to", data = c("B", "C"), ##D umxPath(fromEach = c("B", "C"), to= "D") ##D ) ##D ##D m1 = umxRAM("CFA_sketch", data = paste0("x", 1:4), ##D umxPath("g", to = paste0("x", 1:4)), ##D umxPath(var = paste0("x", 1:4)), ##D umxPath(v1m0 = "g") ##D ) ##D ##D # ================================================= ##D # = This is an example of using your own labels: = ##D # umxRAM will not over-ride them = ##D # ================================================= ##D m1 = umxRAM("tim", data = mtcars, type="cov", ##D umxPath(c("wt", "disp"), to = "mpg"), ##D umxPath(cov = c("wt", "disp"), labels = "b1"), ##D umxPath(var = c("wt", "disp", "mpg")) ##D ) ##D omxCheckEquals(m1$S$labels["disp", "wt"], "b1") # label preserved ##D m1$S$labels ##D # mpg wt disp ##D # mpg "mpg_with_mpg" "mpg_with_wt" "disp_with_mpg" ##D # wt "mpg_with_wt" "wt_with_wt" "b1" ##D # disp "disp_with_mpg" "b1" "disp_with_disp" ##D parameters(m1) ##D ##D # =========== ##D # = Weights = ##D # =========== ##D # !!! Not tested !!! ##D mtcars$litres = mtcars$disp/61.02 ##D m1 = umxRAM("tim", data = mtcars, weight= "cyl", ##D umxPath(c("wt", "litres"), to = "mpg"), ##D umxPath("wt", with = "litres"), ##D umxPath(v.m. = c("wt", "litres", "mpg")) ##D ) ##D ## End(Not run) cleanEx() nameEx("umxRAM2Lav") ### * umxRAM2Lav flush(stderr()); flush(stdout()) ### Name: umxRAM2Lav ### Title: Convert a RAM model to a lavaan string ### Aliases: umxRAM2Lav ### ** Examples ## Not run: ##D umxRAM2Lav(umxLav2RAM("x ~ y", autoRun = FALSE, printTab = FALSE, lavaanMode = "lavaan")) ## End(Not run) cleanEx() nameEx("umxReduceACE") ### * umxReduceACE flush(stderr()); flush(stdout()) ### Name: umxReduceACE ### Title: Reduce an ACE model. ### Aliases: umxReduceACE ### ** Examples ## Not run: ##D data(twinData) ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D m1 = umxACE(selDVs = "bmi", dzData = dzData, mzData = mzData, sep = "") ##D ##D # =========================================================================== ##D # = Table of parameters + fit comparisons, ready too copy to word processor = ##D # =========================================================================== ##D umxReduce(m1, silent=TRUE, digits=2, repo="h") ##D ##D # ========================================== ##D # = Function captures the preferred model = ##D # ========================================== ##D m2 = umxReduce(m1) ##D umxSummary(m2) ##D ##D # works for ADE input also ##D m1 = umxACE(selDVs = "bmi", dzData = dzData, mzData = mzData, sep = "", dzCr = .25) ##D ## End(Not run) cleanEx() nameEx("umxReduceGxE") ### * umxReduceGxE flush(stderr()); flush(stdout()) ### Name: umxReduceGxE ### Title: Reduce a GxE model. ### Aliases: umxReduceGxE ### ** Examples ## Not run: ##D model = umxReduce(model) ## End(Not run) cleanEx() nameEx("umxRenameMatrix") ### * umxRenameMatrix flush(stderr()); flush(stdout()) ### Name: umxRenameMatrix ### Title: Rename a umxMatrix (even in a model) ### Aliases: umxRenameMatrix ### ** Examples ## Not run: ##D data(twinData) # ?twinData from Australian twins. ##D twinData[, c("ht1", "ht2")] = twinData[, c("ht1", "ht2")] * 10 ##D mzData = twinData[twinData$zygosity %in% "MZFF", ] ##D dzData = twinData[twinData$zygosity %in% "DZFF", ] ##D m1 = umxACE(selDVs= "ht", sep= "", dzData= dzData, mzData= mzData, autoRun= FALSE) ##D tmp = umxRenameMatrix(m1$top, matrixName = "a", name="hello") ##D umx_check(tmp$hello$labels == "hello_r1c1") # new is there ##D umx_check(is.null(tmp$a)) # old is gone ## End(Not run) cleanEx() nameEx("umxRotate.MxModelCP") ### * umxRotate.MxModelCP flush(stderr()); flush(stdout()) ### Name: umxRotate.MxModelCP ### Title: Rotate a CP solution ### Aliases: umxRotate.MxModelCP ### ** Examples ## Not run: ##D # Rotate a CP solution(param) ##D # Common pathway model rotation ##D library(umx) ##D # Fit 3 factor CPM ##D data(GFF) ##D selDVs = c("gff", "fc", "qol", "hap", "sat", "AD") ##D m1 = umxCP(selDVs = selDVs, nFac = 2, data = data, tryHard = "yes") ##D m2 = umxRotate(m1, rotation = "varimax", tryHard = "yes") ##D ## End(Not run) cleanEx() nameEx("umxRun") ### * umxRun flush(stderr()); flush(stdout()) ### Name: umxRun ### Title: umxRun: Run an mxModel ### Aliases: umxRun ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D latents = c("G") ##D manifests = names(demoOneFactor) ##D m1 = mxModel("fact", type="RAM", manifestVars=manifests, latentVars=latents, ##D mxPath(latents , to = manifests), ##D mxPath(manifests, arrows = 2), ##D mxPath(latents , arrows = 2, free = FALSE, values = 1), ##D mxData(cov(demoOneFactor), type = "cov", numObs=500) ##D ) ##D ##D m1 = umxRun(m1) # just run: will create saturated model if needed ##D m1 = umxRun(m1, setValues = TRUE, setLabels = TRUE) # set start values and label all parameters ##D umxSummary(m1, std = TRUE) ##D m1 = mxModel(m1, mxCI("G_to_x1")) # add one CI ##D m1 = mxRun(m1, intervals = TRUE) ##D residuals(m1, run = TRUE) # get CIs on all free parameters ##D confint(m1) # OpenMx's SE-based CIs ##D umxConfint(m1, run = TRUE) # get likelihood-based CIs on all free parameters ##D m1 = umxRun(m1, tryHard = "yes") ## End(Not run) cleanEx() nameEx("umxSetParameters") ### * umxSetParameters flush(stderr()); flush(stdout()) ### Name: umxSetParameters ### Title: Change or fix parameters (e.g. their values, labels, bounds, ..) ### in a model. ### Aliases: umxSetParameters ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D latents = c("G") ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = mxData(demoOneFactor[1:80,], type = "raw"), ##D umxPath(from = latents, to = manifests), ##D umxPath(v.m. = manifests), ##D umxPath(v1m0 = latents) ##D ) ##D parameters(m1) ##D # Match all labels ##D umxSetParameters(m1, regex = "^", newlabels= "m1_", test = TRUE) ##D # Change path to x1 to x2, equating these two paths ##D m2 = umxSetParameters(m1, "G_to_x1", newlabels= "G_to_x2", test = FALSE) ##D parameters(m2) ##D ## End(Not run) cleanEx() nameEx("umxSexLim") ### * umxSexLim flush(stderr()); flush(stdout()) ### Name: umxSexLim ### Title: Multivariate sex limitation twin model ### Aliases: umxSexLim ### ** Examples # ========================= # = Load and Process Data = # ========================= ## Not run: ##D require(umx) ##D data("us_skinfold_data") ##D # Rescale vars ##D us_skinfold_data[, c('bic_T1', 'bic_T2')] = us_skinfold_data[, c('bic_T1', 'bic_T2')]/3.4 ##D us_skinfold_data[, c('tri_T1', 'tri_T2')] = us_skinfold_data[, c('tri_T1', 'tri_T2')]/3 ##D us_skinfold_data[, c('caf_T1', 'caf_T2')] = us_skinfold_data[, c('caf_T1', 'caf_T2')]/3 ##D us_skinfold_data[, c('ssc_T1', 'ssc_T2')] = us_skinfold_data[, c('ssc_T1', 'ssc_T2')]/5 ##D us_skinfold_data[, c('sil_T1', 'sil_T2')] = us_skinfold_data[, c('sil_T1', 'sil_T2')]/5 ##D ##D # Data for each of the 5 twin-type groups ##D mzmData = subset(us_skinfold_data, zyg == 1) ##D mzfData = subset(us_skinfold_data, zyg == 2) ##D dzmData = subset(us_skinfold_data, zyg == 3) ##D dzfData = subset(us_skinfold_data, zyg == 4) ##D dzoData = subset(us_skinfold_data, zyg == 5) ##D ##D umxSummarizeTwinData(us_skinfold_data, selVars="bic",zyg="zyg", sep="_T", ##D MZFF=2, DZFF=4, MZMM=1, DZMM=3, DZOS=5 ##D ) ##D ##D # ========================== ##D # = Run univariate example = ##D # ========================== ##D ##D m1 = umxSexLim(selDVs = "bic", sep = "_T", A_or_C = "A", tryHard = "yes", ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, ##D dzoData = dzoData ##D ) ##D ##D # Drop qualitative sex limitation ##D m1a = umxModify(m1, regex = "^Rao_", value=1, name = "no_qual", comparison = TRUE) ##D ##D ##D # Equate a, ac, and try ace across m & f in scalar model ##D m1b = umxModify(m1a, regex = "^a[fm]_", newlabels="a_", name = "eq_a_no_qual", comparison = TRUE) ##D m1c = umxModify(m1b, regex = "^c[fm]_", newlabels="c_", name = "eq_ac_no_qual", comparison = TRUE) ##D m1d = umxModify(m1c, regex = "^e[fm]_", newlabels="e_", name = "eq_ace_no_qual", comparison = TRUE) ##D umxCompare(m1, c(m1a, m1b, m1c, m1d)) ##D ##D # ============================ ##D # = Scalar Sex Limitation = ##D # ============================ ##D ##D m2 = umxSexLim(selDVs = "bic", sep = "_T", sexlim = "Scalar", tryHard = "yes", ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, ##D dzoData = dzoData ##D ) ##D ##D # Show our manual drop of qualitative is the same as umxSexLim with sexlim= "scalar"s ##D umxCompare(m1a, m2) ##D ##D # =============== ##D # = Homogeneity = ##D # =============== ##D ##D m3 = umxSexLim(selDVs = "bic", sep = "_T", sexlim = "Homogeneity", tryHard = "yes", ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, ##D dzoData = dzoData ##D ) ##D umxCompare(m1, c(m2, m3)) ##D ##D # =========================================== ##D # = Bivariate example with manual reduction = ##D # =========================================== ##D m1 = umxSexLim(selDVs = c("bic", "tri"), sep = "_T", A_or_C = "A", tryHard="yes", ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, ##D dzoData = dzoData ##D ) ##D ##D # Scalar sex limitation (same correlation among components for m and f) ##D m2 = umxSexLim(selDVs = c("bic", "tri"), sep = "_T", ##D A_or_C = "A", tryHard="yes", sexlim="Scalar", ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, ##D dzoData = dzoData ##D ) ##D # Drop qualitative sex limitation ##D # Distinct af and am (& c & e), but shared Ra (& Rc & Re) between variables ##D # i.e., same correlations for males and females. ##D m1a = umxModify(m1 , regex = "^Ra[mfo]_", newlabels="^Ra_", name = "no_qual_a", comparison = TRUE) ##D m1b = umxModify(m1a, regex = "^Rc[mfo]_", newlabels="^Rc_", name = "no_qual_ac", comparison = TRUE) ##D m1c = umxModify(m1b, regex = "^Re[mfo]_", newlabels="^Re_", name = "no_qual_ace", comparison = TRUE) ##D umxCompare(m1, c(m1a, m1b, m1c, m2)) ##D ##D # In one smart regular expression ##D m2 = umxModify(m1, regex = "^R([ace])[fmo]_", newlabels = "R\\1_", ##D name = "scalar", comparison = TRUE) ##D ##D # Equate a, ac, and try ace across m & f in scalar model ##D m2a = umxModify(m2 , regex = "^a[fm]_", newlabels="a_", name = "eq_a_no_qual" , comparison = TRUE) ##D m2b = umxModify(m2a, regex = "^c[fm]_", newlabels="c_", name = "eq_ac_no_qual" , comparison = TRUE) ##D m2c = umxModify(m2b, regex = "^e[fm]_", newlabels="e_", name = "eq_ace_no_qual", comparison = TRUE) ##D umxCompare(m1, c(m1a, m1b, m1c, m1d)) ##D ##D # ============================= ##D # = Run multi-variate example = ##D # ============================= ##D # Variables for Analysis ##D selDVs = c('ssc','sil','caf','tri','bic') ##D selDVs = c('ssc','tri','bic') ##D m1 = umxSexLim(selDVs = selDVs, sep = "_T", A_or_C = "A", tryHard = "yes", ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, dzoData = dzoData ##D ) ##D ##D m2 = umxSexLim(selDVs = selDVs, sep = "_T", A_or_C = "A", sexlim = "Nonscalar", ##D tryHard = "yes", ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, dzoData = dzoData ##D ) ##D ##D # umxSummary(m1) ##D # summary(m1) ##D # summary(m1)$Mi ## End(Not run) cleanEx() nameEx("umxSimplex") ### * umxSimplex flush(stderr()); flush(stdout()) ### Name: umxSimplex ### Title: Build and run a simplex twin model (not ready for use!) ### Aliases: umxSimplex ### ** Examples ## Not run: ##D data(iqdat) ##D mzData = subset(iqdat, zygosity == "MZ") ##D dzData = subset(iqdat, zygosity == "DZ") ##D baseVars = c("IQ_age1", "IQ_age2", "IQ_age3", "IQ_age4") ##D m1= umxSimplex(selDVs= baseVars, dzData= dzData, mzData= mzData, sep= "_T", tryHard= "yes") ##D ##D umxSummary(m1) ##D parameters(m1, patt = "^s") ##D m2 = umxModify(m1, regex = "as_r1c1", name = "no_as", comp = TRUE) ##D umxCompare(m1, m2) ##D ##D # ============================= ##D # = Test a 3 time-point model = ##D # ============================= ##D m1 = umxSimplex(selDVs = paste0("IQ_age", 1:3), ##D dzData = dzData, mzData = mzData, tryHard = "yes") ## End(Not run) cleanEx() nameEx("umxSummarizeTwinData") ### * umxSummarizeTwinData flush(stderr()); flush(stdout()) ### Name: umxSummarizeTwinData ### Title: Summarize twin data ### Aliases: umxSummarizeTwinData ### ** Examples data(twinData) umxSummarizeTwinData(twinData, sep = "", selVars = c("wt", "ht")) MZs = c("MZMM", "MZFF"); DZs = c("DZFF","DZMM", "DZOS") umxSummarizeTwinData(twinData, sep = "", selVars = c("wt", "ht"), MZ = MZs, DZ = DZs) cleanEx() nameEx("umxSummary.MxModel") ### * umxSummary.MxModel flush(stderr()); flush(stdout()) ### Name: umxSummary.MxModel ### Title: Shows a compact, publication-style, summary of a RAM model ### Aliases: umxSummary.MxModel umxSummary.MxRAMModel ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D umxSummary(m1, std = TRUE) ##D # output as latex ##D umx_set_table_format("latex") ##D umxSummary(m1, std = TRUE) ##D umx_set_table_format("markdown") ##D # output as raw ##D umxSummary(m1, std = FALSE) ##D ##D # switch to a raw data model ##D m1 = umxRAM("One Factor", data = demoOneFactor[1:100, ], ##D umxPath("G", to = manifests), ##D umxPath(v.m. = manifests), ##D umxPath(v1m0 = "G") ##D ) ##D umxSummary(m1, std = TRUE, filter = "NS") ## End(Not run) cleanEx() nameEx("umxSummaryACE") ### * umxSummaryACE flush(stderr()); flush(stdout()) ### Name: umxSummaryACE ### Title: Shows a compact, publication-style, summary of a umx Cholesky ### ACE model ### Aliases: umxSummaryACE umxSummary.MxModelACE ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D selDVs = c("bmi1", "bmi2") ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D m1 = umxACE(selDVs = selDVs, dzData = dzData, mzData = mzData) ##D umxSummary(m1) ##D umxSummaryACE(m1, file = NA); ##D umxSummaryACE(m1, file = "name", std = TRUE) ##D stdFit = umxSummaryACE(m1, returnStd = TRUE); ## End(Not run) cleanEx() nameEx("umxSummaryACEcov") ### * umxSummaryACEcov flush(stderr()); flush(stdout()) ### Name: umxSummaryACEcov ### Title: Present results of a twin ACE-model with covariates in table and ### graphical forms. ### Aliases: umxSummaryACEcov umxSummary.MxModelACEcov ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D m1 = umxACEcov(selDVs = c("bmi", "wt"), selCovs = "ht", dzData = dzData, mzData = mzData, sep="") ##D umxSummaryACEcov(m1, file = NA) ##D umxSummaryACEcov(m1, file = "name", std = TRUE) ##D stdFit = umxSummary(m1, returnStd = TRUE) ## End(Not run) cleanEx() nameEx("umxSummaryACEv") ### * umxSummaryACEv flush(stderr()); flush(stdout()) ### Name: umxSummaryACEv ### Title: Shows a compact, publication-style, summary of a variance-based ### Cholesky ACE model. ### Aliases: umxSummaryACEv umxSummary.MxModelACEv ### ** Examples require(umx) data(twinData) mzData = subset(twinData, zygosity == "MZFF") dzData = subset(twinData, zygosity == "DZFF") m1 = umxACEv(selDVs = "bmi", sep = "", dzData = dzData, mzData = mzData) umxSummary(m1, std = FALSE) ## Not run: ##D umxSummary(m1, file = NA); ##D umxSummary(m1, file = "name", std = TRUE) ##D stdFit = umxSummary(m1, returnStd = TRUE) ## End(Not run) cleanEx() nameEx("umxSummaryCP") ### * umxSummaryCP flush(stderr()); flush(stdout()) ### Name: umxSummaryCP ### Title: Present the results of a Common-pathway twin model in table and ### graphical form ### Aliases: umxSummaryCP umxSummary.MxModelCP ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D ##D twinData$wt1 = twinData$wt1/10 ##D twinData$wt2 = twinData$wt2/10 ##D selDVs = c("ht", "wt") ##D mzData = subset(twinData, zygosity == "MZFF") ##D dzData = subset(twinData, zygosity == "DZFF") ##D ##D m1 = umxCP(selDVs = selDVs, dzData = dzData, mzData = mzData, sep = "", optimizer = "SLSQP") ##D umxSummaryCP(m1, file = NA) # Suppress plot creation with file ##D umxSummary(m1, file = NA) # Generic summary is the same ##D stdFit = umxSummaryCP(m1, digits = 2, std = TRUE, file = NA, returnStd = TRUE); ##D ##D umxSummary(m1, std = FALSE, showRg = TRUE, file = NA); ##D umxSummary(m1, std = FALSE, file = NA) ##D ##D # ================= ##D # = Print example = ##D # ================= ##D umxSummary(m1, file = "Figure 3", std = TRUE) ##D ##D # ================= ##D # = Confint example = ##D # ================= ##D m1 = umxConfint(m1, "smart", run = FALSE); ##D m1 = umxConfint(m1, "smart", run = TRUE); ##D umxSummary(m1, CIs = TRUE, file = NA); ## End(Not run) cleanEx() nameEx("umxSummaryDoC") ### * umxSummaryDoC flush(stderr()); flush(stdout()) ### Name: umxSummaryDoC ### Title: Shows a compact, publication-style, summary of a umx Direction ### of Causation model ### Aliases: umxSummaryDoC umxSummary.MxModelDoC ### ** Examples ## Not run: ##D # ================ ##D # = 1. Load Data = ##D # ================ ##D data(docData) ##D mzData = subset(docData, zygosity %in% c("MZFF", "MZMM")) ##D dzData = subset(docData, zygosity %in% c("DZFF", "DZMM")) ##D ##D # ======================================= ##D # = 2. Define manifests for var 1 and 2 = ##D # ======================================= ##D var1 = paste0("varA", 1:3) ##D var2 = paste0("varB", 1:3) ##D ##D # ======================================================= ##D # = 2. Make the non-causal (Cholesky) and causal models = ##D # ======================================================= ##D Chol= umxDoC(var1= var1, var2= var2, mzData= mzData, dzData= dzData, causal= FALSE) ##D DoC = umxDoC(var1= var1, var2= var2, mzData= mzData, dzData= dzData, causal= TRUE) ##D ##D # ================================================ ##D # = Make the directional models by modifying DoC = ##D # ================================================ ##D A2B = umxModify(DoC, "a2b", free = TRUE, name = "A2B") ##D A2B = umxModify(DoC, "a2b", free = TRUE, name = "A2B", comp=TRUE) ##D B2A = umxModify(DoC, "b2a", free = TRUE, name = "B2A", comp=TRUE) ##D umxCompare(B2A, A2B) ##D ## End(Not run) cleanEx() nameEx("umxSummaryGxE") ### * umxSummaryGxE flush(stderr()); flush(stdout()) ### Name: umxSummaryGxE ### Title: Summarize a GxE model ### Aliases: umxSummaryGxE umxSummary.MxModelGxE ### ** Examples ## Not run: ##D # The total sample has been subdivided into a young cohort, ##D # aged 18-30 years, and an older cohort aged 31 and above. ##D # Cohort 1 Zygosity is coded as follows 1 == MZ females 2 == MZ males ##D # 3 == DZ females 4 == DZ males 5 == DZ opposite sex pairs ##D require(umx) ##D data(twinData) ##D twinData$age1 = twinData$age2 = twinData$age ##D selDVs = c("bmi1", "bmi2") ##D selDefs = c("age1", "age2") ##D selVars = c(selDVs, selDefs) ##D mzData = subset(twinData, zygosity == "MZFF", selVars) ##D dzData = subset(twinData, zygosity == "DZMM", selVars) ##D # Exclude cases with missing Def ##D mzData = mzData[!is.na(mzData[selDefs[1]]) & !is.na(mzData[selDefs[2]]),] ##D dzData = dzData[!is.na(dzData[selDefs[1]]) & !is.na(dzData[selDefs[2]]),] ##D m1 = umxGxE(selDVs = "bmi", selDefs = "age", sep="", dzData = dzData, mzData = mzData) ##D # Plot Moderation ##D umxSummaryGxE(m1) ##D umxSummaryGxE(m1, location = "topright") ##D umxSummaryGxE(m1, separateGraphs = FALSE) ## End(Not run) cleanEx() nameEx("umxSummaryGxEbiv") ### * umxSummaryGxEbiv flush(stderr()); flush(stdout()) ### Name: umxSummaryGxEbiv ### Title: Summarize a bivariate GxE twin model ### Aliases: umxSummaryGxEbiv umxSummary.MxModelGxEbiv ### ** Examples data(twinData) df = umx_scale_wide_twin_data(twinData, varsToScale = c("ht", "wt"), sep = "") mzData = subset(df, zygosity %in% c("MZFF", "MZMM")) dzData = subset(df, zygosity %in% c("DZFF", "DZMM", "DZOS")) ## Not run: ##D m1 = umxGxEbiv(selDVs = "wt", selDefs = "ht", ##D dzData = dzData, mzData = mzData, sep = "", dropMissingDef = TRUE) ##D # Plot Moderation ##D umxSummary(m1) ##D umxSummary(m1, location = "topright") ##D umxSummary(m1, separateGraphs = FALSE) ## End(Not run) cleanEx() nameEx("umxSummaryIP") ### * umxSummaryIP flush(stderr()); flush(stdout()) ### Name: umxSummaryIP ### Title: Present the results of an independent-pathway twin model in ### table and graphical form ### Aliases: umxSummaryIP umxSummary.MxModelIP ### ** Examples ## Not run: ##D require(umx) ##D data(GFF) # family function and well-being data ##D mzData = subset(GFF, zyg_2grp == "MZ") ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D selDVs = c("hap", "sat", "AD") # These will be expanded into "hap_T1" "hap_T2" etc. ##D m1 = umxIP(selDVs = selDVs, sep = "_T", dzData = dzData, mzData = mzData) ##D umxSummaryIP(m1) ##D plot(m1) ##D umxSummaryIP(m1, digits = 2, file = "Figure3", showRg = FALSE, CIs = TRUE); ## End(Not run) cleanEx() nameEx("umxSummarySexLim") ### * umxSummarySexLim flush(stderr()); flush(stdout()) ### Name: umxSummarySexLim ### Title: Shows a compact, publication-style, summary of a umx Sex ### Limitation model ### Aliases: umxSummarySexLim umxSummary.MxModelSexLim ### ** Examples ## Not run: ##D # ====================================================== ##D # = Beta: Should be good to use for Boulder/March 2020 = ##D # ====================================================== ##D ##D # ============================================= ##D # = Run Qualitative Sex Differences ACE model = ##D # ============================================= ##D ##D # ========================= ##D # = Load and Process Data = ##D # ========================= ##D require(umx) ##D umx_set_optimizer("SLSQP") ##D data("us_skinfold_data") ##D # rescale vars ##D us_skinfold_data[, c('bic_T1', 'bic_T2')] = us_skinfold_data[, c('bic_T1', 'bic_T2')]/3.4 ##D us_skinfold_data[, c('tri_T1', 'tri_T2')] = us_skinfold_data[, c('tri_T1', 'tri_T2')]/3 ##D us_skinfold_data[, c('caf_T1', 'caf_T2')] = us_skinfold_data[, c('caf_T1', 'caf_T2')]/3 ##D us_skinfold_data[, c('ssc_T1', 'ssc_T2')] = us_skinfold_data[, c('ssc_T1', 'ssc_T2')]/5 ##D us_skinfold_data[, c('sil_T1', 'sil_T2')] = us_skinfold_data[, c('sil_T1', 'sil_T2')]/5 ##D ##D # Variables for Analysis ##D selDVs = c('ssc','sil','caf','tri','bic') ##D # Data for each of the 5 twin-type groups ##D mzmData = subset(us_skinfold_data, zyg == 1) ##D mzfData = subset(us_skinfold_data, zyg == 2) ##D dzmData = subset(us_skinfold_data, zyg == 3) ##D dzfData = subset(us_skinfold_data, zyg == 4) ##D dzoData = subset(us_skinfold_data, zyg == 5) ##D ##D # ====================== ##D # = Bivariate example = ##D # ====================== ##D ##D selDVs = c('tri','bic') ##D m1 = umxSexLim(selDVs = selDVs, sep = "_T", A_or_C = "A", tryHard = "yes", ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, ##D dzoData = dzoData ##D ) ##D umxSummary(m1, file = NA); ##D ##D # =============== ##D # = Switch to C = ##D # =============== ##D m1 = umxSexLim(selDVs = selDVs, sep = "_T", A_or_C = "C", tryHard = "yes", ##D mzmData = mzmData, dzmData = dzmData, ##D mzfData = mzfData, dzfData = dzfData, ##D dzoData = dzoData ##D ) ## End(Not run) cleanEx() nameEx("umxSummarySimplex") ### * umxSummarySimplex flush(stderr()); flush(stdout()) ### Name: umxSummarySimplex ### Title: Shows a compact, publication-style, summary of a Simplex model. ### Aliases: umxSummarySimplex umxSummary.MxModelSimplex ### ** Examples ## Not run: ##D # 4 time model ##D # Select Data ##D data(iqdat) ##D mzData <- subset(iqdat, zygosity == "MZ") ##D dzData <- subset(iqdat, zygosity == "DZ") ##D vars = c("IQ_age1", "IQ_age2", "IQ_age3", "IQ_age4") ##D m1= umxSimplex(selDVs= vars, sep= "_T", dzData= dzData, mzData= mzData, tryHard= "yes") ##D umxSummary(m1, file = NA); ## End(Not run) cleanEx() nameEx("umxSuperModel") ### * umxSuperModel flush(stderr()); flush(stdout()) ### Name: umxSuperModel ### Title: Make a multi-group model ### Aliases: umxSuperModel ### ** Examples ## Not run: ##D library(umx) ##D # Create two sets of data in which X & Y correlate ~ .4 in both datasets. ##D manifests = c("x", "y") ##D tmp = umx_make_TwinData(nMZpairs = 100, nDZpairs = 150, ##D AA = 0, CC = .4, EE = .6, varNames = manifests) ##D ##D # Group 1 ##D grp1 = tmp[tmp$zygosity == "MZ", manifests] ##D g1Data = mxData(cov(grp1), type = "cov", numObs = nrow(grp1), means=umx_means(grp1)) ##D ##D # Group 2 ##D grp2 = tmp[tmp$zygosity == "DZ", manifests] ##D g2Data = mxData(cov(grp2), type = "cov", numObs = nrow(grp2), means=umx_means(grp2)) ##D ##D ##D # Model 1 (could add autoRun = FALSE if you don't want to run this as it is being built) ##D m1 = umxRAM("m1", data = g1Data, ##D umxPath("x", to = "y", labels = "beta"), ##D umxPath(var = manifests, labels = c("Var_x", "Resid_y_grp1")), ##D umxPath(means = manifests, labels = c("Mean_x", "Mean_y")) ##D ) ##D ##D # Model 2 ##D m2 = umxRAM("m2", data = g2Data, ##D umxPath("x", to = "y", labels = "beta"), ##D umxPath(var = manifests, labels=c("Var_x", "Resid_y_grp2")), ##D umxPath(means = manifests, labels=c("Mean_x", "Mean_y")) ##D ) ##D ##D # Place m1 and m2 into a supermodel, and autoRun it ##D # NOTE: umxSummary is only semi-smart/certain enough to compute saturated models etc ##D # and report multiple groups correctly. ##D ##D m3 = umxSuperModel('top', m1, m2) ##D ##D umxSummary(m3, std= TRUE) ##D ##D # |name | Std.Estimate| Std.SE|CI | ##D # |:------------|------------:|------:|:-----------------| ##D # |beta | 0.51| 0.05|0.51 [0.41, 0.61] | ##D # |Var_x | 1.00| 0.00|1 [1, 1] | ##D # |Resid_y_grp1 | 0.74| 0.05|0.74 [0.64, 0.84] | ##D # |beta | 0.50| 0.05|0.5 [0.41, 0.6] | ##D # |Var_x | 1.00| 0.00|1 [1, 1] | ##D # |Resid_y_grp2 | 0.75| 0.05|0.75 [0.65, 0.84] | ##D ##D summary(m3) ##D ##D # ==================================== ##D # = Test models with duplicate names = ##D # ==================================== ##D data(GFF) ##D mzData = subset(GFF, zyg_2grp == "MZ") ##D dzData = subset(GFF, zyg_2grp == "DZ") ##D selDVs = c("gff", "fc", "qol") ##D m1 = umxCP(selDVs= selDVs, nFac= 1, dzData= dzData, mzData= mzData, sep= "_T", autoRun= TRUE) ##D m2 = mxRename(m1, "CP2") ##D umxModelNames(m1) # "top" "MZ" "DZ" ##D umxModelNames(m2) # "top" "MZ" "DZ" ##D super = umxSuperModel("myModel", m1, m2, autoRun = TRUE) ##D umxModelNames(super) ## End(Not run) cleanEx() nameEx("umxThresholdMatrix") ### * umxThresholdMatrix flush(stderr()); flush(stdout()) ### Name: umxThresholdMatrix ### Title: Create the threshold matrix needed for modeling ordinal data. ### Aliases: umxThresholdMatrix ### ** Examples # ============================ # = Simple non-twin examples = # ============================ # data: 1 2-level ordered factor x = data.frame(ordered(rbinom(100,1,.5))); names(x) = c("x") tmp = umxThresholdMatrix(x, fullVarNames = "x") # The lower ones matrix (all fixed) tmp[[1]]$values tmp[[1]]$free # The deviations matrix tmp[[2]]$values tmp[[2]]$labels # note: for twins, labels will be equated across twins # The algebra that adds the deviations to create thresholds: tmp[[3]]$formula # Example of a warning to not omit the variable names # tmp = umxThresholdMatrix(x) # Polite message: For coding safety, when calling umxThresholdMatrix, set fullVarNames... # One ordered factor with 5-levels x = cut(rnorm(100), breaks = c(-Inf,.2,.5, .7, Inf)); levels(x) = 1:5 x = data.frame(ordered(x)); names(x) <- c("x") tmp = umxThresholdMatrix(x, fullVarNames = "x") tmp[[2]]$name tmp[[2]]$free # last one is free.. (method = Mehta) tmp = umxThresholdMatrix(x, fullVarNames = "x", l_u_bound= c(-1,1)) tmp[[2]]$lbound # bounds applied to base threshold # ================================= # = Binary example with twin data = # ================================= # =============================================================== # = Create a series of binary and ordinal columns to work with = # =============================================================== data(twinData) # Make "obese" variable with ~20% subjects categorised as obese obesityLevels = c('normal', 'obese') cutPoints = quantile(twinData[, "bmi1"], probs = .2, na.rm = TRUE) twinData$obese1 = cut(twinData$bmi1, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) twinData$obese2 = cut(twinData$bmi2, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) # Step 2: Make the ordinal variables into umxFactors (ordered, with the levels found in the data) selVars = c("obese1", "obese2") twinData[, selVars] = umxFactor(twinData[, selVars]) # Example 1 # use verbose = TRUE to see informative messages tmp = umxThresholdMatrix(twinData, fullVarNames = selVars, sep = "", verbose = TRUE) # ====================================== # = Ordinal (n categories > 2) example = # ====================================== # Repeat for three-level weight variable obesityLevels = c('normal', 'overweight', 'obese') cutPoints = quantile(twinData[, "bmi1"], probs = c(.4, .7), na.rm = TRUE) twinData$obeseTri1 = cut(twinData$bmi1, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) twinData$obeseTri2 = cut(twinData$bmi2, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) selDVs = "obeseTri"; selVars = tvars(selDVs, sep = "", suffixes = 1:2) twinData[, selVars] = umxFactor(twinData[, selVars]) tmp = umxThresholdMatrix(twinData, fullVarNames = selVars, sep = "", verbose = TRUE) # ======================================================== # = Mix of all three kinds example (and a 4-level trait) = # ======================================================== obesityLevels = c('underWeight', 'normal', 'overweight', 'obese') cutPoints = quantile(twinData[, "bmi1"], probs = c(.25, .4, .7), na.rm = TRUE) twinData$obeseQuad1 = cut(twinData$bmi1, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) twinData$obeseQuad2 = cut(twinData$bmi2, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) selVars = c("obeseQuad1", "obeseQuad2") twinData[, selVars] = umxFactor(twinData[, selVars]) selDVs =c("bmi", "obese", "obeseTri", "obeseQuad") tmp = umxThresholdMatrix(twinData, fullVarNames = tvars(selDVs, sep= ""), sep = "", verbose = TRUE) # The lower ones matrix (all fixed) tmp[[1]]$values # The deviations matrix tmp[[2]]$values tmp[[2]]$labels # note labels are equated across twins # Check to be sure twin-1 column labels same as twin-2 tmp[[2]]$labels[,2]==tmp[[2]]$labels[,4] # The algebra that assembles these into thresholds: tmp[[3]]$formula # ================================= # = Example with method = allFree = # ================================= tmp = umxThresholdMatrix(twinData, fullVarNames = tvars(selDVs, sep= ""), sep = "", method = "allFree") all(tmp[[2]]$free) cleanEx() nameEx("umxTwinMaker") ### * umxTwinMaker flush(stderr()); flush(stdout()) ### Name: umxTwinMaker ### Title: Make a twin model from the model describing just one person ### Aliases: umxTwinMaker ### ** Examples ## Not run: ##D # We'll make some ACE models, but first, let's clean up the twinData ##D # set for analysis ##D # 1. Add a separator to the twin variable names (with sep = "_T") ##D # 2. Scale the data so it's easier for the optimizer. ##D data(twinData) ##D tmp = umx_make_twin_data_nice(data=twinData, sep="", zygosity="zygosity", numbering=1:2) ##D tmp = umx_scale_wide_twin_data(varsToScale= c("wt", "ht"), sep= "_T", data= tmp) ##D mzData = subset(tmp, zygosity %in% c("MZFF", "MZMM")) ##D dzData = subset(tmp, zygosity %in% c("DZFF", "DZMM")) ##D ##D # ========================== ##D # = Make an ACE twin model = ##D # ========================== ##D # 1. Define paths for *one* person: ##D paths = c( ##D umxPath(v1m0 = c("a1", 'c1', "e1")), ##D umxPath(means = c("wt")), ##D umxPath(c("a1", 'c1', "e1"), to = "wt", values=.2) ##D ) ##D # 2. Make a twin model from the paths for one person ##D m1 = umxTwinMaker("test", paths, mzData = mzData, dzData= dzData) ##D plot(m1, std= TRUE, means= FALSE) ##D ##D # 3. comparison with umxACE... ##D m2 = umxACE(selDVs="wt", mzData = mzData, dzData=dzData, sep="_T") ##D ##D # ===================== ##D # = Bivariate example = ##D # ===================== ##D latents = paste0(rep(c("a", "c", "e"), each = 2), 1:2) ##D biv = c( ##D umxPath(v1m0 = latents), ##D umxPath(mean = c("wt", "ht")), ##D umxPath(fromEach = c("a1", 'c1', "e1"), to = c("ht", "wt")), ##D umxPath(c("a2", 'c2', "e2"), to = "wt") ##D ) ##D tmp= umxTwinMaker(paths= biv, mzData = mzData, dzData= dzData) ##D plot(tmp, means=FALSE) ##D ##D # How to use latents other than a, c, and e: define in t1_t2links ##D paths = c( ##D umxPath(v1m0 = c("as1", 'c1', "e1")), ##D umxPath(means = c("wt")), ##D umxPath(c("as1", 'c1', "e1"), to = "wt", values=.2) ##D ) ##D m1 = umxTwinMaker("test", paths, mzData = mzData, dzData= dzData, ##D t1_t2links = list('as'=c(1, .5), 'c'=c(1, 1), 'e'=c(0, 0)) ##D ) ##D ## End(Not run) cleanEx() nameEx("umxTwoStage") ### * umxTwoStage flush(stderr()); flush(stdout()) ### Name: umxTwoStage ### Title: Build a SEM implementing the instrumental variable design ### Aliases: umxTwoStage umxMR ### ** Examples ## Not run: ##D library(umx) ##D ##D ##D # ==================================== ##D # = Mendelian Randomization analysis = ##D # ==================================== ##D ##D df = umx_make_MR_data(10e4) ##D m1 = umxMR(Y ~ X, instruments = ~ qtl, data = df) ##D parameters(m1) ##D plot(m1, means = FALSE, min="") # help DiagrammaR layout the plot. ##D m2 = umxModify(m1, "qtl_to_X", comparison=TRUE, tryHard="yes", name="QTL_affects_X") # yip ##D m3 = umxModify(m1, "X_to_Y" , comparison=TRUE, tryHard="yes", name="X_affects_Y") # nope ##D plot(m3, means = FALSE) ##D ##D # Errant analysis using ordinary least squares regression (WARNING this result is CONFOUNDED!!) ##D m1 = lm(Y ~ X , data = df); coef(m1) # incorrect .35 effect of X on Y ##D m1 = lm(Y ~ X + U, data = df); coef(m1) # Controlling U reveals the true 0.1 beta weight ##D ##D ##D df = umx_make_MR_data(10e4) ##D m1 = umxMR(Y ~ X, instruments = ~ qtl, data = df) ##D coef(m1) ##D ##D # ====================== ##D # = Now with sem::tsls = ##D # ====================== ##D # library(sem) # may require you to install X11 ##D m2 = sem::tsls(formula = Y ~ X, instruments = ~ qtl, data = df) ##D coef(m2) ##D ##D # Try with missing value for one subject: A benefit of the FIML approach in OpenMx. ##D m3 = tsls(formula = Y ~ X, instruments = ~ qtl, data = (df[1, "qtl"] = NA)) ## End(Not run) cleanEx() nameEx("umxUnexplainedCausalNexus") ### * umxUnexplainedCausalNexus flush(stderr()); flush(stdout()) ### Name: umxUnexplainedCausalNexus ### Title: umxUnexplainedCausalNexus ### Aliases: umxUnexplainedCausalNexus ### ** Examples ## Not run: ##D umxUnexplainedCausalNexus(from="yrsEd", delta = .5, to = "income35", model) ## End(Not run) cleanEx() nameEx("umxVersion") ### * umxVersion flush(stderr()); flush(stdout()) ### Name: umxVersion ### Title: Get or print the version of umx, along with detail from OpenMx ### and general system info. ### Aliases: umxVersion ### ** Examples x = umxVersion(); x cleanEx() nameEx("umxWeightedAIC") ### * umxWeightedAIC flush(stderr()); flush(stdout()) ### Name: umxWeightedAIC ### Title: AIC weight-based conditional probabilities. ### Aliases: umxWeightedAIC ### ** Examples l1 = lm(mpg~ wt + disp, data=mtcars) l2 = lm(mpg~ wt, data=mtcars) umxWeightedAIC(models = list(l1, l2)) cleanEx() nameEx("umx_APA_pval") ### * umx_APA_pval flush(stderr()); flush(stdout()) ### Name: umx_APA_pval ### Title: Round p-values according to APA guidelines ### Aliases: umx_APA_pval ### ** Examples umx_APA_pval(.052347) umx_APA_pval(1.23E-3) umx_APA_pval(1.23E-4) umx_APA_pval(c(1.23E-3, .5)) umx_APA_pval(c(1.23E-3, .5), addComparison = TRUE) cleanEx() nameEx("umx_aggregate") ### * umx_aggregate flush(stderr()); flush(stdout()) ### Name: umx_aggregate ### Title: Convenient formula-based cross-tabs & built-in summary functions ### Aliases: umx_aggregate ### ** Examples # ===================================== # = Basic use, compare with aggregate = # ===================================== aggregate(mpg ~ cyl, FUN = mean, na.rm = TRUE, data = mtcars) umx_aggregate(mpg ~ cyl, data = mtcars) # ============================================= # = Use different (or user-defined) functions = # ============================================= umx_aggregate(mpg ~ cyl, data = mtcars, what = "n") umx_aggregate(mpg ~ cyl, data = mtcars, what = function(x){sum(!is.na(x))}) # turn off markdown umx_aggregate(mpg ~ cyl, data = mtcars, report = "txt") # ============================================ # = More than one item on the left hand side = # ============================================ umx_aggregate(cbind(mpg, qsec) ~ cyl, data = mtcars, digits = 3) # Transpose table t(umx_aggregate(cbind(mpg, qsec) ~ cyl, data = mtcars)) ## Not run: ##D umx_aggregate(cbind(moodAvg, mood) ~ condition, data = study1) ## End(Not run) cleanEx() nameEx("umx_apply") ### * umx_apply flush(stderr()); flush(stdout()) ### Name: umx_apply ### Title: umx_apply ### Aliases: umx_apply ### ** Examples umx_apply(mean, mtcars, by = "columns") umx_apply("mean", of = mtcars, by = "columns") tmp = mtcars[1:3,]; tmp[1,1] = NA umx_apply("mean", by = "rows", of = tmp) umx_apply("mean", by = "rows", of = tmp, na.rm = TRUE) cleanEx() nameEx("umx_array_shift") ### * umx_array_shift flush(stderr()); flush(stdout()) ### Name: umx_array_shift ### Title: Like the php array_shift function: shifts an item off the ### beginning of a list ### Aliases: umx_array_shift ### ** Examples x = c("Alice", "Bob", "Carol") umx_array_shift(x) # returns "Alice" x # now only 2 items (altered in containing environment) cleanEx() nameEx("umx_as_numeric") ### * umx_as_numeric flush(stderr()); flush(stdout()) ### Name: umx_as_numeric ### Title: umx_as_numeric ### Aliases: umx_as_numeric ### ** Examples # make mpg into string, and cyl into a factor df = mtcars df$mpg = as.character(df$mpg) df$cyl = factor(df$cyl) df$am = df$am==1 df = umx_as_numeric(df); str(df) # mpg not touched df = umx_as_numeric(df, force=TRUE); str(df) # mpg coerced back to numeric ## Not run: ##D # coercing a real string will cause NAs ##D df$mpg = c(letters[1:16]); str(df) # replace mpg with letters. ##D df = umx_as_numeric(df, force=TRUE); str(df) ## End(Not run) cleanEx() nameEx("umx_check") ### * umx_check flush(stderr()); flush(stdout()) ### Name: umx_check ### Title: umx_check ### Aliases: umx_check ### ** Examples umx_check(length(1:3)==3, "message", "item must have length == 3", "another comment", "and another") umx_check(1==2, "message", "one must be 2", ". Another comment", "and another") cleanEx() nameEx("umx_check_OS") ### * umx_check_OS flush(stderr()); flush(stdout()) ### Name: umx_check_OS ### Title: umx_check_OS ### Aliases: umx_check_OS ### ** Examples umx_check_OS() cleanEx() nameEx("umx_check_model") ### * umx_check_model flush(stderr()); flush(stdout()) ### Name: umx_check_model ### Title: Check for required features in an OpenMx. ### Aliases: umx_check_model ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("check_model_ex", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D umx_check_model(m1) # TRUE, this is a model ##D umx_check_model(m1, type = "RAM") # equivalent to umx_is_RAM() ##D umx_check_model(m1, hasData = TRUE) ##D ##D ##D umx_check_model(m1, hasMeans = TRUE) ##D umx_check_model(m1, beenRun = FALSE) ##D # Model with no data ##D m1 = umxRAM("x ~~ .3*y", autoRun = FALSE) ##D umx_check_model(m1, hasData = TRUE) ## End(Not run) cleanEx() nameEx("umx_check_names") ### * umx_check_names flush(stderr()); flush(stdout()) ### Name: umx_check_names ### Title: Check if a request name exists in a dataframe or related object ### Aliases: umx_check_names ### ** Examples require(umx) data(demoOneFactor) # "x1" "x2" "x3" "x4" "x5" umx_check_names(c("x1", "x2"), demoOneFactor) umx_check_names(c("x1", "x2"), as.matrix(demoOneFactor)) umx_check_names(c("x1", "x2"), cov(demoOneFactor[, c("x1","x2")])) umx_check_names(c("x1", "x2"), mxData(demoOneFactor, type="raw")) umx_check_names(c("z1", "x2"), data = demoOneFactor, die = FALSE) umx_check_names(c("x1", "x2"), data = demoOneFactor, die = FALSE, no_others = TRUE) umx_check_names(c("x1","x2","x3","x4","x5"), data = demoOneFactor, die = FALSE, no_others = TRUE) # no request umx_check_names(c(), data = demoOneFactor, die = FALSE, no_others = TRUE) ## Not run: ##D # An example error from vars that don't exist in the data ##D umx_check_names(c("bad_var_name", "x2"), data = demoOneFactor, die = TRUE) ## End(Not run) cleanEx() nameEx("umx_check_parallel") ### * umx_check_parallel flush(stderr()); flush(stdout()) ### Name: umx_check_parallel ### Title: Check if OpenMx is using OpenMP, test cores, and get timings ### Aliases: umx_check_parallel ### ** Examples ## Not run: ##D # On a fast machine, takes a minute with 1 core ##D umx_check_parallel() ## End(Not run) cleanEx() nameEx("umx_cont_2_quantiles") ### * umx_cont_2_quantiles flush(stderr()); flush(stdout()) ### Name: umx_cont_2_quantiles ### Title: umx_cont_2_quantiles ### Aliases: umx_cont_2_quantiles umx2ord ### ** Examples x = umx_cont_2_quantiles(rnorm(1000), nlevels = 10, verbose = TRUE) x = data.frame(x) str(x); levels(x) table(x) ## Not run: ##D ggplot2::qplot(x$x) ##D y = mxDataWLS(x, type = "WLS") ## End(Not run) # =========================== # = Use with twin variables = # =========================== data(twinData) x = twinData cuts = umx_cont_2_quantiles(rbind(x$wt1, x$wt2) , nlevels = 10, returnCutpoints = TRUE) x$wt1 = umx_cont_2_quantiles(x$wt1, nlevels = cuts) # use same for both... x$wt2 = umx_cont_2_quantiles(x$wt2, nlevels = cuts) # use same for both... str(x[, c("wt1", "wt2")]) # More examples x = umx_cont_2_quantiles(mtcars[, "mpg"], nlevels = 5) # quintiles x = umx2ord(mtcars[, "mpg"], nlevels = 5) # using shorter alias x = umx_cont_2_quantiles(mtcars[, "cyl"], nlevels = 10) # more levels than integers exist x = umx_cont_2_quantiles(rbinom(10000, 1, .5), nlevels = 2) cleanEx() nameEx("umx_cor") ### * umx_cor flush(stderr()); flush(stdout()) ### Name: umx_cor ### Title: Report correlations and their p-values ### Aliases: umx_cor ### ** Examples tmp = myFADataRaw[1:8,1:8] umx_cor(tmp) tmp$x1 = letters[1:8] # make one column non-numeric umx_cor(tmp) cleanEx() nameEx("umx_explode") ### * umx_explode flush(stderr()); flush(stdout()) ### Name: umx_explode ### Title: Explode a string (Like the php function 'explode') ### Aliases: umx_explode ### ** Examples umx_explode("", "dog") # "d" "o" "g" umx_explode(" ", "cats and dogs") # [1] "cats" "and" "dogs" cleanEx() nameEx("umx_explode_twin_names") ### * umx_explode_twin_names flush(stderr()); flush(stdout()) ### Name: umx_explode_twin_names ### Title: Break twin variable names (BMI_T1, BMI_T2) into base variable ### names (BMI, "_T", 1:2) ### Aliases: umx_explode_twin_names ### ** Examples ## Not run: ##D require(umx) ##D data("twinData") ##D umx_explode_twin_names(twinData, sep = "") ##D umx_explode_twin_names(twinData, sep = NULL) ##D ##D # Ignore this: just a single-character/single variable test case ##D x = round(10 * rnorm(1000, mean = -.2)) ##D y = round(5 * rnorm(1000)) ##D x[x < 0] = 0; y[y < 0] = 0 ##D umx_explode_twin_names(data.frame(x_T1 = x, x_T2 = y), sep = "_T") ##D umx_explode_twin_names(data.frame(x_T11 = x, x_T22 = y), sep = "_T") ##D umx_explode_twin_names(c("x_T11", "x_T22"), sep = "_T") ## End(Not run) cleanEx() nameEx("umx_file_load_pseudo") ### * umx_file_load_pseudo flush(stderr()); flush(stdout()) ### Name: umx_file_load_pseudo ### Title: Read in files from pseudocons. ### Aliases: umx_file_load_pseudo ### ** Examples ## Not run: ##D basepath = "~/Dropbox/2016 (1). project EA/2018/EA3/" ##D tmp = umx_file_load_pseudo("PRS_EA3_R9_autosomes_HRC1.1_pseudo.txt", bp = bp) ##D str(tmp) ##D head(tmp[, c("BMIS4", "BMIS4_NT")] ## End(Not run) cleanEx() nameEx("umx_find_object") ### * umx_find_object flush(stderr()); flush(stdout()) ### Name: umx_find_object ### Title: umx_find_object ### Aliases: umx_find_object ### ** Examples ## Not run: ##D umx_find_object("^m[0-9]") # mxModels beginning "m1" etc. ##D umx_find_object("", "MxModel") # all MxModels ## End(Not run) cleanEx() nameEx("umx_fun_mean_sd") ### * umx_fun_mean_sd flush(stderr()); flush(stdout()) ### Name: umx_fun_mean_sd ### Title: Summarizing functions used in umx_aggregate and for umxAPA ### Aliases: umx_fun_mean_sd ### ** Examples umxAPA(mtcars[,1:3]) # uses umx_fun_mean_sd cleanEx() nameEx("umx_get_bracket_addresses") ### * umx_get_bracket_addresses flush(stderr()); flush(stdout()) ### Name: umx_get_bracket_addresses ### Title: Get bracket-style addresses from an mxMatrix ### Aliases: umx_get_bracket_addresses ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("get_add_ex", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D )#' ##D umx_get_bracket_addresses(m1$matrices$A, free= TRUE) ## End(Not run) cleanEx() nameEx("umx_get_checkpoint") ### * umx_get_checkpoint flush(stderr()); flush(stdout()) ### Name: umx_get_checkpoint ### Title: Get or set checkpointing for a model ### Aliases: umx_get_checkpoint ### ** Examples ## Not run: ##D umx_get_checkpoint() # current global default ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D umx_get_checkpoint(model = m1) ## End(Not run) cleanEx() nameEx("umx_get_options") ### * umx_get_options flush(stderr()); flush(stdout()) ### Name: umx_get_options ### Title: Display umx options ### Aliases: umx_get_options ### ** Examples umx_get_options() cleanEx() nameEx("umx_grep") ### * umx_grep flush(stderr()); flush(stdout()) ### Name: umx_grep ### Title: Search for text ### Aliases: umx_grep ### ** Examples umx_grep(mtcars, "hp", output="both", ignore.case= TRUE) umx_grep(c("hp", "ph"), "hp") umx_grep(mtcars, "^h.*", output="both", ignore.case= TRUE) ## Not run: ##D umx_grep(spss_df, "labeltext", output = "label") ##D umx_grep(spss_df, "labeltext", output = "name") ## End(Not run) cleanEx() nameEx("umx_has_CIs") ### * umx_has_CIs flush(stderr()); flush(stdout()) ### Name: umx_has_CIs ### Title: umx_has_CIs ### Aliases: umx_has_CIs ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("_has_CI_ex", data = demoOneFactor, type = "cov", ##D umxPath("g", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "g", fixedAt = 1.0) ##D ) ##D ##D umx_has_CIs(m1) # FALSE: no CIs and no output ##D m1 = mxModel(m1, mxCI("g_to_x1")) ##D umx_has_CIs(m1, check = "intervals") # TRUE intervals set ##D umx_has_CIs(m1, check = "output") # FALSE not yet run ##D m1 = mxRun(m1) ##D umx_has_CIs(m1, check = "output") # Still FALSE: Set and Run ##D m1 = mxRun(m1, intervals = TRUE) ##D umx_has_CIs(m1, check = "output") # TRUE: Set, and Run with intervals = T ##D umxSummary(m1) ## End(Not run) cleanEx() nameEx("umx_has_been_run") ### * umx_has_been_run flush(stderr()); flush(stdout()) ### Name: umx_has_been_run ### Title: umx_has_been_run ### Aliases: umx_has_been_run ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("has_been_run_example", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D umx_has_been_run(m1) ## End(Not run) cleanEx() nameEx("umx_has_means") ### * umx_has_means flush(stderr()); flush(stdout()) ### Name: umx_has_means ### Title: umx_has_means ### Aliases: umx_has_means ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("has_means_ex", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D ##D umx_has_means(m1) ##D m1 = mxModel(m1, ##D mxPath(from = "one", to = manifests), ##D mxData(demoOneFactor[1:100,], type = "raw") ##D ) ##D umx_has_means(m1) ##D m1 = mxRun(m1) ##D umx_has_means(m1) ##D ## End(Not run) cleanEx() nameEx("umx_has_square_brackets") ### * umx_has_square_brackets flush(stderr()); flush(stdout()) ### Name: umx_has_square_brackets ### Title: Check if a label contains square brackets ### Aliases: umx_has_square_brackets ### ** Examples umx_has_square_brackets("[hello]") umx_has_square_brackets("goodbye") cleanEx() nameEx("umx_is_MxData") ### * umx_is_MxData flush(stderr()); flush(stdout()) ### Name: umx_is_MxData ### Title: Check if an object is an mxData object ### Aliases: umx_is_MxData ### ** Examples umx_is_MxData(mtcars) umx_is_MxData(mxData(mtcars, type= "raw")) umx_is_MxData(mxData(cov(mtcars), type= "cov", numObs = 73)) umx_is_MxData(mxDataWLS(na.omit(twinData[, c("wt1", "wt2")]), type= "WLS")) cleanEx() nameEx("umx_is_MxMatrix") ### * umx_is_MxMatrix flush(stderr()); flush(stdout()) ### Name: umx_is_MxMatrix ### Title: umx_is_MxMatrix ### Aliases: umx_is_MxMatrix ### ** Examples x = mxMatrix(name = "eg", type = "Full", nrow = 3, ncol = 3, values = .3) if(umx_is_MxMatrix(x)){ message("nice OpenMx matrix!") } cleanEx() nameEx("umx_is_MxModel") ### * umx_is_MxModel flush(stderr()); flush(stdout()) ### Name: umx_is_MxModel ### Title: umx_is_MxModel ### Aliases: umx_is_MxModel ### ** Examples m1 = mxModel("test") if(umx_is_MxModel(m1)){ message("nice OpenMx model!") } if(umx_is_MxModel(list(m1,m1), listOK = TRUE)){ message("nice list of OpenMx models!") } cleanEx() nameEx("umx_is_RAM") ### * umx_is_RAM flush(stderr()); flush(stdout()) ### Name: umx_is_RAM ### Title: umx_is_RAM ### Aliases: umx_is_RAM ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("is_RAM_ex", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D ##D if(umx_is_RAM(m1)){ ##D message("nice RAM model!") ##D } ##D if(!umx_is_RAM(m1)){ ##D message("model needs to be a RAM model") ##D } ## End(Not run) cleanEx() nameEx("umx_is_class") ### * umx_is_class flush(stderr()); flush(stdout()) ### Name: umx_is_class ### Title: Check if variables in a dataframe are in a list of classes. ### Aliases: umx_is_class ### ** Examples umx_is_class(mtcars) # report class list # Are the variables in mtcars type character? umx_is_class(mtcars, "character") # FALSE # They're all numeric data umx_is_class(mtcars, "numeric") # TRUE # Show the test-result for each variable in mtcars umx_is_class(mtcars, "numeric") # TRUE # Are they _either_ a char OR a num? umx_is_class(mtcars, c("character", "numeric")) # Is zygosity a factor (note we don't drop = F to keep as dataframe) umx_is_class(twinData[,"zygosity", drop=FALSE], classes = "factor") umx_is_class(mtcars$mpg) # report class of this column (same as class(mpg)) cleanEx() nameEx("umx_is_cov") ### * umx_is_cov flush(stderr()); flush(stdout()) ### Name: umx_is_cov ### Title: umx_is_cov ### Aliases: umx_is_cov ### ** Examples df = cov(mtcars) umx_is_cov(df) df = cor(mtcars) umx_is_cov(df) umx_is_cov(mxData(df[1:3,1:3], type= "cov", numObs = 200)) umx_is_cov(df, boolean = TRUE) umx_is_cov(mtcars, boolean = TRUE) cleanEx() nameEx("umx_is_endogenous") ### * umx_is_endogenous flush(stderr()); flush(stdout()) ### Name: umx_is_endogenous ### Title: List endogenous variables in a model ### Aliases: umx_is_endogenous ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D m1 = umxRAM("umx_is_endogenous", data = demoOneFactor, type = "cov", ##D umxPath("g", to = names(demoOneFactor)), ##D umxPath(var = "g", fixedAt = 1), ##D umxPath(var = names(demoOneFactor)) ##D ) ##D umx_is_endogenous(m1, manifests_only = TRUE) ##D umx_is_endogenous(m1, manifests_only = FALSE) ##D ## End(Not run) cleanEx() nameEx("umx_is_exogenous") ### * umx_is_exogenous flush(stderr()); flush(stdout()) ### Name: umx_is_exogenous ### Title: umx_is_exogenous ### Aliases: umx_is_exogenous ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("g", to = names(demoOneFactor)), ##D umxPath(var = "g", fixedAt = 1), ##D umxPath(var = names(demoOneFactor)) ##D ) ##D umx_is_exogenous(m1, manifests_only = TRUE) ##D umx_is_exogenous(m1, manifests_only = FALSE) ##D ## End(Not run) cleanEx() nameEx("umx_is_numeric") ### * umx_is_numeric flush(stderr()); flush(stdout()) ### Name: umx_is_numeric ### Title: Check if variables in a dataframe are numeric ### Aliases: umx_is_numeric ### ** Examples umx_is_numeric(mtcars) # TRUE umx_is_numeric(mtcars, all=FALSE) # vector of TRUE cleanEx() nameEx("umx_is_ordered") ### * umx_is_ordered flush(stderr()); flush(stdout()) ### Name: umx_is_ordered ### Title: Test if one or more variables in a dataframe are ordered ### Aliases: umx_is_ordered ### ** Examples x = data.frame(ordered(rbinom(100,1,.5))); names(x) = c("x") umx_is_ordered(x, summaryObject= TRUE) # all ordered factors including binary tmp = mtcars tmp$cyl = ordered(mtcars$cyl) # ordered factor tmp$vs = ordered(mtcars$vs) # binary factor umx_is_ordered(tmp) # true/false umx_is_ordered(tmp, strict=FALSE) umx_is_ordered(tmp, names = TRUE) umx_is_ordered(tmp, names = TRUE, binary.only = TRUE) umx_is_ordered(tmp, names = TRUE, ordinal.only = TRUE) umx_is_ordered(tmp, names = TRUE, continuous.only = TRUE) umx_is_ordered(tmp, continuous.only = TRUE) x = umx_is_ordered(tmp, summaryObject= TRUE) isContinuous = !umx_is_ordered(tmp) ## Not run: ##D # nb: By default, unordered factors cause a message... ##D tmp$gear = factor(mtcars$gear) # Unordered factor ##D umx_is_ordered(tmp) ##D umx_is_ordered(tmp, strict = FALSE) # compare: no warning ##D ##D # also: not designed to work on single variables... ##D umx_is_ordered(tmp$cyl) ##D # Do this instead... ##D umx_is_ordered(tmp[, "cyl", drop= FALSE]) ## End(Not run) cleanEx() nameEx("umx_long2wide") ### * umx_long2wide flush(stderr()); flush(stdout()) ### Name: umx_long2wide ### Title: Take a long twin-data file and make it wide (one family per row) ### Aliases: umx_long2wide ### ** Examples ## Not run: ##D # ============================================== ##D # = First make a long format file for the demo = ##D # ============================================== ##D data(twinData) ##D tmp = twinData[, -2] ##D tmp$twinID1 = 1; tmp$twinID2 = 2 ##D long = umx_wide2long(data = tmp, sep = "") ##D str(long) ##D # 'data.frame': 7616 obs. of 11 variables: ##D # $ fam : int 1 2 3 4 5 6 7 8 9 10 ... ##D # $ zyg : int 1 1 1 1 1 1 1 1 1 1 ... ##D # $ part : int 2 2 2 2 2 2 2 2 2 2 ... ##D # $ cohort : chr "younger" "younger" "younger" "younger" ... ##D # $ zygosity: Factor w/ 5 levels "MZFF","MZMM",..: 1 1 1 1 1 1 1 1 1 1 ... ##D # $ wt : int 58 54 55 66 50 60 65 40 60 76 ... ##D # $ ht : num 1.7 1.63 1.65 1.57 1.61 ... ##D # $ htwt : num 20.1 20.3 20.2 26.8 19.3 ... ##D # $ bmi : num 21 21.1 21 23 20.7 ... ##D # $ age : int 21 24 21 21 19 26 23 29 24 28 ... ##D # $ twinID : num 1 1 1 1 1 1 1 1 1 1 ... ##D ##D # OK. Now to demo long2wide... ##D ##D # Keeping all columns ##D wide = umx_long2wide(data= long, famID= "fam", twinID= "twinID", zygosity= "zygosity") ##D namez(wide) # some vars, like part, should have been passed along instead of made into "part_T1" ##D ##D # ====================================== ##D # = Demo requesting specific vars2keep = ##D # ====================================== ##D ##D # Just keep bmi and wt ##D wide = umx_long2wide(data= long, famID= "fam", twinID= "twinID", ##D zygosity = "zygosity", vars2keep = c("bmi", "wt") ##D ) ##D ##D namez(wide) ##D # "fam" "twinID" "zygosity" "bmi_T1" "wt_T1" "bmi_T2" "wt_T2" ##D ##D # ================== ##D # = Demo passalong = ##D # ================== ##D # Keep bmi and wt, and pass through 'cohort' ##D wide = umx_long2wide(data= long, famID= "fam", twinID= "twinID", zygosity= "zygosity", ##D vars2keep = c("bmi", "wt"), passalong = "cohort" ##D ) ##D namez(wide) ##D ## End(Not run) cleanEx() nameEx("umx_lower.tri") ### * umx_lower.tri flush(stderr()); flush(stdout()) ### Name: umx_lower.tri ### Title: Get values from lower triangle of a matrix ### Aliases: umx_lower.tri ### ** Examples x = qm(1,2,3|4,5,6|7,8,9) umx_lower.tri(x) # 4,7,8 umx_lower.tri(x, diag=TRUE) # 1 4 7 5 8 9 cleanEx() nameEx("umx_lower2full") ### * umx_lower2full flush(stderr()); flush(stdout()) ### Name: umx_lower2full ### Title: Convert lower-only matrix data to full (or enforce symmetry on a ### full matrix) ### Aliases: umx_lower2full ### ** Examples # 1. Test with a vector in byrow = TRUE order) tmp = c( 1.0000, 0.6247, 1.0000, 0.3269, 0.3669, 1.0000, 0.4216, 0.3275, 0.6404, 1.0000, 0.2137, 0.2742, 0.1124, 0.0839, 1.0000, 0.4105, 0.4043, 0.2903, 0.2598, 0.1839, 1.0000, 0.3240, 0.4047, 0.3054, 0.2786, 0.0489, 0.2220, 1.0000, 0.2930, 0.2407, 0.4105, 0.3607, 0.0186, 0.1861, 0.2707, 1.0000, 0.2995, 0.2863, 0.5191, 0.5007, 0.0782, 0.3355, 0.2302, 0.2950, 1.0000, 0.0760, 0.0702, 0.2784, 0.1988, 0.1147, 0.1021, 0.0931, -0.0438, 0.2087, 1.000 ) x = umx_lower2full(tmp, diag = TRUE) # check isSymmetric(x) # 2. Test with matrix input tmpn = c("ROccAsp", "REdAsp", "FOccAsp", "FEdAsp", "RParAsp", "RIQ", "RSES", "FSES", "FIQ", "FParAsp") tmp = matrix(nrow = 10, ncol = 10, byrow = TRUE, dimnames = list(tmpn,tmpn), data = c(1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0, 0.6247, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0, 0.3269, 0.3669, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0, 0.4216, 0.3275, 0.6404, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0, 0.2137, 0.2742, 0.1124, 0.0839, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0, 0.4105, 0.4043, 0.2903, 0.2598, 0.1839, 1.0000, 0.0000, 0.0000, 0.0000, 0, 0.3240, 0.4047, 0.3054, 0.2786, 0.0489, 0.2220, 1.0000, 0.0000, 0.0000, 0, 0.2930, 0.2407, 0.4105, 0.3607, 0.0186, 0.1861, 0.2707, 1.0000, 0.0000, 0, 0.2995, 0.2863, 0.5191, 0.5007, 0.0782, 0.3355, 0.2302, 0.2950, 1.0000, 0, 0.0760, 0.0702, 0.2784, 0.1988, 0.1147, 0.1021, 0.0931, -0.0438, 0.2087, 1) ) x = umx_lower2full(tmp, diag= TRUE) isSymmetric(x) # 3. Test with lower-vector, no diagonal. tmp = c( 0.6247, 0.3269, 0.3669, 0.4216, 0.3275, 0.6404, 0.2137, 0.2742, 0.1124, 0.0839, 0.4105, 0.4043, 0.2903, 0.2598, 0.1839, 0.3240, 0.4047, 0.3054, 0.2786, 0.0489, 0.2220, 0.2930, 0.2407, 0.4105, 0.3607, 0.0186, 0.1861, 0.2707, 0.2995, 0.2863, 0.5191, 0.5007, 0.0782, 0.3355, 0.2302, 0.2950, 0.0760, 0.0702, 0.2784, 0.1988, 0.1147, 0.1021, 0.0931, -0.0438, 0.2087 ) umx_lower2full(tmp, diag = FALSE) # An example with byrow = FALSE ldiag = c( 1, -.17, -.22, -.19, -.12, .81, -.02, -.26, -.2, -.15, 1, .11, .2, .21, -.01, .7, .1, .7, .1, .17, .22, 1, .52, .68, -.12, .09, .49, .27, .46, 1, .5, -.06, .17, .26, .80, .31, 1, -.1, .19, .36, .23, .42, 1, .02, -19, -.06, -.06, 1, .1, .18, .27, 1, .51, .7, 1, .55, 1) umx_lower2full(tmp, byrow = FALSE, diag = TRUE) cleanEx() nameEx("umx_make") ### * umx_make flush(stderr()); flush(stdout()) ### Name: umx_make ### Title: "make" the umx package using devtools: release to CRAN etc. ### Aliases: umx_make ### ** Examples ## Not run: ##D # umx_make() # Just load new code (don't rebuild help etc) ##D # umx_make(what = "quickInst") # Quick install ##D # umx_make(what = "install") # Install the package ##D # umx_make(what = "spell") # Spell check the documents ##D # umx_make(what = "sitrep") # Are needed packages up to date? ##D # umx_make(what = "examples") # Run the examples ##D # umx_make(what = "checkCRAN") # Run R CMD check ##D # umx_make(what = "rhub") # Check on rhub ##D # umx_make(what = "win") # Check on win-builder ##D # umx_make(what = "release") # Release to CRAN ##D # tmp = umx_make(what = "lastRhub") # View rhub result ## End(Not run) cleanEx() nameEx("umx_make_MR_data") ### * umx_make_MR_data flush(stderr()); flush(stdout()) ### Name: umx_make_MR_data ### Title: Simulate Mendelian Randomization data ### Aliases: umx_make_MR_data ### ** Examples df = umx_make_MR_data(10000) str(df) ## Not run: ##D m1 = umxTwoStage(Y ~ X, ~qtl, data = df) ##D plot(m1) ## End(Not run) cleanEx() nameEx("umx_make_TwinData") ### * umx_make_TwinData flush(stderr()); flush(stdout()) ### Name: umx_make_TwinData ### Title: Simulate twin data with control over A, C, and E parameters, as ### well as moderation of A. ### Aliases: umx_make_TwinData ### ** 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")]) ## Not run: ##D ##D # =============== ##D # = GxE Example = ##D # =============== ##D ##D AA = c(avg = .5, min = .1, max = .8) ##D tmp = umx_make_TwinData(nMZpairs = 140, nDZpairs = 240, AA = AA, CC = .35, EE = .65, scale= TRUE) ##D mzData = tmp[tmp$zygosity == "MZ", ] ##D dzData = tmp[tmp$zygosity == "DZ", ] ##D m1 = umxGxE(selDVs = "var", selDefs = "M", sep = "_T", mzData = mzData, dzData = dzData) ##D ##D # ===================== ##D # = Threshold Example = ##D # ===================== ##D tmp = umx_make_TwinData(100, AA = .6, CC = .2, nThresh = 3) ##D str(tmp) ##D umx_polychoric(subset(tmp, zygosity=="MZ", c("var_T1", "var_T2")))$polychorics ##D # Running model with 7 parameters ##D # var_T1 var_T2 ##D # var_T1 1.0000000 0.7435457 ##D # var_T2 0.7435457 1.0000000 ##D ##D ##D # ================================================= ##D # = Just use MZr and DZr (also works with nSib>2) = ##D # ================================================= ##D tmp = umx_make_TwinData(100, MZr = .86, DZr = .60, nSib= 3, varNames = "IQ") ##D umxAPA(subset(tmp, zygosity == "MZ", paste0("IQ_T", 1:2))) ##D umxAPA(subset(tmp, zygosity == "DZ", paste0("IQ_T", 1:2))) ##D m1 = umxACE(selDVs= "IQ", data = tmp) ##D m1 = umxACE(selDVs= "IQ", data = tmp, nSib=3) ##D # TODO tmx_ examples of unmodeled D etc. ##D ##D # Bivariate GxSES example (see umxGxEbiv) ##D ##D AA = list(a11 = .4, a12 = .1, a22 = .15) ##D CC = list(c11 = .2, c12 = .1, c22 = .10) ##D EE = list(e11 = .4, e12 = .3, e22 = .25) ##D Amod = list(Beta_a1 = .025, Beta_a2 = .025) ##D Cmod = list(Beta_c1 = .025, Beta_c2 = .025) ##D Emod = list(Beta_e1 = .025, Beta_e2 = .025) ##D tmp = umx_make_TwinData(5000, AA =AA, CC = CC, EE = EE, ##D bivAmod = Amod, bivCmod =Cmod, bivEmod =Emod) ##D str(tmp) ##D # 'data.frame': 10000 obs. of 7 variables: ##D # $ defM_T1 : num 0.171 0.293 -0.173 0.238 -0.73 ... ##D # $ defM_T2 : num 0.492 -0.405 -0.696 -0.829 -0.858 ... ##D # $ M_T1 : num 0.171 0.293 -0.173 0.238 -0.73 ... ##D # $ var_T1 : num 0.011 0.1045 0.5861 0.0583 1.0225 ... ##D # $ M_T2 : num 0.492 -0.405 -0.696 -0.829 -0.858 ... ##D # $ var_T2 : num -0.502 -0.856 -0.154 0.065 -0.268 ... ##D # $ zygosity: Factor w/ 2 levels "MZ","DZ": 1 1 1 1 1 1 1 1 1 1 ... ##D ##D # TODO tmx example showing how moderation of A introduces heteroscedasticity in a regression model: ##D # More residual variance at one extreme of the x axis (moderator) ##D # m1 = lm(var_T1~ M_T1, data = x); ##D # x = rbind(tmp[[1]], tmp[[2]]) ##D # plot(residuals(m1)~ x$M_T1, data=x) ## End(Not run) cleanEx() nameEx("umx_make_fake_data") ### * umx_make_fake_data flush(stderr()); flush(stdout()) ### Name: umx_make_fake_data ### Title: umx_make_fake_data ### Aliases: umx_make_fake_data ### ** Examples fakeCars = umx_make_fake_data(mtcars) cleanEx() nameEx("umx_make_raw_from_cov") ### * umx_make_raw_from_cov flush(stderr()); flush(stdout()) ### Name: umx_make_raw_from_cov ### Title: Turn a cov matrix into raw data ### Aliases: umx_make_raw_from_cov ### ** Examples covData <- matrix(nrow=6, ncol=6, byrow=TRUE, dimnames=list(paste0("v", 1:6), paste0("v", 1:6)), data = c(0.9223099, 0.1862938, 0.4374359, 0.8959973, 0.9928430, 0.5320662, 0.1862938, 0.2889364, 0.3927790, 0.3321639, 0.3371594, 0.4476898, 0.4374359, 0.3927790, 1.0069552, 0.6918755, 0.7482155, 0.9013952, 0.8959973, 0.3321639, 0.6918755, 1.8059956, 1.6142005, 0.8040448, 0.9928430, 0.3371594, 0.7482155, 1.6142005, 1.9223567, 0.8777786, 0.5320662, 0.4476898, 0.9013952, 0.8040448, 0.8777786, 1.3997558) ) myData = umx_make_raw_from_cov(covData, n = 100, means = 1:6) umxAPA(myData) covMat = matrix(c(1, .3, .3, 1), nrow=2) tmp= umx_make_raw_from_cov(covMat, n=10, varNames= c("x", "y")) cov(tmp) tmp= umx_make_raw_from_cov(covMat, n=10, varNames= c("x", "y"), empirical= TRUE) cov(tmp) tmp= umx_make_raw_from_cov(qm(1, .3| .3, 1), n=10, varNames= c("x", "y")) cov(tmp) cleanEx() nameEx("umx_make_sql_from_excel") ### * umx_make_sql_from_excel flush(stderr()); flush(stdout()) ### Name: umx_make_sql_from_excel ### Title: Convert an excel spreadsheet in a text file on sql statements. ### Aliases: umx_make_sql_from_excel ### ** Examples ## Not run: ##D # An example Excel spreadsheet ##D # local uncompiled path ##D fp = system.file("inst/extdata", "GQ6.sql.xlsx", package = "umx") ##D # installed path ##D fp = system.file("extdata", "GQ6.sql.xlsx", package = "umx") ##D umx_open(fp) ##D umx_make_sql_from_excel() # Using file selected in front-most Finder window ##D umx_make_sql_from_excel("~/Desktop/test.xlsx") # provide a path ## End(Not run) cleanEx() nameEx("umx_make_twin_data_nice") ### * umx_make_twin_data_nice flush(stderr()); flush(stdout()) ### Name: umx_make_twin_data_nice ### Title: Convert a twin dataset into umx standard format. ### Aliases: umx_make_twin_data_nice ### ** Examples data(twinData) tmp = twinData tmp2 = umx_make_twin_data_nice(twinData, sep="", numbering = 1:5, zygosity="zygosity") tmp$zygosity=NULL tmp = umx_make_twin_data_nice(twinData, sep="", numbering = 1:5, zygosity="zygosity") namez(tmp, "zyg") levels(tmp$zygosity) cleanEx() nameEx("umx_means") ### * umx_means flush(stderr()); flush(stdout()) ### Name: umx_means ### Title: umx_means ### Aliases: umx_means ### ** Examples tmp = mtcars[,1:4] tmp$cyl = ordered(mtcars$cyl) # ordered factor tmp$hp = ordered(mtcars$hp) # binary factor umx_means(tmp, ordVar = 0, na.rm = TRUE) cleanEx() nameEx("umx_merge_randomized_columns") ### * umx_merge_randomized_columns flush(stderr()); flush(stdout()) ### Name: umx_merge_randomized_columns ### Title: umx_merge_randomized_columns ### Aliases: umx_merge_randomized_columns ### ** Examples ## Not run: ##D fp = "~/Desktop/Political Ideology_September 13, 2022_10.47.xlsx" ##D df = readxl::read_excel(fp) ##D df = df[c(-1,-2), ] # delete temp data and question text ##D df = data.frame(df) ##D namez(df, "ris", coll = "vec") # c('RiskAversionNoLotter', 'RiskAversionLottery') ##D colNames= c('RiskAversionNoLotter', 'RiskAversionLottery') ##D df = umx_as_numeric(df, colNames, force=TRUE) ##D tmp = umx_merge_randomized_columns(colNames, df); table(tmp$condition) ##D tmp = umx_merge_randomized_columns(colNames, df, ##D levels = c("treatment", "control")); table(tmp$condition) ## End(Not run) cleanEx() nameEx("umx_move_file") ### * umx_move_file flush(stderr()); flush(stdout()) ### Name: umx_move_file ### Title: Move files ### Aliases: umx_move_file ### ** Examples ## Not run: ##D base = "~/Desktop/" ##D dest = "~/Music/iTunes/iTunes Music/Music/" ##D umx_move_file(baseFolder = base, fileNameList = toMove, destFolder = dest, test= TRUE) ##D ##D # ============================================================ ##D # = Move all files in downloads ending in ".jpeg" to Desktop = ##D # ============================================================ ##D umx_move_file(baseFolder = "~/Downloads/", regex=".jpeg", ##D destFolder = "~/Desktop/", test= TRUE) ## End(Not run) cleanEx() nameEx("umx_msg") ### * umx_msg flush(stderr()); flush(stdout()) ### Name: umx_msg ### Title: Print the name and compact contents of variable. ### Aliases: umx_msg ### ** Examples a = "brian" umx_msg(a) b = c("brian", "sally", "jane") umx_msg(b) umx_msg(mtcars) cleanEx() nameEx("umx_names") ### * umx_names flush(stderr()); flush(stdout()) ### Name: umx_names ### Title: umx_names ### Aliases: umx_names namez ### ** Examples # Names from a dataframe, with character matching umx_names(mtcars, "mpg") # only "mpg" matches this # Easy-to-type alias "namez" namez(mtcars, "mpg") # Use a regular expression to match a pattern namez(mtcars, "r[ab]") # "drat", "carb" namez(mtcars, "^d") # vars beginning with 'd' = "disp", drat # Use this function to replace text in names! umx_names(mtcars, "mpg", replacement = "hello") # "mpg" replaced with "hello" # ======================================================================== # = Using the custom collapse option to quote each item, and wrap in c() = # ======================================================================== namez(mtcars, "m", collapse = "vector") # Paste-able R-code for a vector # Other options passed to R's grep command umx_names(mtcars, "mpg" , invert = TRUE) # Non-matches (instead of matches) umx_names(mtcars, "disp", value = FALSE) # Return indices of matches umx_names(mtcars, "^d" , fixed = TRUE) # Vars containing literal '^d' (none...) # ======================================= # = Examples using built-in GFF dataset = # ======================================= # Just show phenotypes for Twin 1 umx_names(GFF, "_T1$") # twin 1 # "zyg" "sex1" "age_T1" "gff_T1" "fc_T1" "qol_T1" "hap_T1"... umx_names(GFF, "2$") # names ending in 2 umx_names(GFF, "[^12bs]$") # doesn't end in `1`, `2`, `b`, or `s` # "zyg_6grp" "zyg_2grp" "divorce" umx_names(mxData(twinData[, c("wt1", "wt2")], type= "raw")) umx_names(mxData(cov(twinData[, c("wt1", "wt2")], use="comp"), type= "cov", numObs= 1000)) umx_names(mxDataWLS(na.omit(twinData[, c("wt1", "wt2")]), type= "WLS")) namez(umxMatrix("bob", "Full", 3,3)$labels) cleanEx() nameEx("umx_open") ### * umx_open flush(stderr()); flush(stdout()) ### Name: umx_open ### Title: Open a file or folder ### Aliases: umx_open ### ** Examples ## Not run: ##D umx_open() # Default is to open working directory getwd() ##D umx_open("~/bin/umx/R/misc_and_utility copy.r") ## End(Not run) cleanEx() nameEx("umx_open_CRAN_page") ### * umx_open_CRAN_page flush(stderr()); flush(stdout()) ### Name: umx_open_CRAN_page ### Title: Open the CRAN page for a package ### Aliases: umx_open_CRAN_page ### ** Examples ## Not run: ##D umx_open_CRAN_page("umx") ## End(Not run) cleanEx() nameEx("umx_pad") ### * umx_pad flush(stderr()); flush(stdout()) ### Name: umx_pad ### Title: Pad an Object with NAs ### Aliases: umx_pad ### ** Examples umx_pad(1:3, 4) umx_pad(1:3, 3) cleanEx() nameEx("umx_paste_names") ### * umx_paste_names flush(stderr()); flush(stdout()) ### Name: umx_paste_names ### Title: Concatenate base variable names with suffixes to create ### wide-format variable names (i.e twin-format) ### Aliases: umx_paste_names tvars ### ** Examples # two styles doing the same thing: first is more general umx_paste_names("bmi", suffixes = c("_T1", "_T2")) umx_paste_names("bmi", sep = "_T", suffixes = 1:2) varNames = umx_paste_names(c("N", "E", "O", "A", "C"), "_T", 1:2) umx_paste_names(c("IQ", "C"), cov = c("age"), sep = "_T", suffixes = 1:2) umx_paste_names(c("IQ", "C"), cov = c("age"), sep = "_T", prefix= "mean_") # For quick-typing, tvars is an alias for umx_paste_names tvars(c("IQ", "C"), cov = "age", sep = "_T", prefix= "mean_") tvars("IQ") cleanEx() nameEx("umx_polychoric") ### * umx_polychoric flush(stderr()); flush(stdout()) ### Name: umx_polychoric ### Title: FIML-based polychoric, polyserial, and Pearson correlations ### Aliases: umx_polychoric ### ** Examples ## Not run: ##D tmp = mtcars ##D tmp$am = umxFactor(mtcars$am) ##D tmp$vs = umxFactor(mtcars$vs) ##D tmp = umx_scale(tmp) ##D x = umx_polychoric(tmp[, c("am", "vs")], tryHard = "yes") ##D x$polychorics ##D cor(mtcars[, c("am", "vs")]) ##D ## End(Not run) cleanEx() nameEx("umx_polypairwise") ### * umx_polypairwise flush(stderr()); flush(stdout()) ### Name: umx_polypairwise ### Title: FIML-based Pairwise polychoric, polyserial, and Pearson ### correlations ### Aliases: umx_polypairwise ### ** Examples umx_set_optimizer("SLSQP") tmp = mtcars tmp$am = umxFactor(mtcars$am) tmp$vs = umxFactor(mtcars$vs) tmp = umx_scale(tmp) x = umx_polypairwise(tmp[, c("hp", "mpg", "am", "vs")], tryHard = "yes") x$R cov2cor(x$R) cor(mtcars[, c("hp", "mpg", "am", "vs")]) cleanEx() nameEx("umx_polytriowise") ### * umx_polytriowise flush(stderr()); flush(stdout()) ### Name: umx_polytriowise ### Title: FIML-based trio-based polychoric, polyserial, and Pearson ### correlations ### Aliases: umx_polytriowise ### ** Examples tmp = mtcars tmp$am = umxFactor(mtcars$am) tmp$vs = umxFactor(mtcars$vs) tmp = umx_scale(tmp) x = umx_polytriowise(tmp[, c("hp", "mpg", "am", "vs")], tryHard = "yes") x$R cor(mtcars[, c("hp", "mpg", "am", "vs")]) cleanEx() nameEx("umx_print") ### * umx_print flush(stderr()); flush(stdout()) ### Name: umx_print ### Title: Print tables in a range of formats (markdown default, see ### 'umx_set_table_format()' for other formats) or as a web browser ### table. ### Aliases: umx_print ### ** Examples data(mtcars) umx_print(mtcars[1:10,], digits = 2, zero.print = ".", justify = "left") umx_print(mtcars[1,1:2], digits = 2, zero.print = "") umx_print(mtcars[1,1:2], digits = 2, caption = "Hi: I'm the caption!") ## Not run: ##D umx_print(mtcars[1:10,], report = "html") ## End(Not run) cleanEx() nameEx("umx_r_test") ### * umx_r_test flush(stderr()); flush(stdout()) ### Name: umx_r_test ### Title: Test the difference between correlations for significance. ### Aliases: umx_r_test ### ** Examples # Is the correlation of mpg with cylinder count different from that # obtaining between disp and hp? vars = c("mpg", "cyl", "disp", "hp") umx_r_test(mtcars, vars) umx_r_test(mtcars, c("mpg", "disp", "hp")) cleanEx() nameEx("umx_read_lower") ### * umx_read_lower flush(stderr()); flush(stdout()) ### Name: umx_read_lower ### Title: Read lower-triangle of data matrix from console or file ### Aliases: umx_read_lower ### ** Examples ## Not run: ##D require(umx) # for umxRAM ##D IQtests = c("brainstorm", "matrix", "moral", "shopping", "typing") ##D allCols = c("C", IQtests, "avgIQ", "maxIQ", "video") ##D ##D df = umx_read_lower(diag = FALSE, names = allCols) ##D 0.38 ##D 0.86 0.30 ##D 0.42 0.12 0.27 ##D 0.66 0.21 0.38 0.18 ##D 0.80 0.13 0.50 0.25 0.43 ##D 0.19 0.11 0.19 0.12 -0.06 0.22 ##D 0.27 0.09 0.33 0.05 -0.04 0.28 .73 ##D 0.52 0.17 0.38 0.37 0.39 0.44 0.18 0.13 ##D ##D dimnames(df) = list(allCols, allCols) # manually add ##D ##D df = umx_read_lower(file = "", diag = FALSE, names = allCols, ensurePD= TRUE) ##D 0.38 ##D 0.86 0.30 ##D 0.42 0.12 0.27 ##D 0.66 0.21 0.38 0.18 ##D 0.80 0.13 0.50 0.25 0.43 ##D 0.19 0.11 0.19 0.12 -0.06 0.22 ##D 0.27 0.09 0.33 0.05 -0.04 0.28 .73 ##D 0.52 0.17 0.38 0.37 0.39 0.44 0.18 0.13 ##D ##D ##D round(df, 2) ##D ##D m1 = umxRAM("wooley", data = mxData(df, type="cov", numObs = 90), ##D umxPath("g", to = IQtests), ##D umxPath(var = "g", fixedAt= 1), ##D umxPath(var = IQtests) ##D ) ##D summary(m1) ## End(Not run) cleanEx() nameEx("umx_read_prolific_demog") ### * umx_read_prolific_demog flush(stderr()); flush(stdout()) ### Name: umx_read_prolific_demog ### Title: Read and optionally merge demographics file from prolific ### academic ### Aliases: umx_read_prolific_demog ### ** Examples ## Not run: ##D fp = "~/Desktop/prolific_export_5f20c3e662e3b6407dcd37a5.csv" ##D df = umx_read_prolific_demog(fp, sex = "gender", df = df) ##D tmp = umx_read_prolific_demog(fp, by.df = "PROLIFIC_PID", vars=c("EthnicitySimplified")) ## End(Not run) cleanEx() nameEx("umx_rename") ### * umx_rename flush(stderr()); flush(stdout()) ### Name: umx_rename ### Title: umx_rename ### Aliases: umx_rename ### ** Examples tmp = mtcars tmp = umx_rename(tmp, to = c(cyl = "cylinder")) # let's check cyl has been changed to cylinder... namez(tmp, "c") # Alternate style: from->to, first with a test-run # Dry run tmp = umx_rename(tmp, from = "disp", to = "displacement", test= TRUE) # Actually do it tmp = umx_rename(tmp, from = c("disp"), to = c("displacement")) umx_check_names("displacement", data = tmp, die = TRUE) namez(tmp, "disp") # This will warn that "disp" does not exist (anymore) new = c("auto", "displacement", "rear_axle_ratio") tmp = umx_rename(tmp, from = c("am", "disp", "drat"), to = new) namez(tmp, "a") # still updated am to auto (and rear_axle_ratio) # Test using regex (in this case to revert "displacement" to "disp") tmp = umx_rename(tmp, regex = "lacement", to = "", test= TRUE) tmp = umx_rename(tmp, regex = "lacement", to = "") # revert to disp umx_names(tmp, "^d") # all names beginning with a d # dev: check deprecated format handled... tmp = umx_rename(tmp, old = c("am", "disp", "drat"), replace = new) cleanEx() nameEx("umx_rename_file") ### * umx_rename_file flush(stderr()); flush(stdout()) ### Name: umx_rename_file ### Title: Rename files ### Aliases: umx_rename_file ### ** Examples ## Not run: ##D # "Season 01" --> "S01" in current folder in MacOS Finder ##D umx_rename_file("[Ss]eason +([0-9]+)", replaceStr="S\\1", test = TRUE) ##D ##D # move date to end of file name ##D umx_rename_file("^(.*) *([0-9]{2}\\.[0-9]{2}\\.[0-9]+) *(.*)", replaceStr="\\1 \\3 \\2") ##D ## End(Not run) cleanEx() nameEx("umx_reorder") ### * umx_reorder flush(stderr()); flush(stdout()) ### Name: umx_reorder ### Title: Reorder or drop variables from a correlation/covariance matrix. ### Aliases: umx_reorder ### ** Examples oldMatrix = cov(mtcars) umx_reorder(oldMatrix, newOrder = c("mpg", "cyl", "disp")) # first 3 umx_reorder(oldMatrix, newOrder = c("hp", "disp", "cyl")) # subset and reordered umx_reorder(oldMatrix, "hp") # edge-case of just 1-var cleanEx() nameEx("umx_residualize") ### * umx_residualize flush(stderr()); flush(stdout()) ### Name: umx_residualize ### Title: Easily residualize variables in long or wide dataframes, ### returning them changed in-place. ### Aliases: umx_residualize ### ** Examples # Residualize mpg on cylinders and displacement r1 = umx_residualize("mpg", c("cyl", "disp"), data = mtcars) r2 = residuals(lm(mpg ~ cyl + disp, data = mtcars, na.action = na.exclude)) all(r1$mpg == r2) # ============================= # = Use the formula interface = # ============================= r1 = umx_residualize(mpg ~ cyl + I(cyl^2) + disp, data = mtcars) # validate against using lm r2 = residuals(lm(mpg ~ cyl + I(cyl^2) + disp, data = mtcars, na.action = na.exclude)) all(r1$mpg == r2) # =========================================================== # = Residualize twin data (i.e. wide or "1 family per row") = # =========================================================== # Make some toy "twin" data to demonstrate with tmp = mtcars tmp$mpg_T1 = tmp$mpg_T2 = tmp$mpg tmp$cyl_T1 = tmp$cyl_T2 = tmp$cyl tmp$disp_T1 = tmp$disp_T2 = tmp$disp covs = c("cyl", "disp") tmp= umx_residualize(var="mpg", covs=covs, suffixes=c("_T1","_T2"), data = tmp) str(tmp[1:5, 12:17]) # =================================== # = Residualize several DVs at once = # =================================== df1 = umx_residualize(c("mpg", "hp"), cov = c("cyl", "disp"), data = tmp) df2 = residuals(lm(hp ~ cyl + disp, data = tmp, na.action = na.exclude)) all(df1$hp == df2) cleanEx() nameEx("umx_rot") ### * umx_rot flush(stderr()); flush(stdout()) ### Name: umx_rot ### Title: Rotate a vector ### Aliases: umx_rot ### ** Examples umx_rot(1:10) umx_rot(c(3,4,5,6,7)) # [1] 4 5 6 7 3 cleanEx() nameEx("umx_round") ### * umx_round flush(stderr()); flush(stdout()) ### Name: umx_round ### Title: umx_round ### Aliases: umx_round ### ** Examples head(umx_round(mtcars, coerce = FALSE)) head(umx_round(mtcars, coerce = TRUE)) cleanEx() nameEx("umx_scale") ### * umx_scale flush(stderr()); flush(stdout()) ### Name: umx_scale ### Title: Scale data columns, skipping non-scalable columns ### Aliases: umx_scale ### ** Examples data(twinData) df = umx_scale(twinData, varsToScale = c("wt1", "wt2")) df = umx_scale(twinData, attr= TRUE) plot(wt1 ~ wt2, data = df) cleanEx() nameEx("umx_scale_wide_twin_data") ### * umx_scale_wide_twin_data flush(stderr()); flush(stdout()) ### Name: umx_scale_wide_twin_data ### Title: Scale wide twin data ### Aliases: umx_scale_wide_twin_data ### ** Examples data(twinData) df = umx_scale_wide_twin_data(data = twinData, varsToScale = c("ht", "wt"), sep = "") plot(wt1 ~ wt2, data = df) cleanEx() nameEx("umx_score_scale") ### * umx_score_scale flush(stderr()); flush(stdout()) ### Name: umx_score_scale ### Title: Score a psychometric scale by summing normal and reversed items. ### Aliases: umx_score_scale ### ** Examples library(psych) library(psychTools) data(bfi) # ============================== # = Score Agreeableness totals = # ============================== # Handscore subject 1 # A1(R)+A2+A3+A4+A5 = (6+1)-2 +4+3+4+4 = 20 tmp = umx_score_scale(base = "A", pos = 2:5, rev = 1, max = 6, data= bfi, name = "A") tmp[1, namez(tmp, "A",ignore.case = FALSE)] # A1 A2 A3 A4 A5 A # 2 4 3 4 4 20 # ==================== # = Request the mean = # ==================== tmp = umx_score_scale(name = "A", base = "A", pos = 2:5, rev = 1, max = 6, data= bfi, score="mean") tmp$A[1] # = 4 # ================== # = na.rm = TRUE ! = # ================== tmpDF = bfi tmpDF[1, "A1"] = NA tmp = umx_score_scale("A", pos = 2:5, rev = 1, max = 6, data= tmpDF, score="mean") tmp$A_score[1] # 3.75 tmp= umx_score_scale("A", pos= 2:5, rev= 1, max = 6, data = tmpDF, score="mean", na.rm=FALSE) tmp$A_score[1] # NA (reject cases with missing items) # =============== # = Score = max = # =============== tmp = umx_score_scale("A", pos = 2:5, rev = 1, max = 6, data = bfi, name = "A", score = "max") tmp$A[1] # Subject 1 max = 5 (reversed) item 1 # Default scale name tmp = umx_score_scale("E", pos = 3:5, rev = 1:2, max = 6, data= tmp, score = "mean", na.rm=FALSE) tmp$E_score[1] # Using @BillRevelle's psych package: More diagnostics, including alpha scores= psych::scoreItems(items = bfi, min = 1, max = 6, keys = list( E = c("-E1","-E2", "E3", "E4", "E5"), A = c("-A1", "A2", "A3", "A4", "A5") )) summary(scores) scores$scores[1, ] # E A # 3.8 4.0 # Compare output # (note, by default psych::scoreItems replaces NAs with the sample median...) RevelleE = as.numeric(scores$scores[,"E"]) RevelleE == tmp[,"E_score"] # ======================= # = MapStrings examples = # ======================= mapStrings = c( "Very Inaccurate", "Moderately Inaccurate", "Slightly Inaccurate", "Slightly Accurate", "Moderately Accurate", "Very Accurate") bfi$As1 = factor(bfi$A1, levels = 1:6, labels = mapStrings) bfi$As2 = factor(bfi$A2, levels = 1:6, labels = mapStrings) bfi$As3 = factor(bfi$A3, levels = 1:6, labels = mapStrings) bfi$As4 = factor(bfi$A4, levels = 1:6, labels = mapStrings) bfi$As5 = factor(bfi$A5, levels = 1:6, labels = mapStrings) bfi= umx_score_scale(name="A" , base="A", pos=2:5, rev=1, max=6, data=bfi) bfi= umx_score_scale(name="As", base="As", pos=2:5, rev=1, mapStrings = mapStrings, data= bfi) cleanEx() nameEx("umx_select_valid") ### * umx_select_valid flush(stderr()); flush(stdout()) ### Name: umx_select_valid ### Title: Update NA values in one column with valid entries from another ### Aliases: umx_select_valid ### ** Examples tmp = mtcars tmp$newDisp = tmp$disp tmp$disp[c(1,3,6)] = NA anyNA(tmp$disp) # column has NAs tmp = umx_select_valid("disp", "newDisp", data = tmp) anyNA(tmp$disp) # column repaired cleanEx() nameEx("umx_set_auto_plot") ### * umx_set_auto_plot flush(stderr()); flush(stdout()) ### Name: umx_set_auto_plot ### Title: umx_set_auto_plot ### Aliases: umx_set_auto_plot ### ** Examples library(umx) umx_set_auto_plot() # print current state old = umx_set_auto_plot(silent = TRUE) # store existing value old umx_set_auto_plot(TRUE) # set to on (internally stored as "name") umx_set_auto_plot(FALSE) # set to off (internally stored as NA) umx_set_auto_plot(old) # reinstate cleanEx() nameEx("umx_set_auto_run") ### * umx_set_auto_run flush(stderr()); flush(stdout()) ### Name: umx_set_auto_run ### Title: Automatically run models? ### Aliases: umx_set_auto_run ### ** Examples library(umx) umx_set_auto_run() # print existing value old = umx_set_auto_run(silent = TRUE) # store existing value umx_set_auto_run(FALSE) # set to FALSE umx_set_auto_run(old) # reinstate cleanEx() nameEx("umx_set_checkpoint") ### * umx_set_checkpoint flush(stderr()); flush(stdout()) ### Name: umx_set_checkpoint ### Title: umx_set_checkpoint ### Aliases: umx_set_checkpoint umx_checkpoint ### ** Examples ## Not run: ##D umx_set_checkpoint(interval = 1, "evaluations", dir = "~/Desktop/") ##D # Turn off checkpointing with interval = 0 ##D umx_set_checkpoint(interval = 0) ##D umx_set_checkpoint(2, "evaluations", prefix="SNP_1") ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D m1 = umx_set_checkpoint(model = m1) ##D m1 = mxRun(m1) ##D umx_checkpoint(0) ## End(Not run) cleanEx() nameEx("umx_set_condensed_slots") ### * umx_set_condensed_slots flush(stderr()); flush(stdout()) ### Name: umx_set_condensed_slots ### Title: umx_set_condensed_slots ### Aliases: umx_set_condensed_slots ### ** Examples library(umx) umx_set_condensed_slots() # print old = umx_set_condensed_slots(silent = TRUE) # store the existing state umx_set_condensed_slots(TRUE) # update globally umx_set_condensed_slots(old) # set back cleanEx() nameEx("umx_set_cores") ### * umx_set_cores flush(stderr()); flush(stdout()) ### Name: umx_set_cores ### Title: umx_set_cores ### Aliases: umx_set_cores ### ** Examples library(umx) manifests = c("mpg", "disp", "gear") m1 = mxModel("ind", type = "RAM", manifestVars = manifests, mxPath(from = manifests, arrows = 2), mxPath(from = "one", to = manifests), mxData(mtcars[, manifests], type = "raw") ) umx_set_cores() # print current value oldCores = umx_set_cores(silent = TRUE) # store existing value umx_set_cores(omxDetectCores()) # set to max umx_set_cores(-1); umx_set_cores() # set to max m1 = umx_set_cores(1, m1) # set m1 usage to 1 core umx_set_cores(model = m1) # show new value for m1 umx_set_cores(oldCores) # reinstate old global value cleanEx() nameEx("umx_set_data_variance_check") ### * umx_set_data_variance_check flush(stderr()); flush(stdout()) ### Name: umx_set_data_variance_check ### Title: umx_set_data_variance_check ### Aliases: umx_set_data_variance_check ### ** Examples library(umx) umx_set_data_variance_check() # print current state old = umx_set_data_variance_check(silent = TRUE) # store existing value umx_set_data_variance_check(minVar = .01) umx_set_data_variance_check(maxVarRatio = 500) umx_set_data_variance_check(minVar = old$minVar, maxVarRatio = old$maxVarRatio) # reinstate cleanEx() nameEx("umx_set_dollar_symbol") ### * umx_set_dollar_symbol flush(stderr()); flush(stdout()) ### Name: umx_set_dollar_symbol ### Title: Set the symbol for money ### Aliases: umx_set_dollar_symbol ### ** Examples library(umx) umx_set_dollar_symbol() # show current state old = umx_set_dollar_symbol(silent=TRUE) # store existing value fin_interest(100) umx_set_dollar_symbol(old) # reinstate cleanEx() nameEx("umx_set_optimization_options") ### * umx_set_optimization_options flush(stderr()); flush(stdout()) ### Name: umx_set_optimization_options ### Title: Set options that affect optimization in OpenMx ### Aliases: umx_set_optimization_options ### ** Examples # show current value for selected or all options umx_set_optimization_options() # print the existing state(s) umx_set_optimization_options("mvnRelEps") ## Not run: ##D umx_set_optimization_options("mvnRelEps", .01) # update globally ##D umx_set_optimization_options("Parallel diagnostics", value = "Yes") ## End(Not run) cleanEx() nameEx("umx_set_optimizer") ### * umx_set_optimizer flush(stderr()); flush(stdout()) ### Name: umx_set_optimizer ### Title: Set the optimizer in OpenMx ### Aliases: umx_set_optimizer ### ** Examples library(umx) umx_set_optimizer() # print the existing state old = umx_set_optimizer(silent = TRUE) # store the existing state umx_set_optimizer("SLSQP") # update globally umx_set_optimizer(old) # set back cleanEx() nameEx("umx_set_plot_file_suffix") ### * umx_set_plot_file_suffix flush(stderr()); flush(stdout()) ### Name: umx_set_plot_file_suffix ### Title: Set output suffix used in umx SEM diagram files saved to disk. ### Aliases: umx_set_plot_file_suffix ### ** Examples umx_set_plot_file_suffix() # print current state old = umx_set_plot_file_suffix(silent = TRUE) # store current value umx_set_plot_file_suffix("dot") umx_set_plot_file_suffix("gv") umx_set_plot_file_suffix(old) # reinstate cleanEx() nameEx("umx_set_plot_format") ### * umx_set_plot_format flush(stderr()); flush(stdout()) ### Name: umx_set_plot_format ### Title: Set output format of plots (structural diagrams) in umx ### Aliases: umx_set_plot_format ### ** Examples library(umx) umx_set_plot_format() # print current state old = umx_set_plot_format(silent = TRUE) # store current value umx_set_plot_format("graphviz") umx_set_plot_format("DiagrammeR") umx_set_plot_format("png") umx_set_plot_format("pdf") umx_set_plot_format(old) # reinstate cleanEx() nameEx("umx_set_plot_use_hrbrthemes") ### * umx_set_plot_use_hrbrthemes flush(stderr()); flush(stdout()) ### Name: umx_set_plot_use_hrbrthemes ### Title: Set theme system to use for plots. ### Aliases: umx_set_plot_use_hrbrthemes ### ** Examples umx_set_plot_use_hrbrthemes() # print current state old = umx_set_plot_use_hrbrthemes(silent = TRUE) # store current value umx_set_plot_use_hrbrthemes(TRUE) umx_set_plot_use_hrbrthemes(old) # reinstate cleanEx() nameEx("umx_set_separator") ### * umx_set_separator flush(stderr()); flush(stdout()) ### Name: umx_set_separator ### Title: Set the separator ### Aliases: umx_set_separator ### ** Examples library(umx) umx_set_separator() # show current state old = umx_set_separator(silent=TRUE) # store existing value umx_set_separator("|") umxAPA(.3, .2) umx_set_separator(old) # reinstate cleanEx() nameEx("umx_set_silent") ### * umx_set_silent flush(stderr()); flush(stdout()) ### Name: umx_set_silent ### Title: Turn off most console and summary output from umx ### Aliases: umx_set_silent ### ** Examples library(umx) old = umx_set_silent() # print & store existing value umx_set_silent(FALSE, silent = TRUE) # set to FALSE umx_set_silent(old) # reinstate umx_set_silent() # print existing value cleanEx() nameEx("umx_set_table_format") ### * umx_set_table_format flush(stderr()); flush(stdout()) ### Name: umx_set_table_format ### Title: umx_set_table_format ### Aliases: umx_set_table_format ### ** Examples library(umx) umx_set_table_format() # show current state old = umx_set_table_format() # store existing value umx_set_table_format("latex") umx_set_table_format("html") umx_set_table_format("markdown") umx_set_table_format("") # get available options umx_set_table_format(old) # reinstate cleanEx() nameEx("umx_stack") ### * umx_stack flush(stderr()); flush(stdout()) ### Name: umx_stack ### Title: Stack data like stack() does, with more control. ### Aliases: umx_stack ### ** Examples # Base-R stack function df = stack(mtcars, select = c("disp", "hp"), drop=FALSE) # umx_stack, with additional variables passed along df= umx_stack(mtcars, select= c("disp", "hp"), passalong= "mpg") str(df) # ind is a factor, with levels select ggplot2::qplot(x = mpg, y= values, color=ind, data = df) cleanEx() nameEx("umx_str_chars") ### * umx_str_chars flush(stderr()); flush(stdout()) ### Name: umx_str_chars ### Title: Select desired characters from a string ### Aliases: umx_str_chars ### ** Examples umx_str_chars("myFpassUword", c(3,8)) cleanEx() nameEx("umx_str_from_object") ### * umx_str_from_object flush(stderr()); flush(stdout()) ### Name: umx_str_from_object ### Title: Return variable name as a string ### Aliases: umx_str_from_object ### ** Examples umx_str_from_object(mtcars) # "mtcars" cleanEx() nameEx("umx_string_to_algebra") ### * umx_string_to_algebra flush(stderr()); flush(stdout()) ### Name: umx_string_to_algebra ### Title: Convert a string to an OpenMx algebra ### Aliases: umx_string_to_algebra ### ** Examples ## Not run: ##D alg = umx_string_to_algebra(paste(rep("A", nReps), collapse = " %*% "), name = "test_case") ## End(Not run) cleanEx() nameEx("umx_time") ### * umx_time flush(stderr()); flush(stdout()) ### Name: umx_time ### Title: umx_time ### Aliases: umx_time ### ** Examples ## Not run: ##D require(umx) ##D umx_time('stop') # alert user stop called when not yet started... ##D umx_time('stop') ##D umx_time('start') ##D data(demoOneFactor) ##D latents = c("G") ##D manifests = names(demoOneFactor) ##D myData = mxData(cov(demoOneFactor), type = "cov", numObs=500) ##D m1 = umxRAM("umx_time_example", data = myData, ##D umxPath(from = latents, to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = latents, fixedAt = 1) ##D ) ##D umx_time(m1) # report time from mxModel ##D m2 = umxRun(m1) ##D umx_time(c(m1, m2)) # print comparison table ##D umx_time('stop') # report the time since timer last started, and restart ##D umx_time('stop') # report the time since timer was restarted. ## End(Not run) cleanEx() nameEx("umx_trim") ### * umx_trim flush(stderr()); flush(stdout()) ### Name: umx_trim ### Title: Trim whitespace surrounding a string. ### Aliases: umx_trim ### ** Examples umx_trim(" dog") # "dog" trimws(" dog ", "l") # added by R in v 3.3.0 umx_trim("dog ") # "dog" umx_trim("\t dog \n") # "dog" umx_trim("xlsx dog.xlsx", "\\.?xlsx ?") # "dog" cleanEx() nameEx("umx_var") ### * umx_var flush(stderr()); flush(stdout()) ### Name: umx_var ### Title: Get variances from a df that might contain some non-numeric ### columns ### Aliases: umx_var ### ** Examples tmp = mtcars[,1:4] tmp$cyl = ordered(mtcars$cyl) # ordered factor tmp$hp = ordered(mtcars$hp) # binary factor umx_var(tmp, format = "diag", ordVar = 1, use = "pair") tmp2 = tmp[, c(1, 3)] umx_var(tmp2, format = "diag") umx_var(tmp2, format = "full") data(myFADataRaw) df = myFADataRaw[,c("z1", "z2", "z3")] df$z1 = mxFactor(df$z1, levels = c(0, 1)) df$z2 = mxFactor(df$z2, levels = c(0, 1)) df$z3 = mxFactor(df$z3, levels = c(0, 1, 2)) umx_var(df, format = "diag") umx_var(df, format = "full", allowCorForFactorCovs=TRUE) # Ordinal/continuous mix data(twinData) twinData= umx_scale_wide_twin_data(data=twinData,varsToScale="wt",sep= "") # Cut BMI column to form ordinal obesity variables obLevels = c('normal', 'overweight', 'obese') cuts = quantile(twinData[, "bmi1"], probs = c(.5, .8), na.rm = TRUE) twinData$obese1=cut(twinData$bmi1,breaks=c(-Inf,cuts,Inf),labels=obLevels) twinData$obese2=cut(twinData$bmi2,breaks=c(-Inf,cuts,Inf),labels=obLevels) # Make the ordinal variables into mxFactors ordDVs = c("obese1", "obese2") twinData[, ordDVs] = umxFactor(twinData[, ordDVs]) varStarts = umx_var(twinData[, c(ordDVs, "wt1", "wt2")], format= "diag", ordVar = 1, use = "pairwise.complete.obs") cleanEx() nameEx("umx_wide2long") ### * umx_wide2long flush(stderr()); flush(stdout()) ### Name: umx_wide2long ### Title: Change data family data from wide (2 twins per row) to long ### format. ### Aliases: umx_wide2long ### ** Examples long = umx_wide2long(data = twinData, sep = "") long = umx_wide2long(data = twinData, sep = "", verbose = TRUE) str(long) str(twinData) cleanEx() nameEx("umx_write_to_clipboard") ### * umx_write_to_clipboard flush(stderr()); flush(stdout()) ### Name: umx_write_to_clipboard ### Title: umx_write_to_clipboard ### Aliases: umx_write_to_clipboard ### ** Examples ## Not run: ##D umx_write_to_clipboard("hello") ## End(Not run) cleanEx() nameEx("us_skinfold_data") ### * us_skinfold_data flush(stderr()); flush(stdout()) ### Name: us_skinfold_data ### Title: Anthropometric data on twins ### Aliases: us_skinfold_data ### Keywords: datasets ### ** Examples ## Not run: ##D data(us_skinfold_data) ##D str(us_skinfold_data) ##D par(mfrow = c(1, 2)) # 1 rows and 3 columns ##D plot(ht_T1 ~ht_T2, ylim = c(130, 165), data = subset(us_skinfold_data, zyg == 1)) ##D plot(ht_T1 ~ht_T2, ylim = c(130, 165), data = subset(us_skinfold_data, zyg == 3)) ##D par(mfrow = c(1, 1)) # back to as it was ## End(Not run) cleanEx() nameEx("xmuHasSquareBrackets") ### * xmuHasSquareBrackets flush(stderr()); flush(stdout()) ### Name: xmuHasSquareBrackets ### Title: xmuHasSquareBrackets ### Aliases: xmuHasSquareBrackets ### ** Examples xmuHasSquareBrackets("A[1,2]") cleanEx() nameEx("xmuLabel") ### * xmuLabel flush(stderr()); flush(stdout()) ### Name: xmuLabel ### Title: xmuLabel: Add labels to a RAM model, matrix, or path ### Aliases: xmuLabel ### ** Examples ## Not run: ##D # ============================================================== ##D # = Show how OpenMx models are not labeled, and then add labels = ##D # ============================================================== ##D require(umx) ##D data(demoOneFactor) ##D latents = c("G") ##D manifests = names(demoOneFactor) ##D m1 = mxModel("One Factor", type = "RAM", ##D manifestVars = manifests, latentVars = latents, ##D mxPath(from = latents , to = manifests), ##D mxPath(from = manifests, arrows = 2), ##D mxPath(from = latents , arrows = 2, free = FALSE, values = 1.0), ##D mxData(cov(demoOneFactor), type = "cov", numObs=500) ##D ) ##D ##D umxGetParameters(m1) # Default "matrix address" labels, i.e "One Factor.S[2,2]" ##D m1 = xmuLabel(m1) ##D umxGetParameters(m1, free = TRUE) # Informative labels: "G_to_x1", "x4_with_x4", etc. ##D ##D # ======================================================================= ##D # = Create a new model, with suffixes added to paths, and model renamed = ##D # ======================================================================= ##D m2 = xmuLabel(m1, suffix= "_male", overRideExisting= TRUE, name = "male") ##D umxGetParameters(m2, free = TRUE) # suffixes added ##D ##D # ============================= ##D # = Example Labeling a matrix = ##D # ============================= ##D a = xmuLabel(mxMatrix(name = "a", "Full", 3, 3, values = 1:9)) ##D a$labels ##D a = xmuLabel(mxMatrix(name = "a", "Full", 3, 3, values = 1:9), baseName="bob") ##D a$labels ##D # note: labels with "data." in the name are left untouched! ##D a = mxMatrix(name = "a", "Full", 1,3, labels = c("data.a", "test", NA)) ##D a$labels ##D xmuLabel(a, verbose = TRUE) ##D xmuLabel(a, verbose = TRUE, overRideExisting = FALSE) ##D xmuLabel(a, verbose = TRUE, overRideExisting = TRUE) ## End(Not run) cleanEx() nameEx("xmuLabel_MATRIX_Model") ### * xmuLabel_MATRIX_Model flush(stderr()); flush(stdout()) ### Name: xmuLabel_MATRIX_Model ### Title: xmuLabel_MATRIX_Model (not a user function) ### Aliases: xmuLabel_MATRIX_Model ### ** Examples require(umx) data(demoOneFactor) m2 <- mxModel("label_ex", mxMatrix("Full", 5, 1, values = 0.2, free = TRUE, name = "A"), mxMatrix("Symm", 1, 1, values = 1.0, free = FALSE, name = "L"), mxMatrix("Diag", 5, 5, values = 1.0, free = TRUE, name = "U"), mxAlgebra(A %*% L %*% t(A) + U, name = "R"), mxExpectationNormal("R", dimnames = names(demoOneFactor)), mxFitFunctionML(), mxData(cov(demoOneFactor), type = "cov", numObs=500) ) m3 = umx:::xmuLabel_MATRIX_Model(m2) m4 = umx:::xmuLabel_MATRIX_Model(m2, suffix = "male") # explore these with omxGetParameters(m4) cleanEx() nameEx("xmuLabel_RAM_Model") ### * xmuLabel_RAM_Model flush(stderr()); flush(stdout()) ### Name: xmuLabel_RAM_Model ### Title: xmuLabel_RAM_Model (not a user function) ### Aliases: xmuLabel_RAM_Model ### ** Examples require(umx); data(demoOneFactor) # raw but no means m1 <- mxModel("label_ex", mxData(demoOneFactor, type = "raw"), type="RAM", manifestVars = "x1", latentVars= "G", umxPath("G", to = "x1"), umxPath(var = "x1"), umxPath(var = "G", fixedAt = 1) ) xmuLabel_RAM_Model(m1) cleanEx() nameEx("xmuMaxLevels") ### * xmuMaxLevels flush(stderr()); flush(stdout()) ### Name: xmuMaxLevels ### Title: xmuMaxLevels ### Aliases: xmuMaxLevels ### ** Examples xmuMaxLevels(mtcars) # NA = no ordinal vars xmuMaxLevels(umxFactor(mtcars)) xmuMaxLevels(umxFactor(mtcars), what = "name") cleanEx() nameEx("xmuMinLevels") ### * xmuMinLevels flush(stderr()); flush(stdout()) ### Name: xmuMinLevels ### Title: xmuMinLevels ### Aliases: xmuMinLevels ### ** Examples xmuMinLevels(mtcars) # NA = no ordinal vars xmuMinLevels(umxFactor(mtcars)) xmuMinLevels(umxFactor(mtcars), what = "name") cleanEx() nameEx("xmuPropagateLabels") ### * xmuPropagateLabels flush(stderr()); flush(stdout()) ### Name: xmuPropagateLabels ### Title: xmuPropagateLabels (not a user function) ### Aliases: xmuPropagateLabels ### ** Examples require(umx) data(demoOneFactor) latents = c("G") manifests = names(demoOneFactor) m1 = mxModel("propage_example", type = "RAM", manifestVars = manifests, latentVars = latents, mxPath(from = latents , to = manifests), mxPath(from = manifests, arrows = 2), mxPath(from = latents , arrows = 2, free = FALSE, values = 1.0), mxData(cov(demoOneFactor), type = "cov", numObs=500) ) m1 = umx:::xmuPropagateLabels(m1, suffix = "MZ") cleanEx() nameEx("xmuRAM2Ordinal") ### * xmuRAM2Ordinal flush(stderr()); flush(stdout()) ### Name: xmuRAM2Ordinal ### Title: xmuRAM2Ordinal ### Aliases: xmuRAM2Ordinal ### ** Examples ## Not run: ##D data(twinData) ##D # Cut to form category of 20% obese subjects ##D obesityLevels = c('normal', 'obese') ##D cutPoints = quantile(twinData[, "bmi1"], probs = .2, na.rm = TRUE) ##D twinData$obese1 = cut(twinData$bmi1, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) ##D twinData$obese2 = cut(twinData$bmi2, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) ##D ordDVs = c("obese1", "obese2") ##D twinData[, ordDVs] = umxFactor(twinData[, ordDVs]) ##D mzData = twinData[twinData$zygosity %in% "MZFF",] ##D m1 = umxRAM("tim", data = mzData, ##D umxPath("bmi1", with = "bmi2"), ##D umxPath(v.m.= c("bmi1", "bmi2")) ##D ) ##D ##D m1 = umxRAM("tim", data = mzData, ##D umxPath("obese1", with = "obese2"), ##D umxPath(v.m.= c("obese1", "obese2")) ##D ) ## End(Not run) cleanEx() nameEx("xmuTwinSuper_Continuous") ### * xmuTwinSuper_Continuous flush(stderr()); flush(stdout()) ### Name: xmuTwinSuper_Continuous ### Title: Create core of twin model for all-continuous data. ### Aliases: xmuTwinSuper_Continuous ### ** Examples ## Not run: ##D xmuTwinSuper_Continuous(name="twin_super", selVars = selVars, selCovs = selCovs, ##D mzData = mzData, dzData = dzData, equateMeans = TRUE, type = type, ##D allContinuousMethod = allContinuousMethod, nSib= nSib, sep = "_T" ) ## End(Not run) cleanEx() nameEx("xmuTwinSuper_NoBinary") ### * xmuTwinSuper_NoBinary flush(stderr()); flush(stdout()) ### Name: xmuTwinSuper_NoBinary ### Title: xmuTwinSuper_NoBinary ### Aliases: xmuTwinSuper_NoBinary ### ** Examples # cleanEx() nameEx("xmuTwinUpgradeMeansToCovariateModel") ### * xmuTwinUpgradeMeansToCovariateModel flush(stderr()); flush(stdout()) ### Name: xmuTwinUpgradeMeansToCovariateModel ### Title: Not for end-users: Add a means model with covariates to a twin ### model ### Aliases: xmuTwinUpgradeMeansToCovariateModel ### ** Examples ## Not run: ##D data(twinData) # ?twinData from Australian twins. ##D twinData[, c("ht1", "ht2")] = twinData[, c("ht1", "ht2")] * 10 ##D mzData = twinData[twinData$zygosity %in% "MZFF", ] ##D dzData = twinData[twinData$zygosity %in% "DZFF", ] ##D # m1 = umxACE(selDVs= "ht", sep= "", dzData= dzData, mzData= mzData, autoRun= FALSE) ##D # m2 = xmuTwinUpgradeMeansToCovariateModel(m1, fullVars = c("ht1", "ht2"), ##D # fullCovs = c("age1", "sex1", "age2", "sex2"), sep = "") ##D ## End(Not run) cleanEx() nameEx("xmuValues") ### * xmuValues flush(stderr()); flush(stdout()) ### Name: xmuValues ### Title: xmuValues: Set values in RAM model, matrix, or path ### Aliases: xmuValues ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D latents = c("G") ##D manifests = names(demoOneFactor) ##D ##D # ==================================================================== ##D # = Make an OpenMx model (which will lack start values and labels..) = ##D # ==================================================================== ##D m1 = mxModel("One Factor", type = "RAM", ##D manifestVars = manifests, latentVars = latents, ##D mxPath(from = latents , to = manifests), ##D mxPath(from = manifests, arrows = 2), ##D mxPath(from = latents , arrows = 2, free = FALSE, values = 1.0), ##D mxData(cov(demoOneFactor), type = "cov", numObs=500) ##D ) ##D mxEval(S, m1) # default variances are jiggled away from near-zero ##D # Add start values to the model ##D m1 = xmuValues(m1) ##D mxEval(S, m1) # plausible variances ##D umx_print(mxEval(S,m1), 3, zero.print = ".") # plausible variances ##D xmuValues(14, sd = 1, n = 10) # Return vector of length 10, with mean 14 and sd 1 ##D ## End(Not run) cleanEx() nameEx("xmu_CI_merge") ### * xmu_CI_merge flush(stderr()); flush(stdout()) ### Name: xmu_CI_merge ### Title: xmu_CI_merge ### Aliases: xmu_CI_merge ### ** Examples ## Not run: ##D xmu_CI_merge(m1, m2) ## End(Not run) cleanEx() nameEx("xmu_DF_to_mxData_TypeCov") ### * xmu_DF_to_mxData_TypeCov flush(stderr()); flush(stdout()) ### Name: xmu_DF_to_mxData_TypeCov ### Title: Convert a dataframe into a cov mxData object ### Aliases: xmu_DF_to_mxData_TypeCov ### ** Examples xmu_DF_to_mxData_TypeCov(mtcars, c("mpg", "hp")) cleanEx() nameEx("xmu_PadAndPruneForDefVars") ### * xmu_PadAndPruneForDefVars flush(stderr()); flush(stdout()) ### Name: xmu_PadAndPruneForDefVars ### Title: Where all data are missing for a twin, add default values for ### definition variables, allowing the row to be kept ### Aliases: xmu_PadAndPruneForDefVars ### ** Examples ## Not run: ##D data(twinData) ##D sum(is.na(twinData$ht1)) ##D df = xmu_PadAndPruneForDefVars(twinData, varNames = "ht", defNames = "wt", c("1", "2")) ## End(Not run) cleanEx() nameEx("xmu_bracket_address2rclabel") ### * xmu_bracket_address2rclabel flush(stderr()); flush(stdout()) ### Name: xmu_bracket_address2rclabel ### Title: Convert a bracket address into an A_rXcX-style label. ### Aliases: xmu_bracket_address2rclabel ### ** Examples xmu_bracket_address2rclabel(label = "A[1,1]") xmu_bracket_address2rclabel(label = "top.A[1,1]") xmu_bracket_address2rclabel(label = "A_std[1,1]") cleanEx() nameEx("xmu_cell_is_on") ### * xmu_cell_is_on flush(stderr()); flush(stdout()) ### Name: xmu_cell_is_on ### Title: Return whether a cell is in a set location of a matrix ### Aliases: xmu_cell_is_on ### ** Examples xmu_cell_is_on(r = 3, c = 3, "lower") xmu_cell_is_on(r = 3, c = 3, "lower_inc") xmu_cell_is_on(r = 3, c = 3, "upper") xmu_cell_is_on(r = 3, c = 3, "upper_inc") xmu_cell_is_on(r = 3, c = 3, "diag") xmu_cell_is_on(r = 2, c = 3, "diag") xmu_cell_is_on(r = 3, c = 3, "any") a_cp = umxMatrix("a_cp", "Lower", 3, 3, free = TRUE, values = 1:6) xmu_cell_is_on(r = 3, c = 3, "left", mat = a_cp) cleanEx() nameEx("xmu_check_levels_identical") ### * xmu_check_levels_identical flush(stderr()); flush(stdout()) ### Name: xmu_check_levels_identical ### Title: xmu_check_levels_identical ### Aliases: xmu_check_levels_identical ### ** Examples require(umx) data(twinData) baseNames = c("bmi") selDVs = umx_paste_names(baseNames, "", 1:2) tmp = twinData[, selDVs] tmp$bmi1[tmp$bmi1 <= 22] = 22 tmp$bmi2[tmp$bmi2 <= 22] = 22 xmu_check_levels_identical(umxFactor(tmp, sep = ""), selDVs = baseNames, sep = "") ## Not run: ##D xmu_check_levels_identical(umxFactor(tmp), selDVs = baseNames, sep = "") ## End(Not run) cleanEx() nameEx("xmu_check_needs_means") ### * xmu_check_needs_means flush(stderr()); flush(stdout()) ### Name: xmu_check_needs_means ### Title: Check data to see if model needs means. ### Aliases: xmu_check_needs_means ### ** Examples xmu_check_needs_means(mtcars, type = "Auto") xmu_check_needs_means(mtcars, type = "FIML") # xmu_check_needs_means(mtcars, type = "cov") # xmu_check_needs_means(mtcars, type = "cor") # TRUE - marginals means means xmu_check_needs_means(mtcars, type = "WLS", allContinuousMethod= "marginals") xmu_check_needs_means(mtcars, type = "ULS", allContinuousMethod= "marginals") xmu_check_needs_means(mtcars, type = "DWLS", allContinuousMethod= "marginals") # ================================ # = Provided as an mxData object = # ================================ tmp = mxData(mtcars, type="raw") xmu_check_needs_means(tmp, type = "FIML") # TRUE xmu_check_needs_means(tmp, type = "ULS", allContinuousMethod= "cumulants") #FALSE # TRUE - means with marginals xmu_check_needs_means(tmp, type = "WLS", allContinuousMethod= "marginals") tmp = mxData(cov(mtcars), type="cov", numObs= 100) # Should catch this can't be type FIML xmu_check_needs_means(tmp) # FALSE tmp = mxData(cov(mtcars), means = umx_means(mtcars), type="cov", numObs= 100) xmu_check_needs_means(tmp) # TRUE # ======================= # = One var is a factor = # ======================= tmp = mtcars tmp$cyl = factor(tmp$cyl) xmu_check_needs_means(tmp, allContinuousMethod= "cumulants") # TRUE xmu_check_needs_means(tmp, allContinuousMethod= "marginals") # TRUE - always has means cleanEx() nameEx("xmu_check_variance") ### * xmu_check_variance flush(stderr()); flush(stdout()) ### Name: xmu_check_variance ### Title: Check the minimum variance in data frame ### Aliases: xmu_check_variance ### ** Examples data(twinData) xmu_check_variance(twinData[, c("wt1", "ht1", "wt2", "ht2")]) twinData[,c("ht1", "ht2")]= twinData[,c("ht1", "ht2")] * 100 xmu_check_variance(twinData[, c("wt1", "ht1", "wt2", "ht2")]) cleanEx() nameEx("xmu_clean_label") ### * xmu_clean_label flush(stderr()); flush(stdout()) ### Name: xmu_clean_label ### Title: Remove illegal characters from labels ### Aliases: xmu_clean_label ### ** Examples xmu_clean_label("data.var", replace = "_") xmu_clean_label("my.var.lab", replace = "_") cleanEx() nameEx("xmu_data_missing") ### * xmu_data_missing flush(stderr()); flush(stdout()) ### Name: xmu_data_missing ### Title: Drop rows with missing definition variables ### Aliases: xmu_data_missing ### ** Examples tmp = mtcars; tmp[1,]; tmp[1, "wt"] = NA tmp = xmu_data_missing(tmp, selVars = "wt", sep= NULL, dropMissingDef= TRUE, hint= "mtcars") dim(mtcars) dim(tmp) ## Not run: ##D tmp = xmu_data_missing(tmp, selVars = "wt", sep= NULL, dropMissingDef= FALSE, hint= "mtcars") ## End(Not run) cleanEx() nameEx("xmu_data_swap_a_block") ### * xmu_data_swap_a_block flush(stderr()); flush(stdout()) ### Name: xmu_data_swap_a_block ### Title: Data helper function to swap blocks of data from one set of ### columns to another. ### Aliases: xmu_data_swap_a_block ### ** Examples test = data.frame( a = paste0("a", 1:10), b = paste0("b", 1:10), c = paste0("c", 1:10), d = paste0("d", 1:10), stringsAsFactors = FALSE) xmu_data_swap_a_block(test, rowSelector = c(1,2,3,6), T1Names = "b", T2Names = "c") xmu_data_swap_a_block(test, rowSelector = c(1,2,3,6), T1Names = c("a","c"), T2Names = c("b","d")) cleanEx() nameEx("xmu_describe_data_WLS") ### * xmu_describe_data_WLS flush(stderr()); flush(stdout()) ### Name: xmu_describe_data_WLS ### Title: Determine if a dataset will need statistics for the means if ### used in a WLS model. ### Aliases: xmu_describe_data_WLS ### ** Examples # ==================================== # = All continuous, data.frame input = # ==================================== tmp =xmu_describe_data_WLS(mtcars, allContinuousMethod= "cumulants", verbose = TRUE) tmp$hasMeans # FALSE - no means with cumulants tmp =xmu_describe_data_WLS(mtcars, allContinuousMethod= "marginals") tmp$hasMeans # TRUE we get means with marginals # ========================== # = mxData object as input = # ========================== tmp = mxData(mtcars, type="raw") xmu_describe_data_WLS(tmp, allContinuousMethod= "cumulants", verbose = TRUE)$hasMeans # FALSE xmu_describe_data_WLS(tmp, allContinuousMethod= "marginals")$hasMeans # TRUE # ======================================= # = One var is a factor: Means modeled = # ======================================= tmp = mtcars tmp$cyl = factor(tmp$cyl) xmu_describe_data_WLS(tmp, allContinuousMethod= "cumulants")$hasMeans # TRUE - always has means xmu_describe_data_WLS(tmp, allContinuousMethod= "marginals")$hasMeans # TRUE cleanEx() nameEx("xmu_dot_define_shapes") ### * xmu_dot_define_shapes flush(stderr()); flush(stdout()) ### Name: xmu_dot_define_shapes ### Title: Helper to make the list of vars and their shapes for a graphviz ### string ### Aliases: xmu_dot_define_shapes ### ** Examples xmu_dot_define_shapes(c("as1"), c("E", "N")) cleanEx() nameEx("xmu_dot_mat2dot") ### * xmu_dot_mat2dot flush(stderr()); flush(stdout()) ### Name: xmu_dot_mat2dot ### Title: Return dot code for paths in a matrix ### Aliases: xmu_dot_mat2dot ### ** Examples # test with a 1 * 1 a_cp = umxMatrix("a_cp", "Lower", 1, 1, free = TRUE, values = pi) out = xmu_dot_mat2dot(a_cp, cells = "lower_inc", from = "cols", arrows = "both") cat(out$str) # a_cp -> a_cp [dir = both label="2"]; out = xmu_dot_mat2dot(a_cp, cells = "lower_inc", from = "cols", arrows = "forward", fromLabel = "fromMe", toLabel = "toYou", fromType = "latent", toType = "manifest", digits = 3, SEstyle = TRUE ) cat(out$str) # fromMe -> toYou [dir = forward label="3.142"]; cat(out$latent) # fromMe cat(out$manifest) # toYou # Make a lower 3 * 3 value= 1:6 (1, 4, 6 on the diag) a_cp = umxMatrix("a_cp", "Lower", 3, 3, free = TRUE, values = 1:6) # Get dot strings for lower triangle (default from and to based on row and column number) out = xmu_dot_mat2dot(a_cp, cells = "lower", from = "cols", arrows = "both") cat(out$str) # a_cp1 -> a_cp2 [dir = both label="2"]; # one arrow (the default = "forward") out = xmu_dot_mat2dot(a_cp, cells = "lower", from = "cols") cat(out$str) # a_cp1 -> a_cp2 [dir = forward label="2"]; # label to (rows) using var names out = xmu_dot_mat2dot(a_cp, toLabel= paste0("v", 1:3), cells = "lower", from = "cols") umx_msg(out$str) # a_cp1 -> v2 [dir = forward label="2"] ... # First call also inits the plot struct out = xmu_dot_mat2dot(a_cp, from = "rows", cells = "lower", arrows = "both", fromType = "latent") out = xmu_dot_mat2dot(a_cp, from = "rows", cells = "diag", toLabel= "common", toType = "manifest", p = out) umx_msg(out$str); umx_msg(out$manifests); umx_msg(out$latents) # ================================ # = Add found sinks to manifests = # ================================ out = xmu_dot_mat2dot(a_cp, from= "rows", cells= "diag", toLabel= c('a','b','c'), toType= "manifest"); umx_msg(out$manifests) # ================================ # = Add found sources to latents = # ================================ out = xmu_dot_mat2dot(a_cp, from= "rows", cells= "diag", toLabel= c('a','b','c'), fromType= "latent"); umx_msg(out$latents) # ======================== # = Label a means matrix = # ======================== tmp = umxMatrix("expMean", "Full", 1, 4, free = TRUE, values = 1:4) out = xmu_dot_mat2dot(tmp, cells = "left", from = "rows", fromLabel= "one", toLabel= c("v1", "v2") ) cat(out$str) ## Not run: ##D # ============================================== ##D # = Get a string which includes CI information = ##D # ============================================== ##D data(demoOneFactor) ##D latents = c("g"); manifests = names(demoOneFactor) ##D m1 = umxRAM("xmu_dot", data = demoOneFactor, type = "cov", ##D umxPath(latents, to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = latents, fixedAt = 1.0) ##D ) ##D m1 = umxCI(m1, run= "yes") ##D out = xmu_dot_mat2dot(m1$A, from = "cols", cells = "any", ##D toLabel= paste0("x", 1:5), fromType = "latent", model= m1); ##D umx_msg(out$str); umx_msg(out$latents) ##D ## End(Not run) cleanEx() nameEx("xmu_dot_move_ranks") ### * xmu_dot_move_ranks flush(stderr()); flush(stdout()) ### Name: xmu_dot_move_ranks ### Title: xmu_dot_move_ranks (not for end users) ### Aliases: xmu_dot_move_ranks ### ** Examples old_min = c("min1", "min2") old_same = c("s1", "s2") old_max = paste0("x", 1:3) # Add L1 to min xmu_dot_move_ranks(min = "L1", old_min= old_min, old_same= old_same, old_max= old_max) # Move min1 to max xmu_dot_move_ranks(max = "min1", old_min= old_min, old_same= old_same, old_max= old_max) # Clear min xmu_dot_move_ranks(min = "", old_min= old_min, old_same= old_same, old_max= old_max) cleanEx() nameEx("xmu_dot_rank") ### * xmu_dot_rank flush(stderr()); flush(stdout()) ### Name: xmu_dot_rank ### Title: Helper to make a graphviz rank string ### Aliases: xmu_dot_rank ### ** Examples xmu_dot_rank(c("as1"), "^[ace]s[0-9]+$", "same") cleanEx() nameEx("xmu_dot_rank_str") ### * xmu_dot_rank_str flush(stderr()); flush(stdout()) ### Name: xmu_dot_rank_str ### Title: xmu_dot_rank_str (not for end users) ### Aliases: xmu_dot_rank_str ### ** Examples xmu_dot_rank_str(min = "L1", same = c("x1", "x2"), max = paste0("e", 1:3)) cleanEx() nameEx("xmu_extract_column") ### * xmu_extract_column flush(stderr()); flush(stdout()) ### Name: xmu_extract_column ### Title: Get one or more columns from mzData or regular data.frame ### Aliases: xmu_extract_column ### ** Examples xmu_extract_column(mtcars, "wt") xmu_extract_column(mxData(mtcars, type = "raw"), "wt") xmu_extract_column(mxData(mtcars, type = "raw"), "wt", drop=TRUE) xmu_extract_column(mxData(mtcars, type = "raw"), c("wt", "mpg")) cleanEx() nameEx("xmu_get_CI") ### * xmu_get_CI flush(stderr()); flush(stdout()) ### Name: xmu_get_CI ### Title: Look up and report CIs for free parameters ### Aliases: xmu_get_CI ### ** Examples ## Not run: ##D require(umx); data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D tmp = umxRAM("get_CI_example", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1) ##D ) ##D tmp = umxCI(tmp, run= "yes") ##D ##D # Get CI by parameter label ##D xmu_get_CI(model= tmp, "x1_with_x1") ##D xmu_get_CI(model= tmp, "x1_with_x1", SEstyle = TRUE, digits = 3) ##D ##D # prefix (submodel) and suffix (e.g. std) are ignored if not needed ##D xmu_get_CI(model= tmp, "x1_with_x1", prefix = "top.", suffix = "_std") ##D ##D xmu_get_CI(fit_IP, label = "ai_r1c1", prefix = "top.", suffix = "_std") ##D xmu_get_CI(fit_IP, label = "ai_r1c1", prefix = "top.", SEstyle = TRUE, suffix = "_std") ## End(Not run) cleanEx() nameEx("xmu_lavaan_process_group") ### * xmu_lavaan_process_group flush(stderr()); flush(stdout()) ### Name: xmu_lavaan_process_group ### Title: Process table of paths to model ### Aliases: xmu_lavaan_process_group ### ** Examples ## Not run: ##D tab = lavaan::lavaanify("y~x") ##D xmu_lavaan_process_group(tab, groupNum = 1) ##D xmu_lavaan_process_group(tab, groupNum = 0) ##D ## End(Not run) cleanEx() nameEx("xmu_make_TwinSuperModel") ### * xmu_make_TwinSuperModel flush(stderr()); flush(stdout()) ### Name: xmu_make_TwinSuperModel ### Title: Helper to make a basic top, MZ, and DZ model. ### Aliases: xmu_make_TwinSuperModel ### ** Examples # ============== # = Continuous = # ============== library(umx) data(twinData) twinData = umx_scale(twinData, varsToScale= c('ht1','ht2')) mzData = twinData[twinData$zygosity %in% "MZFF",] dzData = twinData[twinData$zygosity %in% "DZFF",] m1= xmu_make_TwinSuperModel(mzData=mzData, dzData=dzData, selDVs=c("wt","ht"), sep="", nSib=2) names(m1) # "top" "MZ" "DZ" class(m1$MZ$fitfunction)[[1]] == "MxFitFunctionML" # ==================== # = With a covariate = # ==================== m1= xmu_make_TwinSuperModel(mzData=mzData, dzData=dzData, selDVs= "wt", selCovs= "age", sep="", nSib=2) m1$top$intercept$labels m1$MZ$expMean # =============== # = WLS example = # =============== m1=xmu_make_TwinSuperModel(mzData=mzData, dzData=dzData,selDVs=c("wt","ht"),sep="",type="WLS") class(m1$MZ$fitfunction)[[1]] == "MxFitFunctionWLS" m1$MZ$fitfunction$type =="WLS" # Check default all-continuous method m1$MZ$fitfunction$continuousType == "cumulants" # Choose non-default type (DWLS) m1= xmu_make_TwinSuperModel(mzData= mzData, dzData= dzData, selDVs= c("wt","ht"), sep="", type="DWLS") m1$MZ$fitfunction$type =="DWLS" class(m1$MZ$fitfunction)[[1]] == "MxFitFunctionWLS" # Switch WLS method m1 = xmu_make_TwinSuperModel(mzData= mzData, dzData= dzData, selDVs= c("wt","ht"), sep= "", type = "WLS", allContinuousMethod = "marginals") m1$MZ$fitfunction$continuousType == "marginals" class(m1$MZ$fitfunction)[[1]] == "MxFitFunctionWLS" # ============================================ # = Bivariate continuous and ordinal example = # ============================================ data(twinData) selDVs = c("wt", "obese") # Cut BMI column to form ordinal obesity variables ordDVs = c("obese1", "obese2") obesityLevels = c('normal', 'overweight', 'obese') cutPoints = quantile(twinData[, "bmi1"], probs = c(.5, .2), na.rm = TRUE) twinData$obese1 = cut(twinData$bmi1, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) twinData$obese2 = cut(twinData$bmi2, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) # Make the ordinal variables into mxFactors (ensure ordered is TRUE, and require levels) twinData[, ordDVs] = umxFactor(twinData[, ordDVs]) mzData = twinData[twinData$zygosity %in% "MZFF",] dzData = twinData[twinData$zygosity %in% "DZFF",] m1 = xmu_make_TwinSuperModel(mzData= mzData, dzData= dzData, selDVs= selDVs, sep="", nSib= 2) names(m1) # "top" "MZ" "DZ" # ============== # = One binary = # ============== data(twinData) cutPoints = quantile(twinData[, "bmi1"], probs = .2, na.rm = TRUE) obesityLevels = c('normal', 'obese') twinData$obese1 = cut(twinData$bmi1, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) twinData$obese2 = cut(twinData$bmi2, breaks = c(-Inf, cutPoints, Inf), labels = obesityLevels) ordDVs = c("obese1", "obese2") twinData[, ordDVs] = umxFactor(twinData[, ordDVs]) selDVs = c("wt", "obese") mzData = twinData[twinData$zygosity %in% "MZFF",] dzData = twinData[twinData$zygosity %in% "DZFF",] m1 = xmu_make_TwinSuperModel(mzData= mzData, dzData= dzData, selDVs= selDVs, sep= "", nSib= 2) # ======================================== # = Cov data (calls xmuTwinSuper_CovCor) = # ======================================== data(twinData) mzData =cov(twinData[twinData$zygosity %in% "MZFF", tvars(c("wt","ht"), sep="")], use="complete") dzData =cov(twinData[twinData$zygosity %in% "DZFF", tvars(c("wt","ht"), sep="")], use="complete") m1 = xmu_make_TwinSuperModel(mzData= mzData, dzData= dzData, selDVs= "wt", sep= "", nSib= 2, numObsMZ = 100, numObsDZ = 100, verbose=TRUE) class(m1$MZ$fitfunction)[[1]] =="MxFitFunctionML" dimnames(m1$MZ$data$observed)[[1]]==c("wt1", "wt2") cleanEx() nameEx("xmu_make_bin_cont_pair_data") ### * xmu_make_bin_cont_pair_data flush(stderr()); flush(stdout()) ### Name: xmu_make_bin_cont_pair_data ### Title: Make pairs of bin & continuous columns to represent censored ### data ### Aliases: xmu_make_bin_cont_pair_data ### ** Examples df = xmu_make_bin_cont_pair_data(mtcars, vars = c("mpg")) str(df) df[order(df$mpg), c(1,12)] # Introduce a floor effect tmp = mtcars; tmp$mpg[tmp$mpg<=15]=15 tmp$mpg_T1 = tmp$mpg_T2 = tmp$mpg df = xmu_make_bin_cont_pair_data(tmp, vars = c("mpg"), suffixes = c("_T1", "_T2")) df[order(df$mpg), 12:15] cleanEx() nameEx("xmu_make_mxData") ### * xmu_make_mxData flush(stderr()); flush(stdout()) ### Name: xmu_make_mxData ### Title: Upgrade a dataframe to an mxData type. ### Aliases: xmu_make_mxData ### ** Examples # ========================= # = Continuous ML example = # ========================= data(mtcars) tmp = xmu_make_mxData(data= mtcars, type = "Auto"); # class(tmp); # "MxDataStatic" # names(tmp$observed) # "mpg" "cyl" "disp" manVars = c("mpg", "cyl", "disp") tmp = xmu_make_mxData(data= mtcars, type = "Auto", manifests = manVars); tmp$type == "raw" # TRUE # ============================== # = All continuous WLS example = # ============================== tmp = xmu_make_mxData(data= mtcars, type = "WLS" , manifests = manVars, verbose= TRUE) tmp$type == "raw" # TRUE (WLS is triggered by the fit function, not the data type) # ============================ # = Missing data WLS example = # ============================ tmp = mtcars; tmp[1, "mpg"] = NA # add NA tmp = xmu_make_mxData(data= tmp, type = "WLS", manifests = manVars, verbose= TRUE) ## Not run: ##D # ========================== ##D # = already mxData example = ##D # ========================== ##D m1 = umxRAM("auto", data = mxData(mtcars, type = "raw"), ##D umxPath(var= "wt"), ##D umxPath(mean= "wt") ##D ) ##D ## End(Not run) # ======================== # = Cov and cor examples = # ======================== tmp = xmu_make_mxData(data= mtcars, type = "cov", manifests = c("mpg", "cyl")) tmp = xmu_make_mxData(data= mtcars, type = "cor", manifests = c("mpg", "cyl")) tmp = xmu_make_mxData(data= cov(mtcars[, c("mpg", "cyl")]), type = "cov", manifests = c("mpg", "cyl"), numObs=200) # mxData input examples tmp = mxData(cov(mtcars[, c("mpg", "cyl")]), type = "cov", numObs= 100) xmu_make_mxData(data= tmp, type = "cor", manifests = c("mpg", "cyl")) # consume mxData xmu_make_mxData(data= tmp, type = "cor", manifests = c("mpg")) # trim existing mxData xmu_make_mxData(data= tmp, type = "cor") # no manifests specified (use all) xmu_make_mxData(data= tmp, manifests = c("mpg", "cyl")) # auto # ======================= # = Pass string through = # ======================= xmu_make_mxData(data= c("a", "b", "c"), type = "Auto") cleanEx() nameEx("xmu_match.arg") ### * xmu_match.arg flush(stderr()); flush(stdout()) ### Name: xmu_match.arg ### Title: Select first item in list of options, while being flexible about ### choices. ### Aliases: xmu_match.arg ### ** Examples option_list = c("default", "par.observed", "empirical") xmu_match.arg("par.observed", option_list) xmu_match.arg("allow me", option_list, check = FALSE) xmu_match.arg(option_list, option_list) option_list = c(NULL, "par.observed", "empirical") # fails with NULL!!!!! xmu_match.arg(option_list, option_list) option_list = c(NA, "par.observed", "empirical") xmu_match.arg(option_list, option_list) # use NA instead option_list = c(TRUE, FALSE, NA) xmu_match.arg(option_list, option_list) # works with non character # An example of checking a bad item and stopping ## Not run: ##D tmp <- function(x= c("one", "two", "three")) { ##D xmu_match.arg(x, option_list = c("one", "two", "three")) ##D } ##D testthat::expect_true(tmp() == "one") ##D testthat::expect_error(tmp("bad")) ##D tmp <- function(x= c("one", "two", "three")) { ##D xmu_match.arg(x, option_list = c("one", "two", "three"), check = FALSE) ##D } ##D testthat::expect_true(tmp("OK") == "OK") ##D testthat::expect_error(tmp(), NA) ## End(Not run) cleanEx() nameEx("xmu_name_from_lavaan_str") ### * xmu_name_from_lavaan_str flush(stderr()); flush(stdout()) ### Name: xmu_name_from_lavaan_str ### Title: Find name for model ### Aliases: xmu_name_from_lavaan_str ### ** Examples "m1" == xmu_name_from_lavaan_str("x~~x") "bob" == xmu_name_from_lavaan_str(name = "bob") "my_model" == xmu_name_from_lavaan_str("# my model") cleanEx() nameEx("xmu_path2twin") ### * xmu_path2twin flush(stderr()); flush(stdout()) ### Name: xmu_path2twin ### Title: Re-name variables in umxPaths to twin versions ### Aliases: xmu_path2twin ### ** Examples twin1PathList = c( umxPath(v1m0 = c("a1", 'c1', "e1")), umxPath(fromEach = c("a1", 'c1', "e1"), to = "NFC3", values=.2) ) xmu_path2twin(twin1PathList, thisTwin = 2) cleanEx() nameEx("xmu_path_regex") ### * xmu_path_regex flush(stderr()); flush(stdout()) ### Name: xmu_path_regex ### Title: Re-name variables umxPaths to twin versions ### Aliases: xmu_path_regex ### ** Examples xmu_path_regex(c("a", "one", "b"), pattern = "$", replacement = "_T1") # "a_T1" "one" "b_T1" cleanEx() nameEx("xmu_print_algebras") ### * xmu_print_algebras flush(stderr()); flush(stdout()) ### Name: xmu_print_algebras ### Title: Print algebras from a umx model ### Aliases: xmu_print_algebras ### ** Examples ## Not run: ##D library(mlbench) ##D data(BostonHousing2) ##D BostonHousing2$log_crim = log2(BostonHousing2$crim) ##D BostonHousing2$nox = BostonHousing2$nox*100 ##D m2 = umxRAM(data = BostonHousing2, "#crime_model ##D cmedv ~ log_crim + b1*nox; ##D nox ~ a1*rad + a2*log_crim ##D i_1 := a1*b1 ##D i_2 := a2*b1" ##D ) ##D m3 = mxRun(mxModel(m1, mxAlgebra(name= "rtwo", rbind(i_1, i_2)))) ##D m3 = mxRun(mxModel(m3, mxAlgebra(name= "ctwo", cbind(i_1, i_2)))) ##D xmu_print_algebras(m3) ## End(Not run) cleanEx() nameEx("xmu_rclabel_2_bracket_address") ### * xmu_rclabel_2_bracket_address flush(stderr()); flush(stdout()) ### Name: xmu_rclabel_2_bracket_address ### Title: Convert an "A_r1c1"-style label to a bracket address. ### Aliases: xmu_rclabel_2_bracket_address ### ** Examples xmu_rclabel_2_bracket_address(label = "A_r1c1") #A[1,1] xmu_rclabel_2_bracket_address(label = "A_r10c1") xmu_rclabel_2_bracket_address(label = "A_r1c1", dotprefix = "model.top") xmu_rclabel_2_bracket_address("A_r1c1", suffix= "_std") xmu_rclabel_2_bracket_address("A_r1c1", dotprefix="myModel", suffix="_std") cleanEx() nameEx("xmu_safe_run_summary") ### * xmu_safe_run_summary flush(stderr()); flush(stdout()) ### Name: xmu_safe_run_summary ### Title: Safely run and summarize a model ### Aliases: xmu_safe_run_summary ### ** Examples ## Not run: ##D tmp = mtcars ##D tmp$disp = tmp$disp/100 ##D m1 = umxRAM("tim", data = tmp, ##D umxPath(c("wt", "disp"), to = "mpg"), ##D umxPath("wt", with = "disp"), ##D umxPath(v.m. = c("wt", "disp", "mpg")) ##D ) ##D m2 = umxModify(m1, "wt_to_mpg") ##D ##D # Summary ignored if run is false ##D xmu_safe_run_summary(m1, autoRun = FALSE, summary = TRUE) ##D # Run, no summary ##D xmu_safe_run_summary(m1, autoRun = TRUE, summary = FALSE) ##D # Default summary is just fit string ##D xmu_safe_run_summary(m1, autoRun = TRUE, summary = TRUE) ##D # Show std parameters ##D xmu_safe_run_summary(m1, autoRun = TRUE, summary = TRUE, std = TRUE) ##D # Run + Summary + comparison ##D xmu_safe_run_summary(m1, m2, autoRun = TRUE, summary = TRUE, intervals = TRUE) ##D # Run + Summary + no comparison ##D xmu_safe_run_summary(m1, m2, autoRun = TRUE, summary = TRUE, std = TRUE, comparison= FALSE) ##D ## End(Not run) cleanEx() nameEx("xmu_set_sep_from_suffix") ### * xmu_set_sep_from_suffix flush(stderr()); flush(stdout()) ### Name: xmu_set_sep_from_suffix ### Title: Just a helper to cope with deprecated suffix lying around. ### Aliases: xmu_set_sep_from_suffix ### ** Examples xmu_set_sep_from_suffix(sep = "_T", suffix = "deprecated") cleanEx() nameEx("xmu_show_fit_or_comparison") ### * xmu_show_fit_or_comparison flush(stderr()); flush(stdout()) ### Name: xmu_show_fit_or_comparison ### Title: Show model logLik of model or print comparison table ### Aliases: xmu_show_fit_or_comparison ### ** Examples ## Not run: ##D xmu_show_fit_or_comparison(model, comparison, digits=3) ## End(Not run) cleanEx() nameEx("xmu_simplex_corner") ### * xmu_simplex_corner flush(stderr()); flush(stdout()) ### Name: xmu_simplex_corner ### Title: Internal function to help building simplex models ### Aliases: xmu_simplex_corner ### ** Examples x = umxMatrix('test', 'Full', nrow = 4, ncol = 4) xmu_simplex_corner(x, start = .9) # See how we have a diag free, but offset 1-down? umx_print( xmu_simplex_corner(x, start = .9)$values, zero=".") cleanEx() nameEx("xmu_standardize_ACE") ### * xmu_standardize_ACE flush(stderr()); flush(stdout()) ### Name: xmu_standardize_ACE ### Title: xmu_standardize_ACE ### Aliases: xmu_standardize_ACE ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D selDVs = c("bmi1", "bmi2") ##D mzData = twinData[twinData$zygosity %in% "MZFF", selDVs] ##D dzData = twinData[twinData$zygosity %in% "DZFF", selDVs] ##D m1 = umxACE(selDVs = selDVs, dzData = dzData, mzData = mzData) ##D std = xmu_standardize_ACE(m1) ## End(Not run) cleanEx() nameEx("xmu_standardize_ACEcov") ### * xmu_standardize_ACEcov flush(stderr()); flush(stdout()) ### Name: xmu_standardize_ACEcov ### Title: xmu_standardize_ACEcov ### Aliases: xmu_standardize_ACEcov ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D twinData$age1 = twinData$age2 = twinData$age ##D selDVs = c("bmi") ##D selCovs = c("ht") # silly example ##D selVars = umx_paste_names(c(selDVs, selCovs), sep = "", suffixes= 1:2) ##D mzData = subset(twinData, zyg == 1, selVars)[1:80, ] ##D dzData = subset(twinData, zyg == 3, selVars)[1:80, ] ##D m1 = umxACEcov(selDVs = selDVs, selCovs = selCovs, dzData = dzData, mzData = mzData, ##D sep = "", autoRun = TRUE) ##D fit = xmu_standardize_ACEcov(m1) ## End(Not run) cleanEx() nameEx("xmu_standardize_ACEv") ### * xmu_standardize_ACEv flush(stderr()); flush(stdout()) ### Name: xmu_standardize_ACEv ### Title: Standardize an ACE variance components model (ACEv) ### Aliases: xmu_standardize_ACEv ### ** Examples ## Not run: ##D require(umx) ##D data(twinData) ##D mzData = twinData[twinData$zygosity %in% "MZFF",] ##D dzData = twinData[twinData$zygosity %in% "DZFF",] ##D m1 = umxACEv(selDVs = "bmi", sep="", dzData = dzData, mzData = mzData) ##D std = umx_standardize(m1) ## End(Not run) cleanEx() nameEx("xmu_standardize_CP") ### * xmu_standardize_CP flush(stderr()); flush(stdout()) ### Name: xmu_standardize_CP ### Title: Function to standardize a common pathway model ### Aliases: xmu_standardize_CP ### ** Examples ## Not run: ##D selDVs = c("gff", "fc", "qol", "hap", "sat", "AD") ##D m1 = umxCP(selDVs = selDVs, nFac = 3, data=GFF, zyg="zyg_2grp") ##D m2 = xmu_standardize_CP(m1) ## End(Not run) cleanEx() nameEx("xmu_standardize_IP") ### * xmu_standardize_IP flush(stderr()); flush(stdout()) ### Name: xmu_standardize_IP ### Title: non-user: Standardize an IP model ### Aliases: xmu_standardize_IP ### ** Examples ## Not run: ##D model = xmu_standardize_IP(model) ## End(Not run) cleanEx() nameEx("xmu_standardize_RAM") ### * xmu_standardize_RAM flush(stderr()); flush(stdout()) ### Name: xmu_standardize_RAM ### Title: Standardize a Structural Model (not for end users) ### Aliases: xmu_standardize_RAM ### ** Examples ## Not run: ##D require(umx) ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D ##D m1 = umxRAM("std_ex", data = demoOneFactor, type = "cov", ##D umxPath("G", to = manifests), ##D umxPath(var = manifests), ##D umxPath(var = "G", fixedAt = 1.0) ##D ) ##D ##D m1 = xmu_standardize_RAM(m1) ##D m1 = umx_standardize(m1) ##D umxSummary(m1) ##D ## End(Not run) cleanEx() nameEx("xmu_standardize_SexLim") ### * xmu_standardize_SexLim flush(stderr()); flush(stdout()) ### Name: xmu_standardize_SexLim ### Title: Standardize a SexLim model ### Aliases: xmu_standardize_SexLim ### ** Examples ## Not run: ##D model = xmu_standardize_SexLim(model) ## End(Not run) cleanEx() nameEx("xmu_standardize_Simplex") ### * xmu_standardize_Simplex flush(stderr()); flush(stdout()) ### Name: xmu_standardize_Simplex ### Title: Standardize a Simplex twin model ### Aliases: xmu_standardize_Simplex ### ** Examples ## Not run: ##D data(iqdat) ##D mzData = subset(iqdat, zygosity == "MZ") ##D dzData = subset(iqdat, zygosity == "DZ") ##D m1 = umxSimplex(selDVs = paste0("IQ_age", 1:4), sep = "_T", ##D dzData = dzData, mzData = mzData, tryHard = "yes") ##D std = xmu_standardize_Simplex(m1) ## End(Not run) cleanEx() nameEx("xmu_starts") ### * xmu_starts flush(stderr()); flush(stdout()) ### Name: xmu_starts ### Title: Helper providing boilerplate start values for means and variance ### in twin models ### Aliases: xmu_starts ### ** Examples data(twinData) selDVs = c("wt", "ht") mzData = twinData[twinData$zygosity %in% "MZFF", ] dzData = twinData[twinData$zygosity %in% "DZFF", ] round(sqrt(var(dzData[,tvars(selDVs, "")], na.rm=TRUE)/3),3) xmu_starts(mzData, dzData, selVars=selDVs, nSib= 2, sep="", equateMeans=TRUE, varForm="Cholesky") # Variance instead of SD round(var(dzData[,tvars(selDVs, "")], na.rm=TRUE)/3,3) xmu_starts(mzData, dzData, selVars = selDVs, nSib = 2, sep= "", equateMeans= TRUE, varForm= "Cholesky", SD= FALSE) # one variable xmu_starts(mzData, dzData, selVars= "wt", nSib = 2, sep="", equateMeans = TRUE) # Ordinal/continuous mix data(twinData) twinData= umx_scale_wide_twin_data(data=twinData,varsToScale="wt",sep= "") # Cut BMI column to form ordinal obesity variables cuts = quantile(twinData[, "bmi1"], probs = c(.5, .8), na.rm = TRUE) obLevels = c('normal', 'overweight', 'obese') twinData$obese1= cut(twinData$bmi1,breaks=c(-Inf,cuts,Inf),labels=obLevels) twinData$obese2= cut(twinData$bmi2,breaks=c(-Inf,cuts,Inf),labels=obLevels) # Make the ordinal variables into mxFactors ordDVs = c("obese1", "obese2") twinData[, ordDVs] = umxFactor(twinData[, ordDVs]) mzData = twinData[twinData$zygosity %in% "MZFF",] dzData = twinData[twinData$zygosity %in% "DZFF",] xmu_starts(mzData, dzData, selVars = c("wt","obese"), sep= "", nSib= 2, equateMeans = TRUE, SD= FALSE) xmu_starts(mxData(mzData, type="raw"), mxData(mzData, type="raw"), selVars = c("wt","obese"), sep= "", nSib= 2, equateMeans = TRUE, SD= FALSE) # ============== # = Three sibs = # ============== data(twinData) twinData$wt3 = twinData$wt2 twinData$ht3 = twinData$ht2 selDVs = c("wt", "ht") mzData = twinData[twinData$zygosity %in% "MZFF", ] dzData = twinData[twinData$zygosity %in% "DZFF", ] xmu_starts(mzData, dzData, selVars=selDVs, sep="", nSib=3, equateMeans=TRUE) xmu_starts(mzData, dzData, selVars=selDVs, sep="", nSib=3, equateMeans=FALSE) cleanEx() nameEx("xmu_summary_RAM_group_parameters") ### * xmu_summary_RAM_group_parameters flush(stderr()); flush(stdout()) ### Name: xmu_summary_RAM_group_parameters ### Title: Order and group the parameters in a RAM summary ### Aliases: xmu_summary_RAM_group_parameters ### ** Examples ## Not run: ##D data(demoOneFactor) ##D manifests = names(demoOneFactor) ##D m1 = umxRAM("One Factor", data = demoOneFactor, ##D umxPath("G", to = manifests), ##D umxPath(v.m. = manifests), ##D umxPath(v1m0 = "G") ##D ) ##D tmp = umxSummary(m1, means=FALSE, residuals = FALSE) ##D xmu_summary_RAM_group_parameters(m1, paramTable = tmp, means= FALSE, residuals= FALSE) ## End(Not run) cleanEx() nameEx("xmu_twin_add_WeightMatrices") ### * xmu_twin_add_WeightMatrices flush(stderr()); flush(stdout()) ### Name: xmu_twin_add_WeightMatrices ### Title: Add weight matrices to twin models. ### Aliases: xmu_twin_add_WeightMatrices ### ** Examples tmp = umx_make_twin_data_nice(data=twinData, sep="", zygosity="zygosity", numbering= 1:2) m1 = umxACE(selDVs = "wt", data = tmp, dzData = "DZFF", mzData = "MZFF", autoRun= FALSE) m1$MZ$fitfunction$vector= TRUE tmp = xmu_twin_add_WeightMatrices(m1, mzWeights= rnorm(nrow(m1$MZ$data$observed)), dzWeights= rnorm(nrow(m1$DZ$data$observed)) ) cleanEx() nameEx("xmu_twin_check") ### * xmu_twin_check flush(stderr()); flush(stdout()) ### Name: xmu_twin_check ### Title: Check basic aspects of input for twin models. ### Aliases: xmu_twin_check ### ** Examples library(umx) data(twinData) mzData = subset(twinData, zygosity == "MZFF") dzData = subset(twinData, zygosity == "MZFF") xmu_twin_check(selDVs = c("wt", "ht"), dzData = dzData, mzData = mzData, sep = "", enforceSep = TRUE) xmu_twin_check(selDVs = c("wt", "ht"), dzData = dzData, mzData = mzData, sep = "", enforceSep = FALSE) xmu_twin_check(selDVs = c("wt", "ht"), dzData = dzData, mzData = mzData, sep = "", enforceSep = TRUE, nSib = 2, optimizer = NULL) ## Not run: ##D # TODO xmu_twin_check: move to a test file: ##D # 1. stop on no rows ##D xmu_twin_check("Generativity", twinData[NULL,], twinData[NULL,], sep="_T") ##D # Error in xmu_twin_check("Generativity", twinData[NULL, ], twinData[NULL, : ##D # Your DZ dataset has no rows! ##D ##D # 2. Stop on a NULL sep = NULL IFF enforceSep = TRUE ##D xmu_twin_check(selDVs = c("wt", "ht"), dzData = dzData, mzData = mzData, enforceSep = TRUE) ##D # 3. stop on a factor with sep = NULL ## End(Not run) cleanEx() nameEx("xmu_twin_get_var_names") ### * xmu_twin_get_var_names flush(stderr()); flush(stdout()) ### Name: xmu_twin_get_var_names ### Title: Not for user: pull variable names from a twin model ### Aliases: xmu_twin_get_var_names ### ** Examples ## Not run: ##D data(twinData) # ?twinData from Australian twins. ##D twinData[, c("ht1", "ht2")] = twinData[, c("ht1", "ht2")] * 10 ##D mzData = twinData[twinData$zygosity %in% "MZFF", ] ##D dzData = twinData[twinData$zygosity %in% "DZFF", ] ##D m1 = umxACE(selDVs= "ht", sep= "", dzData= dzData, mzData= mzData, autoRun= FALSE) ##D selVars = xmu_twin_get_var_names(m1, source = "expCovMZ", trim = TRUE, twinOneOnly = TRUE) # "ht" ##D umx_check(selVars == "ht") ##D xmu_twin_get_var_names(m1, source= "expCovMZ", trim= FALSE, twinOneOnly= FALSE) # "ht1" "ht2" ##D selVars = xmu_twin_get_var_names(m1, source= "observed", trim= TRUE, twinOneOnly= TRUE)# "ht" ##D nVar = length(selVars) ##D umx_check(nVar == 1) ## End(Not run) cleanEx() nameEx("xmu_twin_make_def_means_mats_and_alg") ### * xmu_twin_make_def_means_mats_and_alg flush(stderr()); flush(stdout()) ### Name: xmu_twin_make_def_means_mats_and_alg ### Title: Make the matrices and algebras for definition-based means models ### Aliases: xmu_twin_make_def_means_mats_and_alg ### ** Examples # xmu_twin_make_def_means_mats_and_alg(baseCovs= baseCovs, # fullVars = fullVars, nSib = nSib, sep= sep) cleanEx() nameEx("xmu_twin_upgrade_selDvs2SelVars") ### * xmu_twin_upgrade_selDvs2SelVars flush(stderr()); flush(stdout()) ### Name: xmu_twin_upgrade_selDvs2SelVars ### Title: Upgrade selDVs to selVars ### Aliases: xmu_twin_upgrade_selDvs2SelVars ### ** Examples xmu_twin_upgrade_selDvs2SelVars("wt", NULL, 2) ### *