R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: aarch64-apple-darwin20 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > pkgname <- "umx" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('umx') Loading required package: OpenMx OpenMx may run faster if it is compiled to take advantage of multiple cores. For an overview type '?umx' Attaching package: ‘umx’ The following object is masked from ‘package:stats’: loadings > > 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)) [1] 0.08007885 > > > > 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 0.01311769 > SE_from_p(beta = .0020, p = .01) SE 0.0003622892 > SE_from_p(beta = .0020, SE = 0.01) p_value 0.8521097 > umxAPA(.0020, p = .01) β = 0 [0, 0]> > > > cleanEx() > nameEx("bucks") > ### * bucks > > flush(stderr()); flush(stdout()) > > ### Name: bucks > ### Title: Print a money object > ### Aliases: bucks print > > ### ** Examples > > bucks(100 * 1.05^32) $476.49> fin_interest(deposits = 20e3, interest = 0.07, yrs = 20) Table: Compounding £20,000 deposits over 20 years at 7% interest with 0% inflation. |Year |Deposits |Interest |Total_Deposits |Total_Interest |Total | |:----|:--------|:--------|:--------------|:--------------|:--------| | | | | | |£0 | |2023 |£20,000 |£1,446 |£20,000 |£1,446 |£21,446 | |2024 |£20,000 |£2,996 |£40,000 |£4,442 |£44,442 | |2025 |£20,000 |£4,659 |£60,000 |£9,100 |£69,100 | |2026 |£20,000 |£6,441 |£80,000 |£15,542 |£95,542 | |2027 |£20,000 |£8,353 |£100,000 |£23,894 |£123,894 | |2028 |£20,000 |£10,402 |£120,000 |£34,296 |£154,296 | |2029 |£20,000 |£12,600 |£140,000 |£46,896 |£186,896 | |2030 |£20,000 |£14,957 |£160,000 |£61,853 |£221,853 | |2031 |£20,000 |£17,484 |£180,000 |£79,336 |£259,336 | |2032 |£20,000 |£20,193 |£200,000 |£99,529 |£299,529 | |2033 |£20,000 |£23,099 |£220,000 |£122,628 |£342,628 | |2034 |£20,000 |£26,214 |£240,000 |£148,843 |£388,843 | |2035 |£20,000 |£29,555 |£260,000 |£178,398 |£438,398 | |2036 |£20,000 |£33,138 |£280,000 |£211,535 |£491,535 | |2037 |£20,000 |£36,979 |£300,000 |£248,514 |£548,514 | |2038 |£20,000 |£41,098 |£320,000 |£289,612 |£609,612 | |2039 |£20,000 |£45,515 |£340,000 |£335,127 |£675,127 | |2040 |£20,000 |£50,251 |£360,000 |£385,378 |£745,378 | |2041 |£20,000 |£55,329 |£380,000 |£440,707 |£820,707 | |2042 |£20,000 |£60,775 |£400,000 |£501,482 |£901,482 | £901,482> > > > > cleanEx() > nameEx("deg2rad") > ### * deg2rad > > flush(stderr()); flush(stdout()) > > ### Name: deg2rad > ### Title: Convert Degrees to Degrees > ### Aliases: deg2rad > > ### ** Examples > > deg2rad(180) == pi # TRUE! [1] 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) 'data.frame': 1400 obs. of 13 variables: $ zygosity: chr "MZMM" "MZMM" "MZMM" "MZMM" ... $ varA1_T1: num 0.991 0.541 -0.569 1.865 1.287 ... $ varA2_T1: num 0.4092 -0.7654 0.0245 1.0477 1.3926 ... $ varA3_T1: num -0.449 -1.583 1.368 1.069 2.719 ... $ varB1_T1: num 1.619 -0.484 -3.102 0.367 0.285 ... $ varB2_T1: num 2.58 -0.361 -0.859 -0.433 0.683 ... $ varB3_T1: num 1.467 0.087 -0.967 0.307 0.715 ... $ varA1_T2: num 0.668 -0.998 2.455 2.064 -0.625 ... $ varA2_T2: num -0.139 -0.41 2.124 2.522 -0.102 ... $ varA3_T2: num 0.278 0.644 2.695 -0.673 0.828 ... $ varB1_T2: num 1.459 0.397 -2.195 -0.568 1.443 ... $ varB2_T2: num 2.753 0.914 0.779 1.15 2.983 ... $ varB3_T2: num 2.166 0.553 0.821 1.801 0.337 ... > 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) Employer pays £4,576.08, and employee pays £3,891.84. So 20.16 % total! £8,467.92> fin_NI(142000) Employer pays £18,376.08, and employee pays £17,726.44. So 25.42 % total! £36,102.52> > > > > 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) Table: Compounding £5,000 principle plus £0 annual deposits, 5% interest and 0% inflation. |Year |Deposits |Interest |Total_Deposits |Total_Interest |Total | |:----|:--------|:--------|:--------------|:--------------|:------| | | | | | |£5,000 | |2023 |£0 |£256 |£0 |£256 |£5,256 | |2024 |£0 |£269 |£0 |£525 |£5,525 | |2025 |£0 |£283 |£0 |£807 |£5,807 | |2026 |£0 |£297 |£0 |£1,104 |£6,104 | |2027 |£0 |£312 |£0 |£1,417 |£6,417 | |2028 |£0 |£328 |£0 |£1,745 |£6,745 | |2029 |£0 |£345 |£0 |£2,090 |£7,090 | |2030 |£0 |£363 |£0 |£2,453 |£7,453 | |2031 |£0 |£381 |£0 |£2,834 |£7,834 | |2032 |£0 |£401 |£0 |£3,235 |£8,235 | £8,235.05> > 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) [1] 0.05768093 > fin_interest(principal = 50, final=200, yrs = 5) [1] 0.259921 > > # 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) Table: Compounding £100 deposits over 10 years at 7% interest with 0% inflation. |Year |Deposits |Interest |Total_Deposits |Total_Interest |Total | |:----|:--------|:--------|:--------------|:--------------|:------| | | | | | |£0 | |2023 |£100 |£7 |£100 |£7 |£107 | |2024 |£100 |£15 |£200 |£22 |£222 | |2025 |£100 |£23 |£300 |£46 |£346 | |2026 |£100 |£32 |£400 |£78 |£478 | |2027 |£100 |£42 |£500 |£119 |£619 | |2028 |£100 |£52 |£600 |£171 |£771 | |2029 |£100 |£63 |£700 |£234 |£934 | |2030 |£100 |£75 |£800 |£309 |£1,109 | |2031 |£100 |£87 |£900 |£397 |£1,297 | |2032 |£100 |£101 |£1,000 |£498 |£1,498 | £1,497.65> > # 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="$") Table: Compounding $20,000 principle plus $100 annual deposits, 7% interest and 0% inflation. |Year |Deposits |Interest |Total_Deposits |Total_Interest |Total | |:----|:--------|:--------|:--------------|:--------------|:-------| | | | | | |$20,000 | |2023 |$100 |$1,453 |$100 |$1,453 |$21,553 | |2024 |$100 |$1,565 |$200 |$3,018 |$23,218 | |2025 |$100 |$1,686 |$300 |$4,704 |$25,004 | |2026 |$100 |$1,815 |$400 |$6,519 |$26,919 | |2027 |$100 |$1,953 |$500 |$8,472 |$28,972 | |2028 |$100 |$2,102 |$600 |$10,574 |$31,174 | |2029 |$100 |$2,261 |$700 |$12,834 |$33,534 | |2030 |$100 |$2,431 |$800 |$15,266 |$36,066 | |2031 |$100 |$2,614 |$900 |$17,880 |$38,780 | |2032 |$100 |$2,811 |$1,000 |$20,691 |$41,691 | $41,690.87> > # 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") Table: Compounding £10,000 deposits over 5 years at 6% interest with 0% inflation. |Year |Deposits |Interest |Total_Deposits |Total_Interest |Total | |:----|:--------|:--------|:--------------|:--------------|:-------| | | | | | |£0 | |2023 |£10,000 |£0 |£10,000 |£0 |£10,000 | |2024 |£10,000 |£600 |£20,000 |£600 |£20,600 | |2025 |£10,000 |£1,236 |£30,000 |£1,836 |£31,836 | |2026 |£10,000 |£1,910 |£40,000 |£3,746 |£43,746 | |2027 |£10,000 |£2,625 |£50,000 |£6,371 |£56,371 | £56,370.93> > # 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) Table: Compounding £20,000 deposits over 10 years at 15% interest with 0% inflation. |Year |Deposits |Interest |Total_Deposits |Total_Interest |Total | |:----|:--------|:--------|:--------------|:--------------|:--------| | | | | | |£0 | |2 |£20,000 |£3,000 |£20,000 |£3,000 |£23,000 | |3 |£20,000 |£6,450 |£40,000 |£9,450 |£49,450 | |4 |£20,000 |£10,418 |£60,000 |£19,867 |£79,868 | |5 |£20,000 |£14,980 |£80,000 |£34,848 |£114,848 | |6 |£20,000 |£20,227 |£100,000 |£55,075 |£155,075 | |7 |£20,000 |£26,261 |£120,000 |£81,336 |£201,336 | |8 |£20,000 |£33,200 |£140,000 |£114,536 |£254,536 | |9 |£20,000 |£41,180 |£160,000 |£155,717 |£315,717 | |10 |£20,000 |£50,358 |£180,000 |£206,074 |£386,074 | |11 |£20,000 |£60,911 |£200,000 |£266,986 |£466,986 | £466,986> # $466,986 > > # manual equivalent > sum(20e3*(1.15^(10:1))) # 466985.5 [1] 466985.5 > > # 7. Annual (rather than monthly) compounding (n=1) > fin_interest(deposits = 100, interest = 0.07, yrs = 10, n=1) Table: Compounding £100 deposits over 10 years at 7% interest with 0% inflation. |Year |Deposits |Interest |Total_Deposits |Total_Interest |Total | |:----|:--------|:--------|:--------------|:--------------|:------| | | | | | |£0 | |2023 |£100 |£7 |£100 |£7 |£107 | |2024 |£100 |£14 |£200 |£21 |£221 | |2025 |£100 |£23 |£300 |£44 |£344 | |2026 |£100 |£31 |£400 |£75 |£475 | |2027 |£100 |£40 |£500 |£115 |£615 | |2028 |£100 |£50 |£600 |£165 |£765 | |2029 |£100 |£61 |£700 |£226 |£926 | |2030 |£100 |£72 |£800 |£298 |£1,098 | |2031 |£100 |£84 |£900 |£382 |£1,282 | |2032 |£100 |£97 |£1,000 |£478 |£1,478 | £1,478.36> > # 8 Interest needed to increase principal to final value in yrs time. > fin_interest(principal = 100, final=200, yrs = 5) [1] 0.122462 > > > > > 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) $100 decreased by -10% = $90 (Percent to reverse = 11%)> > # Percent needed to return to original value after 10% added on > fin_percent(10) $100 increased by 10% = $110 (Percent to reverse = -9%)> > # Percent needed to return to original value after 50% off 34.50 > fin_percent(-50, value = 34.5) $34.5 decreased by -50% = $17.25 (Percent to reverse = 100%)> > > > 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 > # 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)) [1] 70.71068 > > # For a given sum, geometric mean is maximised with equality > geometric_mean(c(75,75)) [1] 75 > > v = c(1, 149); c(sum(v), geometric_mean(v), mean(v), median(v)) [1] 150.00000 12.20656 75.00000 75.00000 > # 150.00000 12.20656 75.00000 75.00000 > > # Underlying logic > sqrt(50 * 100) [1] 70.71068 > > # Alternate form using logs > exp(mean(log(c(50 *100)))) [1] 5000 > > # Reciprocal duality > 1/geometric_mean(c(100, 50)) [1] 0.01414214 > geometric_mean(c(1/100, 1/50)) [1] 0.01414214 > > > > 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) [1] 27.10714 > > geometric_mean(tmp) [1] 27.54995 > mean(tmp) [1] 28 > > # Example with weights > harmonic_mean(c(33/1, 23/1), weights= c(.2, .8)) [1] 24.48387 > # 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 [1] 1.818182 > > > > > 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") [1] 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 10.4 [16] 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 15.0 [31] 21.4 > noNAs(tmp, cols="mpg", drop = FALSE) mpg Mazda RX4 21.0 Datsun 710 22.8 Hornet 4 Drive 21.4 Hornet Sportabout 18.7 Valiant 18.1 Duster 360 14.3 Merc 240D 24.4 Merc 230 22.8 Merc 280 19.2 Merc 280C 17.8 Merc 450SE 16.4 Merc 450SL 17.3 Merc 450SLC 15.2 Cadillac Fleetwood 10.4 Lincoln Continental 10.4 Chrysler Imperial 14.7 Fiat 128 32.4 Honda Civic 30.4 Toyota Corolla 33.9 Toyota Corona 21.5 Dodge Challenger 15.5 AMC Javelin 15.2 Camaro Z28 13.3 Pontiac Firebird 19.2 Fiat X1-9 27.3 Porsche 914-2 26.0 Lotus Europa 30.4 Ford Pantera L 15.8 Ferrari Dino 19.7 Maserati Bora 15.0 Volvo 142E 21.4 > noNAs(tmp) # no Mazda RX4 Wag mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 > > > > > 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)) Group 1 odds = 0.111 Group 2 odds = 0.429 OR = 0.259 CI95 [0.023, 2.936] polite note: Remember OR is sensitive to base rate: A given odds ratio can represent very different degrees of association/correlation> oddsratio(grp1 = 0.111, grp2 = 0.429) Group 1 odds = 0.111 Group 2 odds = 0.429 OR = 0.259 (input odds as c(n=, N=) to compute CI) polite note: Remember OR is sensitive to base rate: A given odds ratio can represent very different degrees of association/correlation> oddsratio(grp1 = c(3, 10), grp2 = c(1, 10)) Group 1 odds = 0.429 Group 2 odds = 0.111 OR = 3.857 CI95 [0.341, 43.681] polite note: Remember OR is sensitive to base rate: A given odds ratio can represent very different degrees of association/correlation> oddsratio(grp1 = c(3, 10), grp2 = c(1, 10), alpha = .01) Group 1 odds = 0.429 Group 2 odds = 0.111 OR = 3.857 CI99 [0.159, 93.646] polite note: Remember OR is sensitive to base rate: A given odds ratio can represent very different degrees of association/correlation> > > > > 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) $100 decreased by -10% = $90 (Percent to reverse = 11%)> # Percent needed to return to original value after 10% on > tmp = fin_percent(10) $100 increased by 10% = $110 (Percent to reverse = -9%)> plot(tmp) > > # Percent needed to return to original value after 50% off 34.50 > fin_percent(-50, value = 34.5, logY = FALSE) $34.5 decreased by -50% = $17.25 (Percent to reverse = 100%)> > > > > 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") Running ACE with 4 parameters Beginning initial fit attempt Running ACE with 4 parameters Lowest minimum so far: 21994.574343861 Solution found Solution found! Final fit=21994.574 (started at 22414.561) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: -3.35287353436797e-17,0.706922514642312,0.00346268726286137,0.706930816538969 Running drop_a with 3 parameters Beginning initial fit attempt Running drop_a with 3 parameters Lowest minimum so far: 22092.8159384325 Solution found Solution found! Final fit=22092.816 (started at 25153.483) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: -3.35287353436797e-17,0.612219323225085,0.790371748103349 For 80% power to detect 'a_r1c1' of size 0.5, you need 166 MZ and 166 DZ pairs. method = ncp n = 333 power = 0.8 sig.level = 0.05 statistic = LRT > # 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)) Group 1 odds = 0.111 Group 2 odds = 0.429 OR = 0.259 CI95 [0.023, 2.936] polite note: Remember OR is sensitive to base rate: A given odds ratio can represent very different degrees of association/correlation> oddsratio(grp1 = c(3, 10), grp2 = c(1, 10)) Group 1 odds = 0.429 Group 2 odds = 0.111 OR = 3.857 CI95 [0.341, 43.681] polite note: Remember OR is sensitive to base rate: A given odds ratio can represent very different degrees of association/correlation> oddsratio(grp1 = c(3, 10), grp2 = c(1, 10), alpha = .01) Group 1 odds = 0.429 Group 2 odds = 0.111 OR = 3.857 CI99 [0.159, 93.646] polite note: Remember OR is sensitive to base rate: A given odds ratio can represent very different degrees of association/correlation> > > > 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) $100 decreased by -10% = $90 (Percent to reverse = 11%)> # Percent needed to return to original value after 10% on > fin_percent(10) $100 increased by 10% = $110 (Percent to reverse = -9%)> > # Percent needed to return to original value after 50% off 34.50 > fin_percent(-50, value = 34.5) $34.5 decreased by -50% = $17.25 (Percent to reverse = 100%)> > > > > 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)) Alpha reliability = 0.4092 Standardized alpha = -1.102 Reliability deleting each item in turn: Alpha Std.Alpha r(item, total) mpg 0.4533 -0.5734 -0.8658 cyl 0.4004 -0.6398 0.9187 disp -0.1277 -0.6694 0.7665 hp -0.0824 -1.3683 0.7899 drat 0.4160 -1.3205 -0.6444 wt 0.4068 -0.6949 0.8440 qsec 0.4212 -0.2779 -0.5664 vs 0.4162 -0.5262 -0.7514 am 0.4152 -1.4206 -0.4867 gear 0.4157 -2.0394 -0.4189 carb 0.4064 -2.1877 0.5455 > > > > 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) [,1] [,2] [1,] 0 1 [2,] 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 [1] 180 > > > > 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)) Alpha reliability = 0.4092 Standardized alpha = -1.102 Reliability deleting each item in turn: Alpha Std.Alpha r(item, total) mpg 0.4533 -0.5734 -0.8658 cyl 0.4004 -0.6398 0.9187 disp -0.1277 -0.6694 0.7665 hp -0.0824 -1.3683 0.7899 drat 0.4160 -1.3205 -0.6444 wt 0.4068 -0.6949 0.8440 qsec 0.4212 -0.2779 -0.5664 vs 0.4162 -0.5262 -0.7514 am 0.4152 -1.4206 -0.4867 gear 0.4157 -2.0394 -0.4189 carb 0.4064 -2.1877 0.5455 > > > > 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 [1] FALSE > tmx_is.identified(nVariables = 3, nFactors = 1) # TRUE [1] TRUE > tmx_is.identified(nVariables = 4, nFactors = 2) # FALSE [1] FALSE > tmx_is.identified(nVariables = 5, nFactors = 2) # TRUE [1] 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 (Intercept) B = 34.96 [30.53, 39.39], t = 16.15, p < 0.001 wt B = -3.35 [-5.73, -0.97], t = -2.88, p = 0.007 disp B = -0.02 [-0.04, 0], t = -1.93, p = 0.064 R² = 0.781 (adj = 0.766)> umxAPA(lm(mpg ~ wt + disp, mtcars), "wt") # Just effect of weight wt B = -3.35 [-5.73, -0.97], t = -2.88, p = 0.007 R² = 0.781 (adj = 0.766)> umxAPA(lm(mpg ~ wt + disp, mtcars), std = TRUE) # Standardize model! (Intercept) β = 0 [-0.17, 0.17], t = 0, p = 1.000 wt β = -0.54 [-0.93, -0.16], t = -2.88, p = 0.007 disp β = -0.36 [-0.75, 0.02], t = -1.93, p = 0.064 R² = 0.781 (adj = 0.766)> > ############### > # 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) Change in the log odds of the outcome for a one unit increase in the predictor variable: Waiting for profiling to be done... (Intercept) log(odds) = 15.57 [3.45, 35.4], z = 1.98, p = 0.047 wt log(odds) = -3.47 [-7.75, -1.16], z = -2.09, p = 0.036 gear log(odds) = -0.82 [-2.71, 0.76], z = -0.99, p = 0.324 As ORs (odds ratios, rather than log(odds)): (Intercept) OR = 5791028.15 [31.36, 2354921693008653], z = 1.98, p = 0.047 wt OR = 0.03 [0, 0.31], z = -2.09, p = 0.036 gear OR = 0.44 [0.07, 2.15], z = -0.99, p = 0.324 And as probabilities... (Intercept) probability = 1 wt probability = 0.03 gear probability = 0.31 AIC = 29.599> > ############### > # A t-Test # > ############### > > umxAPA(t.test(x = 1:10, y = c(7:20))) Means in the x and y groups were '5.5' and '13.5'respectively. CI[-11.05, -4.95]. t(21.98) = -5.43, p = < 0.001> umxAPA(t.test(extra ~ group, data = sleep)) Means in the 1 and 2 groups were '0.75' and '2.33'respectively. CI[-3.37, 0.21]. t(17.78) = -1.86, p = 0.08> > # ====================================================== > # = Summarize DATA FRAME: Correlations + Means and SDs = > # ====================================================== > umxAPA(mtcars[,1:3]) | |mpg |cyl |disp | |:---------|:------------|:-----------|:---------------| |mpg |1 (0) | | | |cyl |-0.85 (0.05) |1 (0) | | |disp |-0.85 (0.05) |0.9 (0.03) |1 (0) | |Mean (SD) |20.09 (6.03) |6.19 (1.79) |230.72 (123.94) | > umxAPA(mtcars[,1:3], digits = 3) | |mpg |cyl |disp | |:---------|:--------------|:-------------|:---------------| |mpg |1 (0) | | | |cyl |-0.852 (0.049) |1 (0) | | |disp |-0.848 (0.051) |0.902 (0.034) |1 (0) | |Mean (SD) |20.09 (6.03) |6.19 (1.79) |230.72 (123.94) | > umxAPA(mtcars[,1:3], lower = FALSE) | |mpg |cyl |disp | |:---------|:------------|:------------|:---------------| |mpg |1 (0) |-0.85 (0.05) |-0.85 (0.05) | |cyl |-0.85 (0.05) |1 (0) |0.9 (0.03) | |disp |-0.85 (0.05) |0.9 (0.03) |1 (0) | |Mean (SD) |20.09 (6.03) |6.19 (1.79) |230.72 (123.94) | > ## 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 β = 0.4 [-0.19, 0.99]> > # Input beta and CI, and back out the SE > umxAPA(-0.030, c(-0.073, 0.013), digits = 3) β = -0.03 SE = 0.022> > # ==================== > # = Format a p-value = > # ==================== > umxAPA(.0182613) # 0.02 [1] "0.02" > umxAPA(.00018261) # < 0.001 [1] "< 0.001" > umxAPA(.00018261, addComparison = FALSE) # 0.001 [1] 0.001 > > # ======================== > # = Report a correlation = > # ======================== > data(twinData) > tmp = subset(twinData, zygosity %in% c("MZFF", "MZMM")) > m1 = cor.test(~ wt1 + wt2, data = tmp) > umxAPA(m1) r = 0.85 [0.83, 0.86], t(1726) = 66.48, p = < 0.001> > > > > 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() Rub steak in a table spoon of salt, put it back in the fridge for an hour (longer is fine). Place steak on a hot cast-iron skillet, with a little peanut oil. Turn steaks as often as you wish. Control heat to below smoke point. Remove and eat when internal temp reaches 130 € F. > > > > 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])) mpg cyl disp hp drat mpg 1.0000000 -0.8521620 -0.8475514 -0.7761684 0.6811719 cyl -0.8521620 1.0000000 0.9020329 0.8324475 -0.6999381 disp -0.8475514 0.9020329 1.0000000 0.7909486 -0.7102139 hp -0.7761684 0.8324475 0.7909486 1.0000000 -0.4487591 drat 0.6811719 -0.6999381 -0.7102139 -0.4487591 1.0000000 > > > > 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 is pre-alpha quality: Internals are stubs and parameter names may change! `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")' Warning: Removed 96 rows containing non-finite values (stat_smooth). Warning: Removed 96 rows containing missing values (geom_point). Warning in is.na(x) : is.na() applied to non-(list or vector) of type 'language' > umxDiffMZ(x="ht", y="wt", xylim = c( -2, 2), data = twinData, sep = "") umxDiffMZ is pre-alpha quality: Internals are stubs and parameter names may change! `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")' Warning: Removed 96 rows containing non-finite values (stat_smooth). Warning: Removed 96 rows containing missing values (geom_point). Warning in is.na(x) : is.na() applied to non-(list or vector) of type 'language' > > > > 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) [1] a b c d e f g h i j k l m n o p q r s t u v w x y z attr(,"mxFactor") [1] TRUE 26 Levels: a < b < c < d < e < f < g < h < i < j < k < l < m < n < o < ... < z > umxFactor(letters, verbose = TRUE) # report coercions Your variable was not a factor: I made it into one, with 26 levels:a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', '... [1] a b c d e f g h i j k l m n o p q r s t u v w x y z attr(,"mxFactor") [1] TRUE 26 Levels: a < b < c < d < e < f < g < h < i < j < k < l < m < n < o < ... < z > umxFactor(letters, ordered = FALSE) # non-ordered factor like factor(x) [1] a b c d e f g h i j k l m n o p q r s t u v w x y z Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z > # Dataframe example: > x = umx_factor(mtcars[,c("cyl", "am")], ordered = FALSE); str(x) 'data.frame': 32 obs. of 2 variables: $ cyl: Factor w/ 3 levels "4","6","8": 2 2 1 2 3 2 3 1 1 2 ... $ am : Factor w/ 2 levels "0","1": 2 2 2 1 1 1 1 1 1 1 ... > # ================= > # = 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) 'data.frame': 3808 obs. of 2 variables: $ bmi1: Ord.factor w/ 606 levels "22"<"22.0041"<..: 1 1 1 314 1 32 1 1 1 279 ... ..- attr(*, "mxFactor")= logi TRUE $ bmi2: Ord.factor w/ 606 levels "22"<"22.0041"<..: 1 1 1 383 1 123 1 1 1 1 ... ..- attr(*, "mxFactor")= logi TRUE > xmu_check_levels_identical(x, "bmi", sep="") [1] TRUE > > # 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) Ord.factor w/ 28 levels "0"<"1"<"2"<"3"<..: 1 1 1 15 2 1 4 6 5 1 ... - attr(*, "mxFactor")= logi TRUE > df = data.frame(x = x, y = y) > jnk = umxFactor(df); str(jnk) 'data.frame': 1000 obs. of 2 variables: $ x: Ord.factor w/ 28 levels "0"<"1"<"2"<"3"<..: 1 1 1 15 2 1 4 6 5 1 ... ..- attr(*, "mxFactor")= logi TRUE $ y: Ord.factor w/ 18 levels "0"<"1"<"2"<"3"<..: 7 7 1 2 1 1 5 1 1 6 ... ..- attr(*, "mxFactor")= logi TRUE > > > > 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")]) mpg am mpg 1.0000000 0.5998324 am 0.5998324 1.0000000 > umxHetCor(mtcars[,c("mpg", "am")], treatAllAsFactor = TRUE, verbose = TRUE) Two-Step Estimates Correlations/Type of Correlation: mpg am mpg 1 Polychoric am 0.7124 1 mpg am mpg 1.000000 0.712386 am 0.712386 1.000000 > > > > 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) Attaching package: ‘psych’ The following object is masked from ‘package:umx’: reliability The following object is masked from ‘package:OpenMx’: tr > library(psychTools) > data(bfi) > umxParan(bfi[, paste0("A", 1:5)]) Using eigendecomposition of correlation matrix. Computing: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% Results of Horn's Parallel Analysis for component retention 150 iterations, using the mean estimate -------------------------------------------------- Component Adjusted Unadjusted Estimated Eigenvalue Eigenvalue Bias -------------------------------------------------- 1 2.315760 2.369093 0.053333 -------------------------------------------------- Adjusted eigenvalues > 1 indicate dimensions to retain. (1 components retained) > umxParan(bfi, cols= paste0("A", 1:5)) Using eigendecomposition of correlation matrix. Computing: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% Results of Horn's Parallel Analysis for component retention 150 iterations, using the mean estimate -------------------------------------------------- Component Adjusted Unadjusted Estimated Eigenvalue Eigenvalue Bias -------------------------------------------------- 1 2.315612 2.369093 0.053480 -------------------------------------------------- Adjusted eigenvalues > 1 indicate dimensions to retain. (1 components retained) > # umxParan(bfi, paste0("AB", 1)) > > > > cleanEx() detaching ‘package:psychTools’, ‘package:psych’ > 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 mxPath A -> B [value=0, free=TRUE] > umxPath("A", to = "B", fixedAt = 1) # same, with value fixed @1 mxPath A -> B [value=1, free=FALSE] > umxPath("A", to = c("B", "C"), fixedAt = 1:2) # same, with more than 1 value mxPath A -> B [value=1, free=FALSE] A -> C [value=2, free=FALSE] > umxPath("A", to = c("B","C"), firstAt = 1) # Fix only the first path, others free mxPath A -> B [value=1, free=FALSE] A -> C [value=0, free=TRUE] > umxPath(var = "A") # Give a variance to A mxPath A <-> A [value=0, free=TRUE, lbound=0] > umxPath(var = "A", fixedAt = 1) # Give A variance, fixed at 1 mxPath A <-> A [value=1, free=FALSE, lbound=0] > umxPath(means = c("A","B")) # Create a means model for A: from = "one", to = "A" mxPath one -> A [value=0, free=TRUE] one -> B [value=0, free=TRUE] > umxPath(v1m0 = "A") # Give "A" variance and a mean, fixed at 1 and 0 respectively [[1]] mxPath A <-> A [value=1, free=FALSE, lbound=0] [[2]] mxPath one -> A [value=0, free=FALSE] > umxPath(v.m. = "A") # Give "A" variance and a mean, leaving both free. [[1]] mxPath A <-> A [value=1, free=TRUE, lbound=0] [[2]] mxPath one -> A [value=0, free=TRUE] > umxPath(v0m0 = "W", label = c(NA, "data.W")) [[1]] mxPath W <-> W [value=0, free=FALSE] [[2]] mxPath one -> W [value=0, free=FALSE, label='data.W'] > umxPath("A", with = "B") # using with: same as "to = B, arrows = 2" mxPath A <-> B [value=0, free=TRUE] > umxPath("A", with = "B", fixedAt = .5) # 2-head path fixed at .5 mxPath A <-> B [value=0.5, free=FALSE] > umxPath("A", with = c("B", "C"), firstAt = 1) # first covariance fixed at 1 mxPath A <-> B [value=1, free=FALSE] A <-> C [value=0, free=TRUE] > umxPath(cov = c("A", "B")) # Covariance A <-> B mxPath A <-> B [value=0, free=TRUE] > umxPath(defn = "mpg") # create latent called def_mpg, with 0 mean * var, and label = "data.mpg" 1 definition variables created: refer to them/it as: 'def_mpg' [[1]] mxPath def_mpg <-> def_mpg [value=0, free=FALSE, lbound=0] [[2]] mxPath one -> def_mpg [value=0, free=FALSE, label='data.mpg'] > umxPath(fromEach = c('a','b'), to = c('c','d')) # a->c, a<->d, b<->c, b<->d mxPath a -> c [value=0, free=TRUE] a -> d [value=0, free=TRUE] b -> c [value=0, free=TRUE] b -> d [value=0, free=TRUE] > umxPath(unique.bivariate = c('a','b','c')) # bivariate paths a<->b, a<->c, b<->c etc. mxPath a <-> b [value=0, free=TRUE] a <-> c [value=0, free=TRUE] b <-> c [value=0, free=TRUE] > umxPath(unique.pairs = letters[1:3]) # all distinct pairs: a<->a, a<->b, a<->c, b<->b, etc. mxPath a <-> a [value=0, free=TRUE] a <-> b [value=0, free=TRUE] a <-> c [value=0, free=TRUE] b <-> b [value=0, free=TRUE] b <-> c [value=0, free=TRUE] c <-> c [value=0, free=TRUE] > umxPath(Cholesky = c("A1","A2"), to = c("m1", "m2")) # Cholesky mxPath A1 -> m1 [value=0, free=TRUE, label='A1_to_m1', lbound=1e-06] A1 -> m2 [value=0, free=TRUE, label='A1_to_m2'] A2 -> m2 [value=0, free=TRUE, label='A2_to_m2', lbound=1e-06] > > ## 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) `geom_smooth()` using formula 'y ~ x' > umxPlot(x = "wt", y = "mpg", mtcars, fitx = 2, fity = 10) `geom_smooth()` using formula 'y ~ x' > > > > 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")) mean age 34.45 (SD= 14.17) |Var | Mean| SD|rMZFF (1232) |rMZMM (567) |rDZFF (751) |rDZMM (352) |rDZOS (906) | |:---|-----:|-----:|:------------|:-----------|:-----------|:-----------|:-----------| |wt | 63.88| 11.71|0.76 (0.01) |0.8 (0.02) |0.29 (0.03) |0.43 (0.04) |0.31 (0.03) | |ht | 1.68| 0.10|0.87 (0.01) |0.9 (0.01) |0.45 (0.03) |0.41 (0.05) |0.41 (0.03) | > MZs = c("MZMM", "MZFF"); DZs = c("DZFF","DZMM", "DZOS") > umxSummarizeTwinData(twinData, sep = "", selVars = c("wt", "ht"), MZ = MZs, DZ = DZs) mean age 34.45 (SD= 14.17) |Var | Mean| SD|rMZ (1799) |rDZ (2009) | |:---|-----:|-----:|:-----------|:-----------| |wt | 63.88| 11.71|0.85 (0.01) |0.32 (0.02) | |ht | 1.68| 0.10|0.94 (0) |0.39 (0.02) | > > > > 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) Running ACEv with 4 parameters ACEv -2 × log(Likelihood) = 9658.23 polite note: in future, please use report = 'markdown', not file='markdown'. file is for choosing a custom html file when writing to the browser with report= 'html' Table: Standardized parameter estimates from a 1-factor Direct variance ACE model. A: additive genetic; C: common environment; E: unique environment. | | A1| C1| E1| |:---|-----:|------:|-----:| |bmi | 0.807| -0.063| 0.256| Table: Means (from model$top$expMean) | | bmi1| bmi2| |:---------|------:|------:| |intercept | 21.649| 21.649| Standardized variance-based models may yield negative variances... ?umxPlotACEv options: std=, means=, digits=, strip_zero=, file=, min=, max = > umxSummary(m1, std = FALSE) ACEv -2 × log(Likelihood) = 9658.23 polite note: in future, please use report = 'markdown', not file='markdown'. file is for choosing a custom html file when writing to the browser with report= 'html' Table: Raw parameter estimates from a 1-factor direct-variance ACE model. A: additive genetic; C: common environment; E: unique environment. | | A1| C1| E1| |:---|----:|-----:|----:| |bmi | 0.76| -0.06| 0.24| Table: Means (from model$top$expMean) | | bmi1| bmi2| |:---------|-----:|-----:| |intercept | 21.65| 21.65| ?umxPlotACEv options: std=, means=, digits=, strip_zero=, file=, min=, max = > ## 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 [,1] [1,] 1 > tmp[[1]]$free [,1] [1,] FALSE > > # The deviations matrix > tmp[[2]]$values x dev_1 0.05015358 > tmp[[2]]$labels # note: for twins, labels will be equated across twins x dev_1 "x_dev1" > > # The algebra that adds the deviations to create thresholds: > tmp[[3]]$formula lowerOnes_for_thresh %*% deviations_for_thresh > > # 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 [1] "deviations_for_thresh" > tmp[[2]]$free # last one is free.. (method = Mehta) x dev_1 FALSE dev_2 FALSE dev_3 TRUE > > tmp = umxThresholdMatrix(x, fullVarNames = "x", l_u_bound= c(-1,1)) > tmp[[2]]$lbound # bounds applied to base threshold x dev_1 -1.000 dev_2 0.001 dev_3 0.001 > > # ================================= > # = 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) object 'threshMat' created to handle: 1 pair(s) of binary variables:'obese1' and 'obese2' 2 trait(s) are binary: 'obese1' and 'obese2' For these, you you MUST fix the mean and variance of the latent traits driving each variable (usually 0 & 1 respectively) . See ?umxThresholdMatrix Using deviation-based model: Thresholds will be in'threshMat' based on deviations in 'deviations_for_thresh' > > > # ====================================== > # = 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) object 'threshMat' created to handle: 1 pair(s) of ordinal variables:'obeseTri1' and 'obeseTri2' 2 variables are ordinal (>2 levels). For these I will use Paras Mehta's 'fix first 2 thresholds' method. It's ESSENTIAL that you leave the means and variances of the latent ordinal traits FREE! See ?umxThresholdMatrix Using deviation-based model: Thresholds will be in'threshMat' based on deviations in 'deviations_for_thresh' > > > # ======================================================== > # = 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) object 'threshMat' created to handle: 2 pair(s) of ordinal variables:'obeseTri1', 'obeseQuad1', 'obeseTri2', and 'obeseQuad2' : 1 pair(s) of binary variables:'obese1' and 'obese2' 2 trait(s) are binary: 'obese1' and 'obese2' For these, you you MUST fix the mean and variance of the latent traits driving each variable (usually 0 & 1 respectively) . See ?umxThresholdMatrix 4 variables are ordinal (>2 levels). For these I will use Paras Mehta's 'fix first 2 thresholds' method. It's ESSENTIAL that you leave the means and variances of the latent ordinal traits FREE! See ?umxThresholdMatrix Using deviation-based model: Thresholds will be in'threshMat' based on deviations in 'deviations_for_thresh' > # The lower ones matrix (all fixed) > tmp[[1]]$values [,1] [,2] [,3] [1,] 1 0 0 [2,] 1 1 0 [3,] 1 1 1 > # The deviations matrix > tmp[[2]]$values obese1 obeseTri1 obeseQuad1 obese2 obeseTri2 obeseQuad2 dev_1 -0.8878407 -0.3131813 -0.7027590 -0.8878407 -0.3131813 -0.7027590 dev_2 0.8888407 0.7796802 0.3895777 0.8888407 0.7796802 0.3895777 dev_3 0.0010000 0.0010000 0.7796802 0.0010000 0.0010000 0.7796802 > tmp[[2]]$labels # note labels are equated across twins obese1 obeseTri1 obeseQuad1 obese2 dev_1 "obese_dev1" "obeseTri_dev1" "obeseQuad_dev1" "obese_dev1" dev_2 NA "obeseTri_dev2" "obeseQuad_dev2" NA dev_3 NA NA "obeseQuad_dev3" NA obeseTri2 obeseQuad2 dev_1 "obeseTri_dev1" "obeseQuad_dev1" dev_2 "obeseTri_dev2" "obeseQuad_dev2" dev_3 NA "obeseQuad_dev3" > # Check to be sure twin-1 column labels same as twin-2 > tmp[[2]]$labels[,2]==tmp[[2]]$labels[,4] dev_1 dev_2 dev_3 FALSE NA NA > > # The algebra that assembles these into thresholds: > tmp[[3]]$formula lowerOnes_for_thresh %*% deviations_for_thresh > # ================================= > # = Example with method = allFree = > # ================================= > > tmp = umxThresholdMatrix(twinData, fullVarNames = tvars(selDVs, sep= ""), sep = "", + method = "allFree") > all(tmp[[2]]$free) [1] TRUE > > > > > 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 umx version: 4.15.1 OpenMx version: 2.20.6 [GIT v2.20.6-dirty] R version: R version 4.2.1 (2022-06-23) Platform: aarch64-apple-darwin20 MacOS: 12.6 Default optimizer: SLSQP NPSOL-enabled?: No OpenMP-enabled?: No You can update OpenMx with: install.OpenMx(c("NPSOL", "travis", "CRAN", "open travis build page") [1] ‘2.20.6’ > > > > 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)) Model 1 is the best fitting model according to AIC. AIC weight-based conditional probabilities {Wagenmakers, 2004, 192-196} of being the best model are (for each model you gave me): '0.72' and '0.28' Using MuMIn::Weights(AIC()). > > > > 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) [1] "0.052" > umx_APA_pval(1.23E-3) [1] "0.001" > umx_APA_pval(1.23E-4) [1] "< 0.001" > umx_APA_pval(c(1.23E-3, .5)) [1] "0.001" "0.500" > umx_APA_pval(c(1.23E-3, .5), addComparison = TRUE) [1] "= 0.001" "= 0.500" > > > > 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) cyl mpg 1 4 26.66364 2 6 19.74286 3 8 15.10000 > umx_aggregate(mpg ~ cyl, data = mtcars) |cyl |mpg | |:----------|:------------| |4 (n = 11) |26.66 (4.51) | |6 (n = 7) |19.74 (1.45) | |8 (n = 14) |15.1 (2.56) | > > # ============================================= > # = Use different (or user-defined) functions = > # ============================================= > umx_aggregate(mpg ~ cyl, data = mtcars, what = "n") |cyl | mpg| |:----------|---:| |4 (n = 11) | 11| |6 (n = 7) | 7| |8 (n = 14) | 14| > umx_aggregate(mpg ~ cyl, data = mtcars, what = function(x){sum(!is.na(x))}) |cyl | mpg| |:----------|---:| |4 (n = 11) | 11| |6 (n = 7) | 7| |8 (n = 14) | 14| > > # turn off markdown > umx_aggregate(mpg ~ cyl, data = mtcars, report = "txt") cyl mpg 1 4 (n = 11) 26.66 (4.51) 2 6 (n = 7) 19.74 (1.45) 3 8 (n = 14) 15.1 (2.56) > > # ============================================ > # = More than one item on the left hand side = > # ============================================ > umx_aggregate(cbind(mpg, qsec) ~ cyl, data = mtcars, digits = 3) |cyl |mpg |qsec | |:----------|:--------------|:--------------| |4 (n = 11) |26.664 (4.51) |19.137 (1.682) | |6 (n = 7) |19.743 (1.454) |17.977 (1.707) | |8 (n = 14) |15.1 (2.56) |16.772 (1.196) | > # Transpose table > t(umx_aggregate(cbind(mpg, qsec) ~ cyl, data = mtcars)) |cyl |mpg |qsec | |:----------|:------------|:------------| |4 (n = 11) |26.66 (4.51) |19.14 (1.68) | |6 (n = 7) |19.74 (1.45) |17.98 (1.71) | |8 (n = 14) |15.1 (2.56) |16.77 (1.2) | > > ## 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") mpg cyl disp hp drat wt qsec 20.090625 6.187500 230.721875 146.687500 3.596563 3.217250 17.848750 vs am gear carb 0.437500 0.406250 3.687500 2.812500 > umx_apply("mean", of = mtcars, by = "columns") mpg cyl disp hp drat wt qsec 20.090625 6.187500 230.721875 146.687500 3.596563 3.217250 17.848750 vs am gear carb 0.437500 0.406250 3.687500 2.812500 > tmp = mtcars[1:3,]; tmp[1,1] = NA > umx_apply("mean", by = "rows", of = tmp) Mazda RX4 Mazda RX4 Wag Datsun 710 NA 29.98136 23.59818 > umx_apply("mean", by = "rows", of = tmp, na.rm = TRUE) Mazda RX4 Mazda RX4 Wag Datsun 710 30.79800 29.98136 23.59818 > > > > 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" [1] "Alice" > x # now only 2 items (altered in containing environment) [1] "Bob" "Carol" > > > > 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 'data.frame': 32 obs. of 11 variables: $ mpg : chr "21" "21" "22.8" "21.4" ... $ cyl : Factor w/ 3 levels "4","6","8": 2 2 1 2 3 2 3 1 1 2 ... $ disp: num 160 160 108 258 360 ... $ hp : num 110 110 93 110 175 105 245 62 95 123 ... $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ... $ wt : num 2.62 2.88 2.32 3.21 3.44 ... $ qsec: num 16.5 17 18.6 19.4 17 ... $ vs : num 0 0 1 1 0 1 0 1 1 1 ... $ am : logi TRUE TRUE TRUE FALSE FALSE FALSE ... $ gear: num 4 4 4 3 3 3 3 4 4 4 ... $ carb: num 4 4 1 1 2 1 4 2 2 4 ... > df = umx_as_numeric(df, force=TRUE); str(df) # mpg coerced back to numeric 'data.frame': 32 obs. of 11 variables: $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... $ cyl : num 2 2 1 2 3 2 3 1 1 2 ... $ disp: num 160 160 108 258 360 ... $ hp : num 110 110 93 110 175 105 245 62 95 123 ... $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ... $ wt : num 2.62 2.88 2.32 3.21 3.44 ... $ qsec: num 16.5 17 18.6 19.4 17 ... $ vs : num 0 0 1 1 0 1 0 1 1 1 ... $ am : num 1 1 1 0 0 0 0 0 0 0 ... $ gear: num 4 4 4 3 3 3 3 4 4 4 ... $ carb: num 4 4 1 1 2 1 4 2 2 4 ... > ## 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") [1] TRUE > umx_check(1==2, "message", "one must be 2", ". Another comment", "and another") Polite message: one must be 2. Another comment and another [1] FALSE > > > > 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() [1] TRUE > > > > 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) [1] TRUE > umx_check_names(c("x1", "x2"), as.matrix(demoOneFactor)) [1] TRUE > umx_check_names(c("x1", "x2"), cov(demoOneFactor[, c("x1","x2")])) [1] TRUE > umx_check_names(c("x1", "x2"), mxData(demoOneFactor, type="raw")) [1] TRUE > umx_check_names(c("z1", "x2"), data = demoOneFactor, die = FALSE) [1] FALSE > umx_check_names(c("x1", "x2"), data = demoOneFactor, die = FALSE, no_others = TRUE) [1] FALSE > umx_check_names(c("x1","x2","x3","x4","x5"), data = demoOneFactor, die = FALSE, no_others = TRUE) [1] TRUE > # no request > umx_check_names(c(), data = demoOneFactor, die = FALSE, no_others = TRUE) [1] 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) Scores ranged from -3.00804859892048 to 3.81027668071067. Cuts made at '-Inf', '-1.34217601700158', '-0.883178032975253', '-0.511075077137956', '-0.296312753743945', '-0.0353242254668938', '0.24525608131311', '0.536652554171549', '0.855571864288095', '1.32416538358879', and 'Inf' > x = data.frame(x) > str(x); levels(x) 'data.frame': 1000 obs. of 1 variable: $ x: Ord.factor w/ 10 levels "quantile1"<"quantile2"<..: 3 6 3 10 7 3 7 8 8 4 ... ..- attr(*, "mxFactor")= logi TRUE NULL > table(x) x quantile1 quantile2 quantile3 quantile4 quantile5 quantile6 quantile7 100 100 100 100 100 100 100 quantile8 quantile9 quantile10 100 100 100 > ## 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")]) 'data.frame': 3808 obs. of 2 variables: $ wt1: Ord.factor w/ 10 levels "quantile1"<"quantile2"<..: 4 2 3 6 1 5 6 1 5 9 ... ..- attr(*, "mxFactor")= logi TRUE $ wt2: Ord.factor w/ 10 levels "quantile1"<"quantile2"<..: 3 2 1 9 1 5 6 1 3 6 ... ..- attr(*, "mxFactor")= logi TRUE > > # 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) TODO: umx_cor assumes no missing data, n is just nrow() !! lower tri = correlation; upper tri = p-value x1 x2 x3 x4 x5 x6 y1 y2 x1 NA 0.02 0.01 0.05 0.01 0.01 0.01 0.02 x2 0.78 NA 0.04 0.02 0.02 0.02 0.09 0.10 x3 0.83 0.74 NA 0.22 0.01 0.02 0.03 0.01 x4 0.71 0.79 0.49 NA 0.03 0.03 0.25 0.11 x5 0.85 0.80 0.83 0.75 NA 0.00 0.01 0.00 x6 0.85 0.79 0.80 0.74 0.96 NA 0.00 0.02 y1 0.87 0.64 0.76 0.46 0.84 0.88 NA 0.06 y2 0.81 0.63 0.85 0.61 0.87 0.77 0.69 NA > tmp$x1 = letters[1:8] # make one column non-numeric > umx_cor(tmp) TODO: umx_cor assumes no missing data, n is just nrow() !! dropped 1 non-numeric column(s). lower tri = correlation; upper tri = p-value x2 x3 x4 x5 x6 y1 y2 x2 NA 0.04 0.02 0.02 0.02 0.09 0.10 x3 0.74 NA 0.22 0.01 0.02 0.03 0.01 x4 0.79 0.49 NA 0.03 0.03 0.25 0.11 x5 0.80 0.83 0.75 NA 0.00 0.01 0.00 x6 0.79 0.80 0.74 0.96 NA 0.00 0.02 y1 0.64 0.76 0.46 0.84 0.88 NA 0.06 y2 0.63 0.85 0.61 0.87 0.77 0.69 NA > > > > 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" [1] "d" "o" "g" > umx_explode(" ", "cats and dogs") # [1] "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 | |mpg |cyl |disp | |:---------|:------------|:-----------|:---------------| |mpg |1 (0) | | | |cyl |-0.85 (0.05) |1 (0) | | |disp |-0.85 (0.05) |0.9 (0.03) |1 (0) | |Mean (SD) |20.09 (6.03) |6.19 (1.79) |230.72 (123.94) | > > > > 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() Current plot format is 'TRUE' Use TRUE to turn on, FALSE to turn off. Current format is 'DiagrammeR'. Valid options are 'DiagrammeR', 'pdf', 'png', 'svg', or 'graphviz'. TRUE toggles between DiagrammeR and graphviz Current format is'gv'. Valid options are 'gv' or 'dot'. Use TRUE to toggle Currently option to use hrbrthemes for plots is'FALSE'. Valid options are TRUE or FALSE Current format is'markdown'. Valid options are 'latex', 'html', 'pipe', 'simple', 'markdown', and 'rst' Current Optimizer is: 'SLSQP'. Options are: 'CSOLNP' and 'SLSQP' Current auto-run setting is 'TRUE'. Valid options are TRUE or FALSE. mxCondenseMatrixSlots is currently: 'FALSE' 2 cores will be used > > > > 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) [1] "hp" > umx_grep(c("hp", "ph"), "hp") [1] "hp" > umx_grep(mtcars, "^h.*", output="both", ignore.case= TRUE) [1] "hp" > ## 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]") [1] TRUE > umx_has_square_brackets("goodbye") [1] FALSE > > > > 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) [1] FALSE > umx_is_MxData(mxData(mtcars, type= "raw")) [1] TRUE > umx_is_MxData(mxData(cov(mtcars), type= "cov", numObs = 73)) [1] TRUE > umx_is_MxData(mxDataWLS(na.omit(twinData[, c("wt1", "wt2")]), type= "WLS")) [1] TRUE > > > > 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!") + } 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!") + } nice OpenMx model! > if(umx_is_MxModel(list(m1,m1), listOK = TRUE)){ + message("nice list of OpenMx models!") + } 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 [1] "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" [8] "numeric" "numeric" "numeric" "numeric" > # Are the variables in mtcars type character? > umx_is_class(mtcars, "character") # FALSE [1] FALSE > # They're all numeric data > umx_is_class(mtcars, "numeric") # TRUE [1] TRUE > # Show the test-result for each variable in mtcars > umx_is_class(mtcars, "numeric") # TRUE [1] TRUE > # Are they _either_ a char OR a num? > umx_is_class(mtcars, c("character", "numeric")) [1] TRUE > # Is zygosity a factor (note we don't drop = F to keep as dataframe) > umx_is_class(twinData[,"zygosity", drop=FALSE], classes = "factor") [1] TRUE > umx_is_class(mtcars$mpg) # report class of this column (same as class(mpg)) [1] "numeric" > > > > 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) [1] "cov" > df = cor(mtcars) > umx_is_cov(df) [1] "cor" > umx_is_cov(mxData(df[1:3,1:3], type= "cov", numObs = 200)) [1] "cov" > umx_is_cov(df, boolean = TRUE) [1] TRUE > umx_is_cov(mtcars, boolean = TRUE) [1] FALSE > > > > 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 [1] TRUE > umx_is_numeric(mtcars, all=FALSE) # vector of TRUE [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 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 $isFactor [1] TRUE $isOrd [1] FALSE $isBin [1] TRUE $nFactors [1] 1 $nOrdVars [1] 0 $nBinVars [1] 1 $factorVarNames [1] "x" $ordVarNames character(0) $binVarNames [1] "x" $contVarNames character(0) > tmp = mtcars > > tmp$cyl = ordered(mtcars$cyl) # ordered factor > tmp$vs = ordered(mtcars$vs) # binary factor > umx_is_ordered(tmp) # true/false [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE > umx_is_ordered(tmp, strict=FALSE) [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE > umx_is_ordered(tmp, names = TRUE) [1] "cyl" "vs" > umx_is_ordered(tmp, names = TRUE, binary.only = TRUE) [1] "vs" > umx_is_ordered(tmp, names = TRUE, ordinal.only = TRUE) [1] "cyl" > umx_is_ordered(tmp, names = TRUE, continuous.only = TRUE) [1] "mpg" "disp" "hp" "drat" "wt" "qsec" "am" "gear" "carb" > umx_is_ordered(tmp, continuous.only = TRUE) [1] TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE 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) [1] 4 7 8 > # 4,7,8 > umx_lower.tri(x, diag=TRUE) # 1 4 7 5 8 9 [1] 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) [1] TRUE > > # 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) [1] TRUE > > # 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) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1.0000 0.6247 0.3269 0.4216 0.2137 0.4105 0.3240 0.2930 0.2995 0.0760 [2,] 0.6247 1.0000 0.3669 0.3275 0.2742 0.4043 0.4047 0.2407 0.2863 0.0702 [3,] 0.3269 0.3669 1.0000 0.6404 0.1124 0.2903 0.3054 0.4105 0.5191 0.2784 [4,] 0.4216 0.3275 0.6404 1.0000 0.0839 0.2598 0.2786 0.3607 0.5007 0.1988 [5,] 0.2137 0.2742 0.1124 0.0839 1.0000 0.1839 0.0489 0.0186 0.0782 0.1147 [6,] 0.4105 0.4043 0.2903 0.2598 0.1839 1.0000 0.2220 0.1861 0.3355 0.1021 [7,] 0.3240 0.4047 0.3054 0.2786 0.0489 0.2220 1.0000 0.2707 0.2302 0.0931 [8,] 0.2930 0.2407 0.4105 0.3607 0.0186 0.1861 0.2707 1.0000 0.2950 -0.0438 [9,] 0.2995 0.2863 0.5191 0.5007 0.0782 0.3355 0.2302 0.2950 1.0000 0.2087 [10,] 0.0760 0.0702 0.2784 0.1988 0.1147 0.1021 0.0931 -0.0438 0.2087 1.0000 > > # 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) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 0.6247 0.3269 0.3669 0.4216 0.3275 0.6404 0.2137 0.2742 0.1124 [2,] 0.3269 0.0839 0.4105 0.4043 0.2903 0.2598 0.1839 0.3240 0.4047 [3,] 0.3669 0.4105 0.3054 0.2786 0.0489 0.2220 0.2930 0.2407 0.4105 [4,] 0.4216 0.4043 0.2786 0.3607 0.0186 0.1861 0.2707 0.2995 0.2863 [5,] 0.3275 0.2903 0.0489 0.0186 0.5191 0.5007 0.0782 0.3355 0.2302 [6,] 0.6404 0.2598 0.2220 0.1861 0.5007 0.2950 0.0760 0.0702 0.2784 [7,] 0.2137 0.1839 0.2930 0.2707 0.0782 0.0760 0.1988 0.1147 0.1021 [8,] 0.2742 0.3240 0.2407 0.2995 0.3355 0.0702 0.1147 0.0931 -0.0438 [9,] 0.1124 0.4047 0.4105 0.2863 0.2302 0.2784 0.1021 -0.0438 0.2087 > > > > > 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) 'data.frame': 10000 obs. of 4 variables: $ X : num -1.404 -0.131 -1.309 1.372 0.787 ... $ Y : num -1.048 -0.392 -0.223 1.308 0.709 ... $ U : num -0.494 1.128 -1.147 1.481 0.916 ... $ qtl: num 1 0 1 0 0 1 2 0 2 1 ... > ## 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) AA CC DD EE 0.3 0.0 0.0 0.7 a c d e 0.55 0.00 0.00 0.84 > # Show dataframe with 20,000 rows and 3 variables: var_T1, var_T2, and zygosity > str(tmp) 'data.frame': 20000 obs. of 3 variables: $ var_T1 : num -0.0292 0.7731 -0.0612 1.9875 0.5617 ... $ var_T2 : num -0.9809 -0.477 -1.2863 0.5848 -0.0304 ... $ zygosity: Factor w/ 2 levels "MZ","DZ": 1 1 1 1 1 1 1 1 1 1 ... > > # =============================== > # = How to consume the datasets = > # =============================== > > mzData = tmp[tmp$zygosity == "MZ", ] > dzData = tmp[tmp$zygosity == "DZ", ] > str(mzData); str(dzData); 'data.frame': 10000 obs. of 3 variables: $ var_T1 : num -0.0292 0.7731 -0.0612 1.9875 0.5617 ... $ var_T2 : num -0.9809 -0.477 -1.2863 0.5848 -0.0304 ... $ zygosity: Factor w/ 2 levels "MZ","DZ": 1 1 1 1 1 1 1 1 1 1 ... 'data.frame': 10000 obs. of 3 variables: $ var_T1 : num -0.224 -0.397 -0.208 -1.272 1.134 ... $ var_T2 : num 0.581 0.768 -0.766 -1.663 0.441 ... $ zygosity: Factor w/ 2 levels "MZ","DZ": 2 2 2 2 2 2 2 2 2 2 ... > cov(mzData[, c("var_T1", "var_T2")]) var_T1 var_T2 var_T1 1.0051009 0.3225885 var_T2 0.3225885 1.0143726 > cov(dzData[, c("var_T1", "var_T2")]) var_T1 var_T2 var_T1 1.0245903 0.1600554 var_T2 0.1600554 0.9908650 > umxAPA(mzData[, c("var_T1", "var_T2")]) | |var_T1 |var_T2 | |:---------|:-----------|:------------| |var_T1 |1 (0) | | |var_T2 |0.32 (0.01) |1 (0) | |Mean (SD) |0 (1) |-0.01 (1.01) | > > # Prefer to work in path coefficient values? (little a?) > tmp = umx_make_TwinData(2000, AA = .7^2, CC = .0) AA CC DD EE 0.49 0.00 0.00 0.51 a c d e 0.70 0.00 0.00 0.71 > mzData = tmp[tmp$zygosity == "MZ", ] > dzData = tmp[tmp$zygosity == "DZ", ] > m1 = umxACE(selDVs="var", sep="_T", mzData= mzData, dzData= dzData) Running ACE with 4 parameters ACE -2 × log(Likelihood) = 22296.864 Table: Standardized parameter estimates from a 1-factor Cholesky ACE model. A: additive genetic; C: common environment; E: unique environment. | | a1| c1| e1| |:---|-----:|-----:|----:| |var | 0.644| 0.259| 0.72| Table: Means (from model$top$expMean) | | var_T1| var_T2| |:---------|------:|------:| |intercept | -0.02| -0.02| ?umxPlotACE options: std=T/F, means=T/F, digits=n, strip_zero=T/F, file=, min=, max = > > # Examine correlations > cor(mzData[,c("var_T1","var_T2")]) var_T1 var_T2 var_T1 1.0000000 0.4757047 var_T2 0.4757047 1.0000000 > cor(dzData[,c("var_T1","var_T2")]) var_T1 var_T2 var_T1 1.0000000 0.2787042 var_T2 0.2787042 1.0000000 > > # Example with D (left un-modeled in ACE) > tmp = umx_make_TwinData(nMZpairs = 500, AA = .4, DD = .2, CC = .2) AA CC DD EE 0.4 0.2 0.2 0.2 a c d e 0.63 0.45 0.45 0.45 > m1 = umxACE(selDVs="var", data = tmp, mzData= "MZ", dzData= "DZ") Running ACE with 4 parameters ACE -2 × log(Likelihood) = 5144.552 Table: Standardized parameter estimates from a 1-factor Cholesky ACE model. A: additive genetic; C: common environment; E: unique environment. | | a1| c1| e1| |:---|-----:|-----:|-----:| |var | 0.811| 0.346| 0.472| Table: Means (from model$top$expMean) | | var_T1| var_T2| |:---------|------:|------:| |intercept | -0.032| -0.032| ?umxPlotACE options: std=T/F, means=T/F, digits=n, strip_zero=T/F, file=, min=, max = > # | | a1| c1| e1| > # |:---|----:|----:|----:| > # |var | 0.86| 0.24| 0.45| > > m1 = umxACE(selDVs="var", data = tmp, mzData= "MZ", dzData= "DZ", dzCr=.25) Running ADE with 4 parameters ADE -2 × log(Likelihood) = 5147.348 Table: Standardized parameter estimates from a 1-factor Cholesky ACE model. A: additive genetic; D: dominance effects; E: unique environment. | | a1|d1 | e1| |:---|-----:|:--|----:| |var | 0.883|. | 0.47| Table: Means (from model$top$expMean) | | var_T1| var_T2| |:---------|------:|------:| |intercept | -0.033| -0.033| ?umxPlotACE options: std=T/F, means=T/F, digits=n, strip_zero=T/F, file=, min=, max = > # | | 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) AA CC DD EE 0.5 0.3 0.0 0.2 a c d e 0.71 0.55 0.00 0.45 > cov(tmp[tmp$zygosity == "DZ", c("var_T1","var_T2")]) var_T1 var_T2 var_T1 1.0490877 0.6471903 var_T2 0.6471903 1.0707104 > > # Not limited to unit variance > tmp = umx_make_TwinData(100, AA = 3, CC = 2, EE = 3, sum2one = FALSE) AA CC DD EE 3 2 0 3 a c d e 1.73 1.41 0.00 1.73 > cov(tmp[tmp$zygosity == "MZ", c("var_T1","var_T2")]) var_T1 var_T2 var_T1 8.097469 4.764774 var_T2 4.764774 7.192760 > > # Output can be scaled (mean=0, std=1) > tmp = umx_make_TwinData(100, AA = .7, CC = .1, scale = TRUE) AA CC DD EE 0.7 0.1 0.0 0.2 a c d e 0.84 0.32 0.00 0.45 > cov(tmp[tmp$zygosity == "MZ", c("var_T1","var_T2")]) var_T1 var_T2 var_T1 1.142008 0.7663580 var_T2 0.766358 0.8534717 > > ## 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) | |v1 |v2 |v3 |v4 |v5 |v6 | |:---------|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------| |v1 |1 (0) | | | | | | |v2 |0.36 (0.09) |1 (0) | | | | | |v3 |0.41 (0.08) |0.75 (0.04) |1 (0) | | | | |v4 |0.64 (0.06) |0.5 (0.08) |0.51 (0.07) |1 (0) | | | |v5 |0.67 (0.06) |0.38 (0.09) |0.44 (0.08) |0.8 (0.04) |1 (0) | | |v6 |0.47 (0.08) |0.67 (0.06) |0.71 (0.05) |0.47 (0.08) |0.43 (0.08) |1 (0) | |Mean (SD) |0.93 (0.91) |1.96 (0.54) |2.92 (0.9) |3.86 (1.28) |4.83 (1.24) |5.95 (1.12) | > covMat = matrix(c(1, .3, .3, 1), nrow=2) > tmp= umx_make_raw_from_cov(covMat, n=10, varNames= c("x", "y")) > cov(tmp) x y x 1.2320783 0.2547967 y 0.2547967 1.2597837 > tmp= umx_make_raw_from_cov(covMat, n=10, varNames= c("x", "y"), empirical= TRUE) > cov(tmp) x y x 1.0 0.3 y 0.3 1.0 > tmp= umx_make_raw_from_cov(qm(1, .3| .3, 1), n=10, varNames= c("x", "y")) > cov(tmp) x y x 0.8789356 0.1278233 y 0.1278233 1.8444490 > > > > 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") [1] "zyg" "zygosity" > levels(tmp$zygosity) [1] "MZFF" "MZMM" "DZFF" "DZMM" "DZOS" > > > > > 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) [1] 20.09062 0.00000 230.72188 0.00000 > > > > 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) a = brian > b = c("brian", "sally", "jane") > umx_msg(b) b = 'brian', 'sally', and 'jane' > umx_msg(mtcars) mtcars = 'data.frame': 32 obs. of 11 variables: $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... $ cyl : num 6 6 4 6 8 6 8 4 4 6 ... $ disp: num 160 160 108 258 360 ... $ hp : num 110 110 93 110 175 105 245 62 95 123 ... $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ... $ wt : num 2.62 2.88 2.32 3.21 3.44 ... $ qsec: num 16.5 17 18.6 19.4 17 ... $ vs : num 0 0 1 1 0 1 0 1 1 1 ... $ am : num 1 1 1 0 0 0 0 0 0 0 ... $ gear: num 4 4 4 3 3 3 3 4 4 4 ... $ carb: num 4 4 1 1 2 1 4 2 2 4 ... > > > > 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 [1] "mpg" > > # Easy-to-type alias "namez" > namez(mtcars, "mpg") [1] "mpg" > > # Use a regular expression to match a pattern > namez(mtcars, "r[ab]") # "drat", "carb" [1] "drat" "carb" > namez(mtcars, "^d") # vars beginning with 'd' = "disp", drat [1] "disp" "drat" > > # Use this function to replace text in names! > umx_names(mtcars, "mpg", replacement = "hello") # "mpg" replaced with "hello" [1] "hello" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" [10] "gear" "carb" > > > # ======================================================================== > # = 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 [1] "c('mpg', 'am')" > > # Other options passed to R's grep command > umx_names(mtcars, "mpg" , invert = TRUE) # Non-matches (instead of matches) [1] "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb" > umx_names(mtcars, "disp", value = FALSE) # Return indices of matches [1] 3 > umx_names(mtcars, "^d" , fixed = TRUE) # Vars containing literal '^d' (none...) character(0) > > # ======================================= > # = Examples using built-in GFF dataset = > # ======================================= > > # Just show phenotypes for Twin 1 > umx_names(GFF, "_T1$") # twin 1 [1] "sex_T1" "age_T1" "gff_T1" "fc_T1" "qol_T1" "hap_T1" "sat_T1" [8] "AD_T1" "SOMA_T1" "SOC_T1" "THOU_T1" > # "zyg" "sex1" "age_T1" "gff_T1" "fc_T1" "qol_T1" "hap_T1"... > > umx_names(GFF, "2$") # names ending in 2 [1] "sex_T2" "age_T2" "gff_T2" "fc_T2" "qol_T2" "hap_T2" "sat_T2" [8] "AD_T2" "SOMA_T2" "SOC_T2" "THOU_T2" > umx_names(GFF, "[^12bs]$") # doesn't end in `1`, `2`, `b`, or `s` [1] "zyg_6grp" "zyg_2grp" "divorce" > # "zyg_6grp" "zyg_2grp" "divorce" > umx_names(mxData(twinData[, c("wt1", "wt2")], type= "raw")) [1] "wt1" "wt2" > umx_names(mxData(cov(twinData[, c("wt1", "wt2")], use="comp"), type= "cov", numObs= 1000)) [1] "wt1" "wt2" > umx_names(mxDataWLS(na.omit(twinData[, c("wt1", "wt2")]), type= "WLS")) [1] "wt1" "wt2" > > namez(umxMatrix("bob", "Full", 3,3)$labels) [1] "bob_r1c1" "bob_r2c1" "bob_r3c1" "bob_r1c2" "bob_r2c2" "bob_r3c2" "bob_r1c3" [8] "bob_r2c3" "bob_r3c3" > > > > > 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) [1] 1 2 3 NA > umx_pad(1:3, 3) [1] 1 2 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")) [1] "bmi_T1" "bmi_T2" > umx_paste_names("bmi", sep = "_T", suffixes = 1:2) [1] "bmi_T1" "bmi_T2" > 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) [1] "IQ_T1" "C_T1" "IQ_T2" "C_T2" "age_T1" "age_T2" > umx_paste_names(c("IQ", "C"), cov = c("age"), sep = "_T", prefix= "mean_") [1] "mean_IQ_T1" "mean_C_T1" "mean_IQ_T2" "mean_C_T2" "mean_age_T1" [6] "mean_age_T2" > # For quick-typing, tvars is an alias for umx_paste_names > tvars(c("IQ", "C"), cov = "age", sep = "_T", prefix= "mean_") [1] "mean_IQ_T1" "mean_C_T1" "mean_IQ_T2" "mean_C_T2" "mean_age_T1" [6] "mean_age_T2" > tvars("IQ") [1] "IQ1" "IQ2" > > > > 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") 1 hp mpgRunning model with 5 parameters Beginning initial fit attempt Running model with 5 parameters Lowest minimum so far: 150.075328336548 Solution found Solution found! Final fit=150.07533 (started at 179.62413) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: -0.776168373745124,0,0,0.984250986987651,0.984250987534811 Running model with 5 parameters 2 hp amRunning model with 4 parameters Beginning initial fit attempt Running model with 4 parameters Lowest minimum so far: 131.142462276822 Solution found Solution found! Final fit=131.14246 (started at 144.08932) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: -0.297796000379108,-0.00128537764265813,0.984296264399916,0.230376681278412 Running model with 4 parameters 3 hp vsRunning model with 4 parameters Beginning initial fit attempt Running model with 4 parameters Lowest minimum so far: 107.371862051928 Solution found Solution found! Final fit=107.37186 (started at 142.47539) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: -0.995628257562367,0.171376098005784,0.963255681972712,0.417126504410266 Running model with 4 parameters 4 mpg amRunning model with 4 parameters Beginning initial fit attempt Running model with 4 parameters Lowest minimum so far: 119.326996614238 Solution found Solution found! Final fit=119.327 (started at 144.08932) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: 0.739605326276199,0.0318257096435269,0.986760263563837,0.168613719944492 Running model with 4 parameters 5 mpg vsRunning model with 4 parameters Beginning initial fit attempt Running model with 4 parameters Lowest minimum so far: 115.395487688581 Solution found Solution found! Final fit=115.39549 (started at 142.47539) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: 0.827852485908209,0.0367899768994823,0.986255611784731,0.086351939761419 Running model with 4 parameters 6 am vsRunning model with 3 parameters Beginning initial fit attempt Running model with 3 parameters Lowest minimum so far: 86.1827403799855 Solution found Solution found! Final fit=86.18274 (started at 106.94058) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: 0.264080932862892,0.237202159512479,0.157310683112822 Running model with 3 parameters > x$R hp mpg am vs hp 1.0000000 -0.7519131 -0.2931195 -0.9590446 mpg -0.7519131 1.0000000 0.7298131 0.8164743 am -0.2931195 0.7298131 1.0000000 0.2640808 vs -0.9590446 0.8164743 0.2640808 1.0000000 > cov2cor(x$R) hp mpg am vs hp 1.0000000 -0.7519131 -0.2931195 -0.9590446 mpg -0.7519131 1.0000000 0.7298131 0.8164743 am -0.2931195 0.7298131 1.0000000 0.2640808 vs -0.9590446 0.8164743 0.2640808 1.0000000 > cor(mtcars[, c("hp", "mpg", "am", "vs")]) hp mpg am vs hp 1.0000000 -0.7761684 -0.2432043 -0.7230967 mpg -0.7761684 1.0000000 0.5998324 0.6640389 am -0.2432043 0.5998324 1.0000000 0.1683451 vs -0.7230967 0.6640389 0.1683451 1.0000000 > > > > 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") 1 hp mpgRunning model with 5 parameters Beginning initial fit attempt Running model with 5 parameters Lowest minimum so far: 150.075328336548 Solution found Solution found! Final fit=150.07533 (started at 179.62413) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: -0.776168373745124,0,0,0.984250986987651,0.984250987534811 Running model with 5 parameters 2 hp amRunning model with 4 parameters Beginning initial fit attempt Running model with 4 parameters Lowest minimum so far: 131.142462276822 Solution found Solution found! Final fit=131.14246 (started at 144.08932) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: -0.297796000379108,-0.00128537764265813,0.984296264399916,0.230376681278412 Running model with 4 parameters 3 hp vsRunning model with 4 parameters Beginning initial fit attempt Running model with 4 parameters Lowest minimum so far: 107.371862051928 Solution found Solution found! Final fit=107.37186 (started at 142.47539) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: -0.995628257562367,0.171376098005784,0.963255681972712,0.417126504410266 Running model with 4 parameters 4 mpg amRunning model with 4 parameters Beginning initial fit attempt Running model with 4 parameters Lowest minimum so far: 119.326996614238 Solution found Solution found! Final fit=119.327 (started at 144.08932) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: 0.739605326276199,0.0318257096435269,0.986760263563837,0.168613719944492 Running model with 4 parameters 5 mpg vsRunning model with 4 parameters Beginning initial fit attempt Running model with 4 parameters Lowest minimum so far: 115.395487688581 Solution found Solution found! Final fit=115.39549 (started at 142.47539) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: 0.827852485908209,0.0367899768994823,0.986255611784731,0.086351939761419 Running model with 4 parameters 6 am vsRunning model with 3 parameters Beginning initial fit attempt Running model with 3 parameters Lowest minimum so far: 86.1827403799855 Solution found Solution found! Final fit=86.18274 (started at 106.94058) (1 attempt(s): 1 valid, 0 errors) Start values from best fit: 0.264080932862892,0.237202159512479,0.157310683112822 Running model with 3 parameters > x$R hp mpg am vs hp 1.0000000 -0.7519131 -0.2931195 -0.9590446 mpg -0.7519131 1.0000000 0.7298131 0.8164743 am -0.2931195 0.7298131 1.0000000 0.2640808 vs -0.9590446 0.8164743 0.2640808 1.0000000 > cor(mtcars[, c("hp", "mpg", "am", "vs")]) hp mpg am vs hp 1.0000000 -0.7761684 -0.2432043 -0.7230967 mpg -0.7761684 1.0000000 0.5998324 0.6640389 am -0.2432043 0.5998324 1.0000000 0.1683451 vs -0.7230967 0.6640389 0.1683451 1.0000000 > > > > > 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") | | mpg| cyl| disp| hp| drat| wt| qsec|vs |am | gear| carb| |:-----------------|----:|---:|-----:|---:|----:|----:|-----:|:--|:--|----:|----:| |Mazda RX4 | 21.0| 6| 160.0| 110| 3.90| 2.62| 16.46|. |1 | 4| 4| |Mazda RX4 Wag | 21.0| 6| 160.0| 110| 3.90| 2.88| 17.02|. |1 | 4| 4| |Datsun 710 | 22.8| 4| 108.0| 93| 3.85| 2.32| 18.61|1 |1 | 4| 1| |Hornet 4 Drive | 21.4| 6| 258.0| 110| 3.08| 3.21| 19.44|1 |. | 3| 1| |Hornet Sportabout | 18.7| 8| 360.0| 175| 3.15| 3.44| 17.02|. |. | 3| 2| |Valiant | 18.1| 6| 225.0| 105| 2.76| 3.46| 20.22|1 |. | 3| 1| |Duster 360 | 14.3| 8| 360.0| 245| 3.21| 3.57| 15.84|. |. | 3| 4| |Merc 240D | 24.4| 4| 146.7| 62| 3.69| 3.19| 20.00|1 |. | 4| 2| |Merc 230 | 22.8| 4| 140.8| 95| 3.92| 3.15| 22.90|1 |. | 4| 2| |Merc 280 | 19.2| 6| 167.6| 123| 3.92| 3.44| 18.30|1 |. | 4| 4| > umx_print(mtcars[1,1:2], digits = 2, zero.print = "") | | mpg| cyl| |:---------|---:|---:| |Mazda RX4 | 21| 6| > umx_print(mtcars[1,1:2], digits = 2, caption = "Hi: I'm the caption!") Table: Hi: I'm the caption! | | mpg| cyl| |:---------|---:|---:| |Mazda RX4 | 21| 6| > ## 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) Results of a comparison of two nonoverlapping correlations based on dependent groups Comparison between r.jk = -0.8522 and r.hm = 0.7909 Difference: r.jk - r.hm = -1.6431 Related correlations: r.jh = -0.8476, r.jm = -0.7762, r.kh = 0.902, r.km = 0.8324 Group size: n = 32 Null hypothesis: r.jk is equal to r.hm Alternative hypothesis: r.jk is not equal to r.hm (two-sided) Alpha: 0.05 silver2004: Silver, Hittner, and May's (2004) modification of Dunn and Clark's z (1969) using a backtransformed average Fisher's (1921) Z procedure z = -5.7246, p-value = 0.0000 Null hypothesis rejected > umx_r_test(mtcars, c("mpg", "disp", "hp")) Results of a comparison of two overlapping correlations based on dependent groups Comparison between r.jk = -0.8476 and r.jh = -0.7762 Difference: r.jk - r.jh = -0.0714 Related correlation: r.kh = 0.7909 Group size: n = 32 Null hypothesis: r.jk is equal to r.jh Alternative hypothesis: r.jk is not equal to r.jh (two-sided) Alpha: 0.05 hittner2003: Hittner, May, and Silver's (2003) modification of Dunn and Clark's z (1969) using a backtransformed average Fisher's (1921) Z procedure z = -1.1474, p-value = 0.2512 Null hypothesis retained > > > > 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") [1] "cylinder" "qsec" "carb" > > # Alternate style: from->to, first with a test-run > # Dry run > tmp = umx_rename(tmp, from = "disp", to = "displacement", test= TRUE) The following changes would be made (set test =FALSE to actually make them Names to be replaced [1] "disp" replacement names: [1] "displacement" > # Actually do it > tmp = umx_rename(tmp, from = c("disp"), to = c("displacement")) > umx_check_names("displacement", data = tmp, die = TRUE) [1] TRUE > namez(tmp, "disp") [1] "displacement" > > # 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) Warning in umx_rename(tmp, from = c("am", "disp", "drat"), to = new) : The following names did not appear in the dataframe:disp Perhaps you already updated them > namez(tmp, "a") # still updated am to auto (and rear_axle_ratio) [1] "displacement" "rear_axle_ratio" "auto" "gear" [5] "carb" > > # Test using regex (in this case to revert "displacement" to "disp") > tmp = umx_rename(tmp, regex = "lacement", to = "", test= TRUE) The following changes would be made (set test =FALSE to actually make them) 11 names found. 1 would be changed. Old: [1] "displacement" New: [1] "disp" > tmp = umx_rename(tmp, regex = "lacement", to = "") # revert to disp > umx_names(tmp, "^d") # all names beginning with a d [1] "disp" > > # dev: check deprecated format handled... > tmp = umx_rename(tmp, old = c("am", "disp", "drat"), replace = new) Polite message: Please use 'from' instead of 'old' in umx_rename() Polite message: Please use 'to' instead of 'replace' in umx_rename() Warning in umx_rename(tmp, old = c("am", "disp", "drat"), replace = new) : The following names did not appear in the dataframe:am, drat Perhaps you already updated them > > > > 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 mpg cyl disp mpg 36.324103 -9.172379 -633.0972 cyl -9.172379 3.189516 199.6603 disp -633.097208 199.660282 15360.7998 > umx_reorder(oldMatrix, newOrder = c("hp", "disp", "cyl")) # subset and reordered hp disp cyl hp 4700.8669 6721.1587 101.931452 disp 6721.1587 15360.7998 199.660282 cyl 101.9315 199.6603 3.189516 > umx_reorder(oldMatrix, "hp") # edge-case of just 1-var hp hp 4700.867 > > > > 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) (Intercept) B = 34.661 [29.452, 39.87], t = 13.609, p < 0.001 cyl B = -1.587 [-3.043, -0.131], t = -2.23, p = 0.034 disp B = -0.021 [-0.042, 0], t = -2.007, p = 0.054 R² = 0.76 (adj = 0.743)> r2 = residuals(lm(mpg ~ cyl + disp, data = mtcars, na.action = na.exclude)) > all(r1$mpg == r2) [1] TRUE > > # ============================= > # = Use the formula interface = > # ============================= > r1 = umx_residualize(mpg ~ cyl + I(cyl^2) + disp, data = mtcars) (Intercept) B = 53.445 [31.077, 75.814], t = 4.894, p < 0.001 cyl B = -8.367 [-16.359, -0.376], t = -2.145, p = 0.041 I(cyl^2) B = 0.597 [-0.096, 1.291], t = 1.766, p = 0.088 disp B = -0.027 [-0.049, -0.006], t = -2.574, p = 0.016 R² = 0.784 (adj = 0.76)> > # validate against using lm > r2 = residuals(lm(mpg ~ cyl + I(cyl^2) + disp, data = mtcars, na.action = na.exclude)) > all(r1$mpg == r2) [1] TRUE > > # =========================================================== > # = 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) (Intercept) B = 34.661 [31.149, 38.173], t = 19.737, p < 0.001 cyl B = -1.587 [-2.569, -0.606], t = -3.234, p = 0.002 disp B = -0.021 [-0.035, -0.006], t = -2.91, p = 0.005 R² = 0.76 (adj = 0.752)> str(tmp[1:5, 12:17]) 'data.frame': 5 obs. of 6 variables: $ mpg_T2 : num -0.844 -0.844 -3.289 1.573 4.147 $ mpg_T1 : num -0.844 -0.844 -3.289 1.573 4.147 $ cyl_T2 : num 6 6 4 6 8 $ cyl_T1 : num 6 6 4 6 8 $ disp_T2: num 160 160 108 258 360 $ disp_T1: num 160 160 108 258 360 > > # =================================== > # = Residualize several DVs at once = > # =================================== > df1 = umx_residualize(c("mpg", "hp"), cov = c("cyl", "disp"), data = tmp) (Intercept) B = 34.661 [29.452, 39.87], t = 13.609, p < 0.001 cyl B = -1.587 [-3.043, -0.131], t = -2.23, p = 0.034 disp B = -0.021 [-0.042, 0], t = -2.007, p = 0.054 R² = 0.76 (adj = 0.743)(Intercept) B = -32.432 [-98.452, 33.589], t = -1.005, p = 0.323 cyl B = 24.515 [6.063, 42.966], t = 2.717, p = 0.011 disp B = 0.119 [-0.147, 0.385], t = 0.915, p = 0.368 R² = 0.702 (adj = 0.681)> df2 = residuals(lm(hp ~ cyl + disp, data = tmp, na.action = na.exclude)) > all(df1$hp == df2) [1] TRUE > > > > 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) [1] 2 3 4 5 6 7 8 9 10 1 > umx_rot(c(3,4,5,6,7)) [1] 4 5 6 7 3 > # [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)) mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1 > head(umx_round(mtcars, coerce = TRUE)) mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1 > > > > > 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) Attaching package: ‘psych’ The following object is masked from ‘package:umx’: reliability The following object is masked from ‘package:OpenMx’: tr > 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") Polite note: You asked for scale totals, but some subjects have missing data: Perhaps use means?... > tmp[1, namez(tmp, "A",ignore.case = FALSE)] A1 A2 A3 A4 A5 A 61617 2 4 3 4 4 20 > # 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 [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 [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) [1] NA > > # =============== > # = 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 [1] 5 > > # 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] [1] 3.8 > > # 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) Call: psych::scoreItems(keys = list(E = c("-E1", "-E2", "E3", "E4", "E5"), A = c("-A1", "A2", "A3", "A4", "A5")), items = bfi, min = 1, max = 6) Scale intercorrelations corrected for attenuation raw correlations below the diagonal, (unstandardized) alpha on the diagonal corrected correlations above the diagonal: E A E 0.76 0.63 A 0.46 0.70 > scores$scores[1, ] E A 3.8 4.0 > # 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"] [1] FALSE TRUE TRUE TRUE FALSE FALSE TRUE FALSE NA FALSE TRUE TRUE [13] FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [25] TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE [37] TRUE TRUE TRUE FALSE FALSE FALSE FALSE TRUE FALSE TRUE FALSE TRUE [49] FALSE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE [61] TRUE FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE TRUE NA [73] FALSE TRUE FALSE TRUE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE [85] FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE [97] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE [109] FALSE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE FALSE [121] FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE TRUE TRUE TRUE TRUE [133] NA FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE [145] TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE FALSE TRUE [157] TRUE FALSE FALSE FALSE TRUE FALSE TRUE TRUE TRUE FALSE FALSE NA [169] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE FALSE [181] TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE [193] FALSE FALSE FALSE TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE [205] TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE NA TRUE [217] FALSE TRUE FALSE FALSE TRUE FALSE TRUE FALSE TRUE TRUE FALSE FALSE [229] FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE [241] TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [253] FALSE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE FALSE [265] FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE TRUE TRUE FALSE FALSE [277] TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [289] TRUE TRUE TRUE FALSE NA FALSE FALSE TRUE TRUE FALSE FALSE FALSE [301] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE FALSE [313] FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE [325] FALSE TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE FALSE [337] FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE [349] TRUE TRUE TRUE FALSE TRUE FALSE TRUE NA TRUE TRUE TRUE TRUE [361] FALSE FALSE FALSE TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE [373] TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE [385] TRUE FALSE FALSE NA TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE [397] TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE [409] FALSE TRUE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE TRUE [421] TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE [433] TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE FALSE [445] FALSE TRUE FALSE TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE [457] TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE [469] TRUE NA TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE [481] FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE TRUE TRUE TRUE [493] FALSE FALSE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE [505] FALSE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE FALSE TRUE FALSE [517] TRUE FALSE FALSE TRUE TRUE TRUE NA FALSE NA TRUE FALSE FALSE [529] FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE NA TRUE [541] TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE FALSE FALSE [553] TRUE FALSE TRUE TRUE FALSE FALSE FALSE TRUE TRUE FALSE TRUE TRUE [565] FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE FALSE TRUE FALSE FALSE [577] FALSE FALSE FALSE TRUE TRUE FALSE TRUE FALSE TRUE FALSE TRUE TRUE [589] TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE FALSE FALSE TRUE FALSE [601] FALSE TRUE TRUE FALSE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE [613] TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [625] TRUE TRUE NA TRUE FALSE FALSE TRUE FALSE TRUE TRUE FALSE FALSE [637] FALSE FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE TRUE TRUE TRUE [649] TRUE TRUE TRUE FALSE TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE [661] TRUE TRUE TRUE FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE [673] TRUE TRUE TRUE NA TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE [685] FALSE TRUE FALSE TRUE FALSE NA TRUE TRUE TRUE TRUE FALSE TRUE [697] FALSE TRUE FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE FALSE [709] FALSE TRUE TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE [721] FALSE FALSE TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE [733] FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE [745] TRUE FALSE TRUE FALSE TRUE FALSE TRUE TRUE FALSE FALSE FALSE TRUE [757] FALSE NA TRUE FALSE TRUE FALSE TRUE FALSE FALSE FALSE TRUE FALSE [769] TRUE TRUE TRUE TRUE TRUE FALSE NA TRUE FALSE FALSE FALSE TRUE [781] FALSE TRUE TRUE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE [793] FALSE TRUE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE TRUE TRUE [805] FALSE TRUE FALSE FALSE TRUE FALSE TRUE TRUE FALSE FALSE TRUE TRUE [817] TRUE FALSE FALSE TRUE FALSE TRUE TRUE TRUE TRUE FALSE NA FALSE [829] FALSE FALSE TRUE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE [841] TRUE FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE FALSE [853] TRUE NA TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE [865] TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE [877] TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE [889] TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE FALSE TRUE FALSE TRUE [901] NA NA FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE TRUE FALSE [913] TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE [925] TRUE FALSE TRUE FALSE TRUE TRUE FALSE FALSE TRUE TRUE FALSE FALSE [937] NA TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE FALSE FALSE [949] TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE FALSE [961] TRUE TRUE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE FALSE [973] TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE [985] FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE FALSE [997] TRUE FALSE TRUE TRUE NA TRUE TRUE FALSE TRUE TRUE TRUE TRUE [1009] TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE [1021] FALSE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE NA TRUE TRUE [1033] FALSE TRUE TRUE TRUE FALSE TRUE TRUE FALSE FALSE TRUE FALSE TRUE [1045] TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE NA TRUE FALSE [1057] FALSE TRUE TRUE NA TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE [1069] TRUE TRUE TRUE FALSE FALSE TRUE FALSE TRUE TRUE TRUE FALSE TRUE [1081] TRUE TRUE FALSE TRUE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE [1093] TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE FALSE TRUE TRUE TRUE [1105] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE [1117] FALSE TRUE TRUE NA FALSE NA FALSE FALSE TRUE TRUE TRUE TRUE [1129] FALSE FALSE TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE [1141] FALSE TRUE TRUE FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE TRUE [1153] TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE [1165] FALSE FALSE NA TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [1177] FALSE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE FALSE FALSE FALSE [1189] FALSE TRUE FALSE TRUE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE [1201] FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE [1213] FALSE TRUE TRUE FALSE FALSE TRUE TRUE FALSE NA TRUE FALSE TRUE [1225] FALSE FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE TRUE NA [1237] TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE FALSE [1249] FALSE TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE [1261] TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE [1273] FALSE FALSE NA FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE [1285] TRUE TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE TRUE TRUE [1297] FALSE TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE [1309] FALSE TRUE TRUE FALSE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE [1321] TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE [1333] TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [1345] NA TRUE TRUE FALSE TRUE TRUE TRUE FALSE FALSE TRUE NA FALSE [1357] TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [1369] TRUE FALSE FALSE FALSE TRUE TRUE FALSE FALSE TRUE FALSE TRUE FALSE [1381] TRUE FALSE FALSE FALSE TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE [1393] TRUE TRUE TRUE TRUE TRUE NA TRUE TRUE TRUE TRUE TRUE TRUE [1405] TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE [1417] FALSE FALSE FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE [1429] FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE [1441] FALSE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE FALSE FALSE [1453] TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE NA FALSE [1465] TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE NA FALSE TRUE [1477] TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE NA FALSE FALSE [1489] TRUE TRUE FALSE NA TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE [1501] TRUE FALSE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE [1513] TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE NA TRUE [1525] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE [1537] TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE FALSE FALSE TRUE FALSE [1549] FALSE TRUE TRUE FALSE TRUE FALSE FALSE TRUE FALSE TRUE FALSE TRUE [1561] TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE [1573] TRUE FALSE FALSE FALSE TRUE FALSE NA TRUE TRUE TRUE TRUE TRUE [1585] TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE [1597] TRUE TRUE TRUE TRUE NA TRUE TRUE FALSE FALSE NA TRUE TRUE [1609] TRUE FALSE TRUE FALSE TRUE TRUE FALSE FALSE FALSE TRUE FALSE TRUE [1621] TRUE FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE TRUE FALSE [1633] TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE [1645] TRUE FALSE TRUE NA TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE [1657] TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE TRUE NA TRUE [1669] TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE [1681] TRUE TRUE NA FALSE TRUE TRUE FALSE FALSE FALSE TRUE TRUE NA [1693] FALSE FALSE FALSE TRUE TRUE FALSE TRUE FALSE TRUE FALSE FALSE FALSE [1705] TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE [1717] TRUE TRUE FALSE TRUE FALSE TRUE FALSE TRUE TRUE TRUE FALSE FALSE [1729] FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE [1741] TRUE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE [1753] FALSE TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE NA [1765] FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE NA TRUE FALSE [1777] TRUE TRUE TRUE FALSE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE [1789] FALSE FALSE TRUE FALSE FALSE TRUE TRUE FALSE FALSE FALSE TRUE TRUE [1801] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE [1813] TRUE FALSE TRUE NA FALSE NA TRUE FALSE TRUE TRUE TRUE FALSE [1825] FALSE TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE TRUE [1837] FALSE TRUE FALSE TRUE TRUE FALSE TRUE TRUE FALSE FALSE FALSE TRUE [1849] NA FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE TRUE TRUE [1861] TRUE TRUE TRUE NA TRUE TRUE TRUE TRUE TRUE NA TRUE FALSE [1873] TRUE TRUE FALSE NA FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE [1885] FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE [1897] TRUE TRUE FALSE FALSE TRUE NA TRUE TRUE TRUE FALSE TRUE NA [1909] FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE [1921] TRUE NA TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE [1933] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE [1945] TRUE FALSE FALSE TRUE TRUE TRUE FALSE FALSE NA TRUE TRUE TRUE [1957] TRUE FALSE FALSE FALSE TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE [1969] TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE [1981] TRUE TRUE NA TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE [1993] FALSE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE [2005] FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE [2017] TRUE TRUE TRUE FALSE TRUE TRUE FALSE FALSE FALSE FALSE TRUE TRUE [2029] TRUE FALSE NA TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE NA [2041] FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE [2053] TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE FALSE TRUE NA [2065] TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE [2077] TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE TRUE [2089] TRUE FALSE TRUE TRUE FALSE FALSE TRUE FALSE FALSE TRUE TRUE TRUE [2101] TRUE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE TRUE TRUE [2113] TRUE FALSE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE FALSE TRUE [2125] TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE [2137] TRUE TRUE TRUE FALSE FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [2149] FALSE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE [2161] TRUE TRUE NA TRUE FALSE FALSE TRUE FALSE TRUE TRUE TRUE FALSE [2173] TRUE FALSE TRUE NA TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE [2185] TRUE TRUE FALSE FALSE FALSE TRUE FALSE FALSE TRUE TRUE TRUE TRUE [2197] FALSE FALSE TRUE FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE [2209] TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [2221] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE NA TRUE [2233] FALSE TRUE TRUE TRUE FALSE FALSE TRUE FALSE FALSE NA FALSE FALSE [2245] TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE [2257] FALSE FALSE TRUE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE [2269] TRUE FALSE FALSE TRUE FALSE FALSE TRUE TRUE TRUE FALSE FALSE TRUE [2281] FALSE TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE FALSE TRUE TRUE [2293] FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE NA [2305] TRUE FALSE NA FALSE TRUE TRUE TRUE TRUE TRUE NA TRUE NA [2317] FALSE TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE [2329] TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [2341] TRUE NA FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE [2353] TRUE FALSE TRUE TRUE TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE [2365] TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE FALSE FALSE TRUE FALSE [2377] TRUE FALSE FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [2389] TRUE FALSE TRUE TRUE TRUE NA TRUE TRUE TRUE TRUE TRUE TRUE [2401] NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE [2413] FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE NA TRUE FALSE FALSE [2425] TRUE TRUE FALSE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE [2437] FALSE FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE TRUE FALSE TRUE [2449] FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE FALSE TRUE [2461] FALSE TRUE FALSE NA TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE [2473] TRUE FALSE NA FALSE TRUE TRUE TRUE TRUE TRUE FALSE NA FALSE [2485] FALSE NA TRUE FALSE TRUE FALSE TRUE TRUE TRUE FALSE FALSE TRUE [2497] TRUE TRUE FALSE TRUE FALSE TRUE FALSE FALSE TRUE TRUE FALSE TRUE [2509] FALSE TRUE TRUE TRUE FALSE TRUE NA TRUE TRUE FALSE FALSE FALSE [2521] TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE [2533] TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE [2545] TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE [2557] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE [2569] FALSE NA TRUE TRUE FALSE FALSE TRUE TRUE FALSE FALSE TRUE NA [2581] FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE TRUE [2593] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE [2605] FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE NA TRUE [2617] TRUE TRUE TRUE FALSE TRUE NA TRUE TRUE TRUE FALSE TRUE FALSE [2629] FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE FALSE TRUE TRUE [2641] FALSE TRUE TRUE NA FALSE FALSE TRUE FALSE FALSE TRUE FALSE TRUE [2653] FALSE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE [2665] FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE FALSE [2677] TRUE FALSE FALSE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE FALSE [2689] FALSE TRUE FALSE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE FALSE [2701] FALSE NA FALSE FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE [2713] FALSE FALSE FALSE TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE [2725] TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE [2737] FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE TRUE TRUE TRUE FALSE [2749] TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE FALSE TRUE FALSE TRUE [2761] FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE FALSE FALSE TRUE TRUE [2773] TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE NA TRUE [2785] TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE FALSE TRUE TRUE [2797] TRUE TRUE FALSE TRUE > > # ======================= > # = 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) Polite note: You asked for scale totals, but some subjects have missing data: Perhaps use means?... > bfi= umx_score_scale(name="As", base="As", pos=2:5, rev=1, mapStrings = mapStrings, data= bfi) Polite note: You asked for scale totals, but some subjects have missing data: Perhaps use means?... > > > > cleanEx() detaching ‘package:psychTools’, ‘package:psych’ > 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 [1] TRUE > tmp = umx_select_valid("disp", "newDisp", data = tmp) > anyNA(tmp$disp) # column repaired [1] FALSE > > > > 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 Current plot format is 'TRUE' Use TRUE to turn on, FALSE to turn off. > old = umx_set_auto_plot(silent = TRUE) # store existing value > old [1] TRUE > 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 Current auto-run setting is 'TRUE'. Valid options are TRUE or FALSE. > 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 mxCondenseMatrixSlots is currently: 'FALSE' > 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 2/10 [1] 2 > 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 10/10 [1] 10 > m1 = umx_set_cores(1, m1) # set m1 usage to 1 core > umx_set_cores(model = m1) # show new value for m1 1/10 [1] 1 > 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 Current threshold for small variance warning in umx functions is '0.1' Current threshold for excess ratio among variances warning in umx functions is '1000' > old = umx_set_data_variance_check(silent = TRUE) # store existing value > umx_set_data_variance_check(minVar = .01) Current threshold for excess ratio among variances warning in umx functions is '1000' > umx_set_data_variance_check(maxVarRatio = 500) Current threshold for small variance warning in umx functions is '0.01' > 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 Current format is '£' > old = umx_set_dollar_symbol(silent=TRUE) # store existing value > fin_interest(100) Table: Compounding £100 principle plus £0 annual deposits, 5% interest and 0% inflation. |Year |Deposits |Interest |Total_Deposits |Total_Interest |Total | |:----|:--------|:--------|:--------------|:--------------|:-----| | | | | | |£100 | |2023 |£0 |£5 |£0 |£5 |£105 | |2024 |£0 |£5 |£0 |£10 |£110 | |2025 |£0 |£6 |£0 |£16 |£116 | |2026 |£0 |£6 |£0 |£22 |£122 | |2027 |£0 |£6 |£0 |£28 |£128 | |2028 |£0 |£7 |£0 |£35 |£135 | |2029 |£0 |£7 |£0 |£42 |£142 | |2030 |£0 |£7 |£0 |£49 |£149 | |2031 |£0 |£8 |£0 |£57 |£157 | |2032 |£0 |£8 |£0 |£65 |£165 | £164.70> 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) Current mvnRelEps is: '0.005' Current mvnMaxPointsA is: '0' Current Parallel diagnostics is: 'No' > umx_set_optimization_options("mvnRelEps") Current mvnRelEps is: '0.005' > ## 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 Current Optimizer is: 'SLSQP'. Options are: 'CSOLNP' and 'SLSQP' > 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 Current format is'gv'. Valid options are 'gv' or 'dot'. Use TRUE to toggle > 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 Current format is 'DiagrammeR'. Valid options are 'DiagrammeR', 'pdf', 'png', 'svg', or 'graphviz'. TRUE toggles between DiagrammeR and graphviz > 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 Currently option to use hrbrthemes for plots is'FALSE'. Valid options are TRUE or FALSE > 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 Current separator is',' > old = umx_set_separator(silent=TRUE) # store existing value > umx_set_separator("|") > umxAPA(.3, .2) β = 0.3 [-0.09| 0.69]> 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 Current silent setting is 'FALSE'. Valid options are TRUE or FALSE. > umx_set_silent(FALSE, silent = TRUE) # set to FALSE > umx_set_silent(old) # reinstate > umx_set_silent() # print existing value Current silent setting is 'FALSE'. Valid options are TRUE or FALSE. > > > > 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 Current format is'markdown'. Valid options are 'latex', 'html', 'pipe', 'simple', 'markdown', and 'rst' > old = umx_set_table_format() # store existing value Current format is'markdown'. Valid options are 'latex', 'html', 'pipe', 'simple', 'markdown', and 'rst' > umx_set_table_format("latex") > umx_set_table_format("html") > umx_set_table_format("markdown") > umx_set_table_format("") # get available options legal options are 'latex', 'html', 'pipe', 'simple', 'markdown', and 'rst' > 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 'data.frame': 64 obs. of 3 variables: $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... $ values: num 160 160 108 258 360 ... $ ind : Factor w/ 2 levels "disp","hp": 1 1 1 1 1 1 1 1 1 1 ... > 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)) [1] "F" "U" > > > > 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) [1] "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" [1] "dog" > trimws(" dog ", "l") # added by R in v 3.3.0 [1] "dog " > umx_trim("dog ") # "dog" [1] "dog" > umx_trim("\t dog \n") # "dog" [1] "dog" > umx_trim("xlsx dog.xlsx", "\\.?xlsx ?") # "dog" [1] "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") [1] 36.3241 1.0000 15360.7998 1.0000 > tmp2 = tmp[, c(1, 3)] > umx_var(tmp2, format = "diag") mpg disp 36.3241 15360.7998 > umx_var(tmp2, format = "full") mpg disp mpg 36.3241 -633.0972 disp -633.0972 15360.7998 > > 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") [1] 1 1 1 > umx_var(df, format = "full", allowCorForFactorCovs=TRUE) z1 z2 z3 z1 1.0000000 0.6260672 0.6949095 z2 0.6260672 1.0000000 0.6749120 z3 0.6949095 0.6749120 1.0000000 > > # 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 = "") Hmm... A variable already existed matching one of the de-suffixed twin variables... A second column with the same name will be created. the issue is with:'age' > long = umx_wide2long(data = twinData, sep = "", verbose = TRUE) nonTwinColNames = 'fam', 'age', 'zyg', 'part', 'cohort', and 'zygosity' twinColumns = 'wt', 'ht', 'htwt', 'bmi', and 'age' Hmm... A variable already existed matching one of the de-suffixed twin variables... A second column with the same name will be created. the issue is with:'age' > str(long) 'data.frame': 7616 obs. of 11 variables: $ fam : int 1 2 3 4 5 6 7 8 9 10 ... $ age : int 21 24 21 21 19 26 23 29 24 28 ... $ zyg : int 1 1 1 1 1 1 1 1 1 1 ... $ part : int 2 2 2 2 2 2 2 2 2 2 ... $ cohort : chr "younger" "younger" "younger" "younger" ... $ zygosity: Factor w/ 5 levels "MZFF","MZMM",..: 1 1 1 1 1 1 1 1 1 1 ... $ wt : int 58 54 55 66 50 60 65 40 60 76 ... $ ht : num 1.7 1.63 1.65 1.57 1.61 ... $ htwt : num 20.1 20.3 20.2 26.8 19.3 ... $ bmi : num 21 21.1 21 23 20.7 ... $ age : int 21 24 21 21 19 26 23 29 24 28 ... > str(twinData) 'data.frame': 3808 obs. of 16 variables: $ fam : int 1 2 3 4 5 6 7 8 9 10 ... $ age : int 21 24 21 21 19 26 23 29 24 28 ... $ zyg : int 1 1 1 1 1 1 1 1 1 1 ... $ part : int 2 2 2 2 2 2 2 2 2 2 ... $ wt1 : int 58 54 55 66 50 60 65 40 60 76 ... $ wt2 : int 57 53 50 76 48 60 65 39 57 64 ... $ ht1 : num 1.7 1.63 1.65 1.57 1.61 ... $ ht2 : num 1.7 1.63 1.68 1.65 1.63 ... $ htwt1 : num 20.1 20.3 20.2 26.8 19.3 ... $ htwt2 : num 19.7 19.9 17.7 27.9 18.1 ... $ bmi1 : num 21 21.1 21 23 20.7 ... $ bmi2 : num 20.9 21 20.1 23.3 20.3 ... $ cohort : chr "younger" "younger" "younger" "younger" ... $ zygosity: Factor w/ 5 levels "MZFF","MZMM",..: 1 1 1 1 1 1 1 1 1 1 ... $ age1 : int 21 24 21 21 19 26 23 29 24 28 ... $ age2 : int 21 24 21 21 19 26 23 29 24 28 ... > > > > 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]") [1] TRUE > > > > 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) MxModel 'label_ex' type : RAM $matrices : 'A', 'S', and 'F' $algebras : NULL $penalties : NULL $constraints : NULL $intervals : NULL $latentVars : 'G' $manifestVars : 'x1' $data : 500 x 5 $data means : NA $data type: 'raw' $submodels : NULL $expectation : MxExpectationRAM $fitfunction : MxFitFunctionML $compute : NULL $independent : FALSE $options : $output : FALSE > > > > > cleanEx() > nameEx("xmuMaxLevels") > ### * xmuMaxLevels > > flush(stderr()); flush(stdout()) > > ### Name: xmuMaxLevels > ### Title: xmuMaxLevels > ### Aliases: xmuMaxLevels > > ### ** Examples > > xmuMaxLevels(mtcars) # NA = no ordinal vars [1] NA > xmuMaxLevels(umxFactor(mtcars)) [1] 30 > xmuMaxLevels(umxFactor(mtcars), what = "name") [1] "qsec" > > > > cleanEx() > nameEx("xmuMinLevels") > ### * xmuMinLevels > > flush(stderr()); flush(stdout()) > > ### Name: xmuMinLevels > ### Title: xmuMinLevels > ### Aliases: xmuMinLevels > > ### ** Examples > > xmuMinLevels(mtcars) # NA = no ordinal vars [1] NA > xmuMinLevels(umxFactor(mtcars)) [1] 2 > xmuMinLevels(umxFactor(mtcars), what = "name") [1] "vs" > > > > 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")) MxData 'data' type : 'cov' numObs : '32' observed : mpg hp mpg 36.3241 -320.7321 hp -320.7321 4700.8669 means : NA > > > > 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]") [1] "A[1,1]" > xmu_bracket_address2rclabel(label = "top.A[1,1]") [1] "top.A[1,1]" > xmu_bracket_address2rclabel(label = "A_std[1,1]") [1] "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") [1] FALSE > xmu_cell_is_on(r = 3, c = 3, "lower_inc") [1] TRUE > xmu_cell_is_on(r = 3, c = 3, "upper") [1] FALSE > xmu_cell_is_on(r = 3, c = 3, "upper_inc") [1] TRUE > xmu_cell_is_on(r = 3, c = 3, "diag") [1] TRUE > xmu_cell_is_on(r = 2, c = 3, "diag") [1] FALSE > xmu_cell_is_on(r = 3, c = 3, "any") [1] TRUE > 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) [1] FALSE > > > > 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 = "") [1] TRUE > ## 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") [1] TRUE > xmu_check_needs_means(mtcars, type = "FIML") [1] TRUE > # 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") [1] TRUE > xmu_check_needs_means(mtcars, type = "ULS", allContinuousMethod= "marginals") [1] TRUE > xmu_check_needs_means(mtcars, type = "DWLS", allContinuousMethod= "marginals") [1] TRUE > > # ================================ > # = Provided as an mxData object = > # ================================ > tmp = mxData(mtcars, type="raw") > xmu_check_needs_means(tmp, type = "FIML") # TRUE [1] TRUE > xmu_check_needs_means(tmp, type = "ULS", allContinuousMethod= "cumulants") #FALSE [1] FALSE > # TRUE - means with marginals > xmu_check_needs_means(tmp, type = "WLS", allContinuousMethod= "marginals") [1] TRUE > tmp = mxData(cov(mtcars), type="cov", numObs= 100) > # Should catch this can't be type FIML > xmu_check_needs_means(tmp) # FALSE [1] FALSE > tmp = mxData(cov(mtcars), means = umx_means(mtcars), type="cov", numObs= 100) > xmu_check_needs_means(tmp) # TRUE [1] TRUE > > # ======================= > # = One var is a factor = > # ======================= > tmp = mtcars > tmp$cyl = factor(tmp$cyl) > xmu_check_needs_means(tmp, allContinuousMethod= "cumulants") # TRUE [1] TRUE > xmu_check_needs_means(tmp, allContinuousMethod= "marginals") # TRUE - always has means [1] TRUE > > > > 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")]) Polite note: Variance of variable(s) 'ht1' and 'ht2' is < 0.1. You might want to express the variable in smaller units, e.g. multiply to use cm instead of metres. Alternatively umx_scale() for data already in long-format, or umx_scale_wide_twin_data for wide data might be useful. Polite note: Variance of variable(s) 'wt2' is more than 1000 times that of 'ht1'. You might want scale the less variable manifests to get all variables on similar scales. Alternatively, umx_scale() for data already in long-format, or umx_scale_wide_twin_data for wide data might be useful. > 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 = "_") [1] "data.var" > xmu_clean_label("my.var.lab", replace = "_") [1] "my_var_lab" > > > > 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 mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4 > tmp = xmu_data_missing(tmp, selVars = "wt", sep= NULL, dropMissingDef= TRUE, hint= "mtcars") 1 row(s) dropped from 'mtcars' due to missing definition variable(s) > dim(mtcars) [1] 32 11 > dim(tmp) [1] 31 11 > > ## 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") a b c d 1 a1 c1 b1 d1 2 a2 c2 b2 d2 3 a3 c3 b3 d3 4 a4 b4 c4 d4 5 a5 b5 c5 d5 6 a6 c6 b6 d6 7 a7 b7 c7 d7 8 a8 b8 c8 d8 9 a9 b9 c9 d9 10 a10 b10 c10 d10 > xmu_data_swap_a_block(test, rowSelector = c(1,2,3,6), T1Names = c("a","c"), T2Names = c("b","d")) a b c d 1 b1 a1 d1 c1 2 b2 a2 d2 c2 3 b3 a3 d3 c3 4 a4 b4 c4 d4 5 a5 b5 c5 d5 6 b6 a6 d6 c6 7 a7 b7 c7 d7 8 a8 b8 c8 d8 9 a9 b9 c9 d9 10 a10 b10 c10 d10 > > > > > 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) [1] "all continuous" > tmp$hasMeans # FALSE - no means with cumulants [1] FALSE > tmp =xmu_describe_data_WLS(mtcars, allContinuousMethod= "marginals") > tmp$hasMeans # TRUE we get means with marginals [1] TRUE > > # ========================== > # = mxData object as input = > # ========================== > tmp = mxData(mtcars, type="raw") > xmu_describe_data_WLS(tmp, allContinuousMethod= "cumulants", verbose = TRUE)$hasMeans # FALSE [1] "all continuous" [1] FALSE > xmu_describe_data_WLS(tmp, allContinuousMethod= "marginals")$hasMeans # TRUE [1] 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 [1] TRUE > xmu_describe_data_WLS(tmp, allContinuousMethod= "marginals")$hasMeans # TRUE [1] 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")) [1] "\n# Latents\n\tas1 [shape = circle];\n\n# Manifests\n\tE [shape = square];\n\tN [shape = square];\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"]; a_cp -> a_cp [dir = both label="3.14"];> 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"]; fromMe -> toYou [dir = forward label="3.142"];> cat(out$latent) # fromMe fromMe> cat(out$manifest) # toYou 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"]; a_cp1 -> a_cp2 [dir = both label="2"]; a_cp1 -> a_cp3 [dir = both label="3"]; a_cp2 -> a_cp3 [dir = both label="5"];> > # 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"]; a_cp1 -> a_cp2 [dir = forward label="2"]; a_cp1 -> a_cp3 [dir = forward label="3"]; a_cp2 -> a_cp3 [dir = forward label="5"];> > # 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"] ... out$str = a_cp1 -> v2 [dir = forward label="2"]; a_cp1 -> v3 [dir = forward label="3"]; a_cp2 -> v3 [dir = forward label="5"]; > > # 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) out$str = a_cp2 -> a_cp1 [dir = both label="2"]; a_cp3 -> a_cp1 [dir = both label="3"]; a_cp3 -> a_cp2 [dir = both label="5"]; a_cp1 -> common1 [dir = forward label="1"]; a_cp2 -> common2 [dir = forward label="4"]; a_cp3 -> common3 [dir = forward label="6"]; out$manifests = 'common1', 'common2', and 'common3' out$latents = 'a_cp2' and 'a_cp3' > > # ================================ > # = 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) out$manifests = 'a', 'b', and 'c' > > # ================================ > # = 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) out$latents = 'a_cp1', 'a_cp2', and 'a_cp3' > > > # ======================== > # = 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) one -> v1 [dir = forward label="1"]; one -> v2 [dir = forward label="2"];> > ## 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) $min [1] "min1" "min2" "L1" $same [1] "s1" "s2" $max [1] "x1" "x2" "x3" > > # Move min1 to max > xmu_dot_move_ranks(max = "min1", old_min= old_min, old_same= old_same, old_max= old_max) $min [1] "min2" $same [1] "s1" "s2" $max [1] "x1" "x2" "x3" "min1" > > # Clear min > xmu_dot_move_ranks(min = "", old_min= old_min, old_same= old_same, old_max= old_max) $min NULL $same [1] "s1" "s2" $max [1] "x1" "x2" "x3" > > > > 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") [1] "{rank=same; as1};\n" > > > > 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)) [1] "\t{rank=min; L1};\n\t{rank=same; x1 x2};\n\t{rank=max; e1 e2 e3};\n" > > > > > 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") wt Mazda RX4 2.620 Mazda RX4 Wag 2.875 Datsun 710 2.320 Hornet 4 Drive 3.215 Hornet Sportabout 3.440 Valiant 3.460 Duster 360 3.570 Merc 240D 3.190 Merc 230 3.150 Merc 280 3.440 Merc 280C 3.440 Merc 450SE 4.070 Merc 450SL 3.730 Merc 450SLC 3.780 Cadillac Fleetwood 5.250 Lincoln Continental 5.424 Chrysler Imperial 5.345 Fiat 128 2.200 Honda Civic 1.615 Toyota Corolla 1.835 Toyota Corona 2.465 Dodge Challenger 3.520 AMC Javelin 3.435 Camaro Z28 3.840 Pontiac Firebird 3.845 Fiat X1-9 1.935 Porsche 914-2 2.140 Lotus Europa 1.513 Ford Pantera L 3.170 Ferrari Dino 2.770 Maserati Bora 3.570 Volvo 142E 2.780 > xmu_extract_column(mxData(mtcars, type = "raw"), "wt") wt Mazda RX4 2.620 Mazda RX4 Wag 2.875 Datsun 710 2.320 Hornet 4 Drive 3.215 Hornet Sportabout 3.440 Valiant 3.460 Duster 360 3.570 Merc 240D 3.190 Merc 230 3.150 Merc 280 3.440 Merc 280C 3.440 Merc 450SE 4.070 Merc 450SL 3.730 Merc 450SLC 3.780 Cadillac Fleetwood 5.250 Lincoln Continental 5.424 Chrysler Imperial 5.345 Fiat 128 2.200 Honda Civic 1.615 Toyota Corolla 1.835 Toyota Corona 2.465 Dodge Challenger 3.520 AMC Javelin 3.435 Camaro Z28 3.840 Pontiac Firebird 3.845 Fiat X1-9 1.935 Porsche 914-2 2.140 Lotus Europa 1.513 Ford Pantera L 3.170 Ferrari Dino 2.770 Maserati Bora 3.570 Volvo 142E 2.780 > xmu_extract_column(mxData(mtcars, type = "raw"), "wt", drop=TRUE) [1] 2.620 2.875 2.320 3.215 3.440 3.460 3.570 3.190 3.150 3.440 3.440 4.070 [13] 3.730 3.780 5.250 5.424 5.345 2.200 1.615 1.835 2.465 3.520 3.435 3.840 [25] 3.845 1.935 2.140 1.513 3.170 2.770 3.570 2.780 > xmu_extract_column(mxData(mtcars, type = "raw"), c("wt", "mpg")) wt mpg Mazda RX4 2.620 21.0 Mazda RX4 Wag 2.875 21.0 Datsun 710 2.320 22.8 Hornet 4 Drive 3.215 21.4 Hornet Sportabout 3.440 18.7 Valiant 3.460 18.1 Duster 360 3.570 14.3 Merc 240D 3.190 24.4 Merc 230 3.150 22.8 Merc 280 3.440 19.2 Merc 280C 3.440 17.8 Merc 450SE 4.070 16.4 Merc 450SL 3.730 17.3 Merc 450SLC 3.780 15.2 Cadillac Fleetwood 5.250 10.4 Lincoln Continental 5.424 10.4 Chrysler Imperial 5.345 14.7 Fiat 128 2.200 32.4 Honda Civic 1.615 30.4 Toyota Corolla 1.835 33.9 Toyota Corona 2.465 21.5 Dodge Challenger 3.520 15.5 AMC Javelin 3.435 15.2 Camaro Z28 3.840 13.3 Pontiac Firebird 3.845 19.2 Fiat X1-9 1.935 27.3 Porsche 914-2 2.140 26.0 Lotus Europa 1.513 30.4 Ford Pantera L 3.170 15.8 Ferrari Dino 2.770 19.7 Maserati Bora 3.570 15.0 Volvo 142E 2.780 21.4 > > > > 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" [1] "top" "MZ" "DZ" "fitfunction" "name" [6] "matrices" "algebras" "constraints" "data" "submodels" [11] "output" "compute" "options" "intervals" "manifestVars" [16] "latentVars" "penalties" > class(m1$MZ$fitfunction)[[1]] == "MxFitFunctionML" [1] TRUE > > # ==================== > # = With a covariate = > # ==================== > > m1= xmu_make_TwinSuperModel(mzData=mzData, dzData=dzData, + selDVs= "wt", selCovs= "age", sep="", nSib=2) 1 row(s) dropped from 'data' due to missing definition variable(s) > m1$top$intercept$labels wt1 wt2 means "intercept_wt1" "intercept_wt1" > m1$MZ$expMean mxAlgebra 'expMean' $formula: top.intercept + cbind(T1DefVars %*% top.meansBetas, T2DefVars %*% top.meansBetas) $result: (not yet computed) <0 x 0 matrix> dimnames: [[1]] [1] "means" [[2]] [1] "wt1" "wt2" > > # =============== > # = WLS example = > # =============== > m1=xmu_make_TwinSuperModel(mzData=mzData, dzData=dzData,selDVs=c("wt","ht"),sep="",type="WLS") Data treated as WLS > class(m1$MZ$fitfunction)[[1]] == "MxFitFunctionWLS" [1] TRUE > m1$MZ$fitfunction$type =="WLS" [1] TRUE > # Check default all-continuous method > m1$MZ$fitfunction$continuousType == "cumulants" [1] TRUE > > # Choose non-default type (DWLS) > m1= xmu_make_TwinSuperModel(mzData= mzData, dzData= dzData, + selDVs= c("wt","ht"), sep="", type="DWLS") Data treated as DWLS > m1$MZ$fitfunction$type =="DWLS" [1] TRUE > class(m1$MZ$fitfunction)[[1]] == "MxFitFunctionWLS" [1] TRUE > > # Switch WLS method > m1 = xmu_make_TwinSuperModel(mzData= mzData, dzData= dzData, selDVs= c("wt","ht"), sep= "", + type = "WLS", allContinuousMethod = "marginals") Data treated as WLS > m1$MZ$fitfunction$continuousType == "marginals" [1] TRUE > class(m1$MZ$fitfunction)[[1]] == "MxFitFunctionWLS" [1] TRUE > > > # ============================================ > # = 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) Found 1 pair(s) of ordinal variables:'obese1' and 'obese2' (No binary) 1 pair(s) of continuous variables:'wt1' > names(m1) # "top" "MZ" "DZ" [1] "top" "MZ" "DZ" "fitfunction" "name" [6] "matrices" "algebras" "constraints" "data" "submodels" [11] "output" "compute" "options" "intervals" "manifestVars" [16] "latentVars" "penalties" > > # ============== > # = 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) Found 1 pairs of binary variables:'obese1' and 'obese2' I am fixing the latent means and variances of these variables to 0 and 1 and 1 pair(s) of continuous variables first of each pair was: 'wt1' > > # ======================================== > # = 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) dataType = cov > class(m1$MZ$fitfunction)[[1]] =="MxFitFunctionML" [1] TRUE > dimnames(m1$MZ$data$observed)[[1]]==c("wt1", "wt2") [1] TRUE TRUE > > > > > 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) 'data.frame': 32 obs. of 12 variables: $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... $ cyl : num 6 6 4 6 8 6 8 4 4 6 ... $ disp : num 160 160 108 258 360 ... $ hp : num 110 110 93 110 175 105 245 62 95 123 ... $ drat : num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ... $ wt : num 2.62 2.88 2.32 3.21 3.44 ... $ qsec : num 16.5 17 18.6 19.4 17 ... $ vs : num 0 0 1 1 0 1 0 1 1 1 ... $ am : num 1 1 1 0 0 0 0 0 0 0 ... $ gear : num 4 4 4 3 3 3 3 4 4 4 ... $ carb : num 4 4 1 1 2 1 4 2 2 4 ... $ mpgbin: Ord.factor w/ 2 levels "low"<"high": NA NA NA NA NA NA NA NA NA NA ... ..- attr(*, "mxFactor")= logi TRUE > df[order(df$mpg), c(1,12)] mpg mpgbin Camaro Z28 13.3 Duster 360 14.3 Chrysler Imperial 14.7 Maserati Bora 15.0 Merc 450SLC 15.2 AMC Javelin 15.2 Dodge Challenger 15.5 Ford Pantera L 15.8 Merc 450SE 16.4 Merc 450SL 17.3 Merc 280C 17.8 Valiant 18.1 Hornet Sportabout 18.7 Merc 280 19.2 Pontiac Firebird 19.2 Ferrari Dino 19.7 Mazda RX4 21.0 Mazda RX4 Wag 21.0 Hornet 4 Drive 21.4 Volvo 142E 21.4 Toyota Corona 21.5 Datsun 710 22.8 Merc 230 22.8 Merc 240D 24.4 Porsche 914-2 26.0 Fiat X1-9 27.3 Honda Civic 30.4 Lotus Europa 30.4 Fiat 128 32.4 Toyota Corolla 33.9 Cadillac Fleetwood NA low Lincoln Continental NA low > # 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] mpg_T2 mpg_T1 mpgbin_T1 mpgbin_T2 Duster 360 NA NA low low Cadillac Fleetwood NA NA low low Lincoln Continental NA NA low low Chrysler Imperial NA NA low low Camaro Z28 NA NA low low Maserati Bora NA NA low low Merc 450SLC 15.2 15.2 AMC Javelin 15.2 15.2 Dodge Challenger 15.5 15.5 Ford Pantera L 15.8 15.8 Merc 450SE 16.4 16.4 Merc 450SL 17.3 17.3 Merc 280C 17.8 17.8 Valiant 18.1 18.1 Hornet Sportabout 18.7 18.7 Merc 280 19.2 19.2 Pontiac Firebird 19.2 19.2 Ferrari Dino 19.7 19.7 Mazda RX4 21.0 21.0 Mazda RX4 Wag 21.0 21.0 Hornet 4 Drive 21.4 21.4 Volvo 142E 21.4 21.4 Toyota Corona 21.5 21.5 Datsun 710 22.8 22.8 Merc 230 22.8 22.8 Merc 240D 24.4 24.4 Porsche 914-2 26.0 26.0 Fiat X1-9 27.3 27.3 Honda Civic 30.4 30.4 Lotus Europa 30.4 30.4 Fiat 128 32.4 32.4 Toyota Corolla 33.9 33.9 > > > > 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" Polite note: Variance of variable(s) 'disp' is more than 1000 times that of 'am'. You might want scale the less variable manifests to get all variables on similar scales. Alternatively, umx_scale() for data already in long-format, or umx_scale_wide_twin_data for wide data might be useful. > # names(tmp$observed) # "mpg" "cyl" "disp" > manVars = c("mpg", "cyl", "disp") > tmp = xmu_make_mxData(data= mtcars, type = "Auto", manifests = manVars); Polite note: Variance of variable(s) 'disp' is more than 1000 times that of 'cyl'. You might want scale the less variable manifests to get all variables on similar scales. Alternatively, umx_scale() for data already in long-format, or umx_scale_wide_twin_data for wide data might be useful. > tmp$type == "raw" # TRUE [1] TRUE > > # ============================== > # = All continuous WLS example = > # ============================== > tmp = xmu_make_mxData(data= mtcars, type = "WLS" , manifests = manVars, verbose= TRUE) Polite note: Variance of variable(s) 'disp' is more than 1000 times that of 'cyl'. You might want scale the less variable manifests to get all variables on similar scales. Alternatively, umx_scale() for data already in long-format, or umx_scale_wide_twin_data for wide data might be useful. ManifestVars set to: mpg, cyl, disp. 8 unused variables (hp, drat, wt, qsec, vs, am, gear, carb > tmp$type == "raw" # TRUE (WLS is triggered by the fit function, not the data type) [1] TRUE > > # ============================ > # = Missing data WLS example = > # ============================ > tmp = mtcars; tmp[1, "mpg"] = NA # add NA > tmp = xmu_make_mxData(data= tmp, type = "WLS", manifests = manVars, verbose= TRUE) Polite note: Variance of variable(s) 'disp' is more than 1000 times that of 'cyl'. You might want scale the less variable manifests to get all variables on similar scales. Alternatively, umx_scale() for data already in long-format, or umx_scale_wide_twin_data for wide data might be useful. ManifestVars set to: mpg, cyl, disp. 8 unused variables (hp, drat, wt, qsec, vs, am, gear, carb > > ## 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 MxData 'data' type : 'cov' numObs : '100' observed : mpg cyl mpg 36.324103 -9.172379 cyl -9.172379 3.189516 means : NA > xmu_make_mxData(data= tmp, type = "cor", manifests = c("mpg")) # trim existing mxData MxData 'data' type : 'cov' numObs : '100' observed : mpg mpg 36.3241 means : NA > xmu_make_mxData(data= tmp, type = "cor") # no manifests specified (use all) MxData 'data' type : 'cov' numObs : '100' observed : mpg cyl mpg 36.324103 -9.172379 cyl -9.172379 3.189516 means : NA > xmu_make_mxData(data= tmp, manifests = c("mpg", "cyl")) # auto MxData 'data' type : 'cov' numObs : '100' observed : mpg cyl mpg 36.324103 -9.172379 cyl -9.172379 3.189516 means : NA > > # ======================= > # = Pass string through = > # ======================= > xmu_make_mxData(data= c("a", "b", "c"), type = "Auto") [1] "a" "b" "c" > > > > > 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) [1] "par.observed" > xmu_match.arg("allow me", option_list, check = FALSE) [1] "allow me" > xmu_match.arg(option_list, option_list) [1] "default" > option_list = c(NULL, "par.observed", "empirical") > # fails with NULL!!!!! > xmu_match.arg(option_list, option_list) [1] "par.observed" > option_list = c(NA, "par.observed", "empirical") > xmu_match.arg(option_list, option_list) # use NA instead [1] NA > option_list = c(TRUE, FALSE, NA) > xmu_match.arg(option_list, option_list) # works with non character [1] TRUE > # 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") [1] TRUE > "bob" == xmu_name_from_lavaan_str(name = "bob") [1] TRUE > "my_model" == xmu_name_from_lavaan_str("# my model") [1] TRUE > > > > > 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) [[1]] mxPath a1_T2 <-> a1_T2 [value=1, free=FALSE, lbound=0] c1_T2 <-> c1_T2 [value=1, free=FALSE, lbound=0] e1_T2 <-> e1_T2 [value=1, free=FALSE, lbound=0] [[2]] mxPath one -> a1_T2 [value=0, free=FALSE] one -> c1_T2 [value=0, free=FALSE] one -> e1_T2 [value=0, free=FALSE] [[3]] mxPath a1_T2 -> NFC3_T2 [value=0.2, free=TRUE] c1_T2 -> NFC3_T2 [value=0.2, free=TRUE] e1_T2 -> NFC3_T2 [value=0.2, free=TRUE] > > > > > 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") [1] "a_T1" "one" "b_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] [1] "A[1,1]" > xmu_rclabel_2_bracket_address(label = "A_r10c1") [1] "A[10,1]" > xmu_rclabel_2_bracket_address(label = "A_r1c1", dotprefix = "model.top") [1] "model.top.A[1,1]" > xmu_rclabel_2_bracket_address("A_r1c1", suffix= "_std") [1] "A_std[1,1]" > xmu_rclabel_2_bracket_address("A_r1c1", dotprefix="myModel", suffix="_std") [1] "myModel.A_std[1,1]" > > > > > 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") [1] "_T" > > > > 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) FullMatrix 'test' $labels [,1] [,2] [,3] [,4] [1,] "test_r1c1" "test_r1c2" "test_r1c3" "test_r1c4" [2,] "test_r2c1" "test_r2c2" "test_r2c3" "test_r2c4" [3,] "test_r3c1" "test_r3c2" "test_r3c3" "test_r3c4" [4,] "test_r4c1" "test_r4c2" "test_r4c3" "test_r4c4" $values [,1] [,2] [,3] [,4] [1,] 0.0 0.0 0.0 0 [2,] 0.9 0.0 0.0 0 [3,] 0.0 0.9 0.0 0 [4,] 0.0 0.0 0.9 0 $free [,1] [,2] [,3] [,4] [1,] FALSE FALSE FALSE FALSE [2,] TRUE FALSE FALSE FALSE [3,] FALSE TRUE FALSE FALSE [4,] FALSE FALSE TRUE FALSE $lbound: No lower bounds assigned. $ubound: No upper bounds assigned. > # See how we have a diag free, but offset 1-down? > umx_print( xmu_simplex_corner(x, start = .9)$values, zero=".") |X1 |X2 |X3 |X4 | |:---|:---|:---|:--| |. |. |. |. | |0.9 |. |. |. | |. |0.9 |. |. | |. |. |0.9 |. | > > > > 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) wt1 ht1 wt2 ht2 wt1 5.313 0.292 2.923 0.158 ht1 0.292 0.039 0.173 0.026 wt2 2.923 0.173 5.523 0.279 ht2 0.158 0.026 0.279 0.038 > xmu_starts(mzData, dzData, selVars=selDVs, nSib= 2, sep="", equateMeans=TRUE, varForm="Cholesky") $varStarts [,1] [,2] [1,] 5.366022 0.00000000 [2,] 0.000000 0.03812264 $meanStarts wt1 ht1 wt1 ht1 58.757841 1.624691 58.757841 1.624691 $meanLabels [1] "expMean_wt1" "expMean_ht1" "expMean_wt1" "expMean_ht1" > > # Variance instead of SD > round(var(dzData[,tvars(selDVs, "")], na.rm=TRUE)/3,3) wt1 ht1 wt2 ht2 wt1 28.230 0.085 8.545 0.025 ht1 0.085 0.002 0.030 0.001 wt2 8.545 0.030 30.509 0.078 ht2 0.025 0.001 0.078 0.001 > xmu_starts(mzData, dzData, selVars = selDVs, nSib = 2, sep= "", + equateMeans= TRUE, varForm= "Cholesky", SD= FALSE) $varStarts [,1] [,2] [1,] 28.7942 0.000000000 [2,] 0.0000 0.001453336 $meanStarts wt1 ht1 wt1 ht1 58.757841 1.624691 58.757841 1.624691 $meanLabels [1] "expMean_wt1" "expMean_ht1" "expMean_wt1" "expMean_ht1" > > # one variable > xmu_starts(mzData, dzData, selVars= "wt", nSib = 2, sep="", equateMeans = TRUE) $varStarts [,1] [1,] 5.366022 $meanStarts wt1 wt1 58.75784 58.75784 $meanLabels [1] "expMean_wt1" "expMean_wt1" > > # 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) $varStarts [,1] [,2] [1,] 0.209985 0.0000000 [2,] 0.000000 0.3333333 $meanStarts [1] -0.437565 0.000000 -0.437565 0.000000 $meanLabels [1] "expMean_wt1" "expMean_obese1" "expMean_wt1" "expMean_obese1" > > xmu_starts(mxData(mzData, type="raw"), mxData(mzData, type="raw"), + selVars = c("wt","obese"), sep= "", nSib= 2, equateMeans = TRUE, SD= FALSE) $varStarts [,1] [,2] [1,] 0.2086248 0.0000000 [2,] 0.0000000 0.3333333 $meanStarts [1] -0.4589486 0.0000000 -0.4589486 0.0000000 $meanLabels [1] "expMean_wt1" "expMean_obese1" "expMean_wt1" "expMean_obese1" > > # ============== > # = 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) $varStarts [,1] [,2] [1,] 5.366022 0.00000000 [2,] 0.000000 0.03812264 $meanStarts wt1 ht1 wt1 ht1 wt1 ht1 58.757841 1.624691 58.757841 1.624691 58.757841 1.624691 $meanLabels [1] "expMean_wt1" "expMean_ht1" "expMean_wt1" "expMean_ht1" "expMean_wt1" [6] "expMean_ht1" > xmu_starts(mzData, dzData, selVars=selDVs, sep="", nSib=3, equateMeans=FALSE) $varStarts [,1] [,2] [1,] 5.366022 0.00000000 [2,] 0.000000 0.03812264 $meanStarts wt1 ht1 wt1 ht1 wt1 ht1 58.757841 1.624691 58.757841 1.624691 58.757841 1.624691 $meanLabels [1] "expMean_wt1" "expMean_ht1" "expMean_wt2" "expMean_ht2" "expMean_wt3" [6] "expMean_ht3" > > > > 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) [1] "wt" > > > > > ### *