R version 4.6.0 beta (2026-04-12 r89874 ucrt) -- "Because it was There" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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. 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. > > library("mvtnorm") > > options(digits = 4) > > J <- 5 > > set.seed(290875) > > lxd <- ltMatrices(runif(J * (J + 1) / 2) + 1, diag = TRUE, names = LETTERS[seq_len(J)]) > m <- matrix(1:J, ncol = 1) > d <- Mult(lxd, m) > > d0 <- mvnorm(invchol = lxd) > Y <- as.data.frame(t(simulate(d0, nsim = 1e6, seed = 29))) > mlm <- lm(D ~ 0 + A + B + C, data = Y) > (cf <- coef(d0, which = "D")) A B C -1.265 -1.178 -1.687 attr(,"sigma") D 0.9072 > coef(mlm) A B C -1.263 -1.176 -1.684 > summary(mlm)$sigma [1] 0.9062 > md <- margDist(d0, which = 1:4) > cd <- condDist(md, which_given = 1:3, given = diag(3)) > class(cd$scale) [1] "invchol" "ltMatrices" "matrix" "array" > coef(cd) [,1] [,2] [,3] D -1.265 -1.178 -1.687 attr(,"sigma") [1] 0.9072 > > d0 <- mvnorm(chol = solve(lxd)) > Y <- as.data.frame(t(simulate(d0, nsim = 1e6, seed = 29))) > mlm <- lm(D ~ 0 + A + B + C, data = Y) > (cf <- coef(d0, which = "D")) A B C -1.265 -1.178 -1.687 attr(,"sigma") D 0.9072 > coef(mlm) A B C -1.263 -1.176 -1.684 > summary(mlm)$sigma [1] 0.9062 > md <- margDist(d0, which = 1:4) > cd <- condDist(md, which_given = 1:3, given = diag(3)) > coef(cd) [,1] [,2] [,3] D -1.265 -1.178 -1.687 attr(,"sigma") [1] 0.9072 > > (d1 <- mvnorm(invchol = lxd, mean = m)) $scale , , 1 A B C D E A 1.512 . . . . B 1.058 1.234 . . . C 1.910 1.516 1.818 . . D 1.394 1.298 1.859 1.102 . E 1.661 1.075 1.374 1.117 1.796 $mean [,1] A 1 B 2 C 3 D 4 E 5 attr(,"class") [1] "mvnorm" > Y <- as.data.frame(t(simulate(d1, nsim = 1e6, seed = 29))) > mlm <- lm(D ~ A + B + C, data = Y) > (cf <- coef(d1, which = "D")) (Intercept) A B C 12.680 -1.265 -1.178 -1.687 attr(,"sigma") D 0.9072 > coef(mlm) (Intercept) A B C 12.666 -1.263 -1.176 -1.684 > summary(mlm)$sigma [1] 0.9062 > md <- margDist(d1, which = 1:4) > > cd <- condDist(md, which_given = 1:3, given = diag(3)) > class(cd$scale) [1] "invchol" "ltMatrices" "matrix" "array" > coef(cd) [,1] [,2] [,3] D 11.41 11.5 10.99 attr(,"sigma") [1] 0.9072 > cf[1] + cf[-1] A B C 11.41 11.50 10.99 > > d2 <- mvnorm(invchol = lxd, invcholmean = d) > Y <- as.data.frame(t(simulate(d2, nsim = 1e6, seed = 29))) > mlm <- lm(D ~ A + B + C, data = Y) > coef(d2, which = "D") (Intercept) A B C 12.680 -1.265 -1.178 -1.687 attr(,"sigma") D 0.9072 > coef(mlm) (Intercept) A B C 12.666 -1.263 -1.176 -1.684 > summary(mlm)$sigma [1] 0.9062 > coef(condDist(margDist(d2, which = 1:4), which_given = 1:3, given = diag(3))) [,1] [,2] [,3] D 11.41 11.5 10.99 attr(,"sigma") [1] 0.9072 > cf[1] + cf[-1] A B C 11.41 11.50 10.99 > > d3 <- mvnorm(chol = solve(lxd), invcholmean = d) > Y <- as.data.frame(t(simulate(d3, nsim = 1e6, seed = 29))) > mlm <- lm(D ~ A + B + C, data = Y) > coef(d3, which = "D") (Intercept) A B C 12.680 -1.265 -1.178 -1.687 attr(,"sigma") D 0.9072 > coef(mlm) (Intercept) A B C 12.666 -1.263 -1.176 -1.684 > summary(mlm)$sigma [1] 0.9062 > coef(condDist(margDist(d3, which = 1:4), which_given = 1:3, given = diag(3))) [,1] [,2] [,3] D 11.41 11.5 10.99 attr(,"sigma") [1] 0.9072 > cf[1] + cf[-1] A B C 11.41 11.50 10.99 > > d4 <- mvnorm(chol = solve(lxd), mean = m) > Y <- as.data.frame(t(simulate(d4, nsim = 1e6, seed = 29))) > mlm <- lm(D ~ A + B + C, data = Y) > coef(d4, which = "D") (Intercept) A B C 12.680 -1.265 -1.178 -1.687 attr(,"sigma") D 0.9072 > coef(mlm) (Intercept) A B C 12.666 -1.263 -1.176 -1.684 > summary(mlm)$sigma [1] 0.9062 > coef(condDist(margDist(d4, which = 1:4), which_given = 1:3, given = diag(3))) [,1] [,2] [,3] D 11.41 11.5 10.99 attr(,"sigma") [1] 0.9072 > cf[1] + cf[-1] A B C 11.41 11.50 10.99 > > > proc.time() user system elapsed 8.75 2.14 10.86