I am trying to create a figure in R. In this there is a normal bisected general distribution for the vector variable (X, Y) C along with F (X), F (Y); Conditional distribution f (y | x) and conditioning value x = x (this will be line through a simple align (v = x)). I have already received contour and abline:
But I do not know how to continue.
Even the code that I have used so far:
bivariate general < - Function (x, mu, sigma) {exp (- 5 * t (x-mu)% *% solution (sigma)% *% (x-mu)) / sqrt (2 * pi * det (sigma))} MU & LT; - C (0,0) Sigma & LT; - Matrix (C (1, .8, .8,1), NRO = 2) x1 & lt; - Seek (-3, 3, length outside = 50) x2 & lt; - seq (-3, 3, length.out = 50) z < - External (x1, x2, fun = function (x1, x2, ...) {apply (cbind (x1, x2), 1, bivariate.normal, ...)}, mu = mu, sigma = sigma (x 1, x2, z, col = "blue", drawlabels = FALSE, nlevels = 4, xlab = expression [1]), ylab = expression (x [2]), lvd = 1) abline (v = .7, Col = 1, lwd = 2, lty = 2) text (2, -2, label = expression (x) [1] == 0.7))
If you were provided it would be helpful to distribute the marginal function to the Constitution. The marginal distribution function could have been wrong, but I think you get what you want:
par (lwd = 2, mgp = c (1,1,0) ) # Remove the modified diagonal Bivariate.normal & lt; - Function (x, mu, sigma) exp (- 5 * diag (t (x-mu)% *% solution (sigma)% * (x-mu))) / sqrt (2 * Pi * det (sigma) ) Mu & lt; - c (0,0) sigma & lt; - Matrix (c (1, .8, .8,1), nrow = 2) x1 & lt; - seq (-3, 3, length out = 50) x2 & lt; - seq (-3, 3, length.out = 50) Plot (1: 10, Axis = FALSE, frame.plot = TRUE, lwd = 1) #z can now be calculated very easy. J and Lt-bivariate.normal (T (extended. Grid (x1, x2)), mu, sigma dim (jade) & lt; -C (length x1, length (x2)) contour (x1, x2, z, col = "# 4545FF", drawlabels = FALSE, nlevels = 4, xlab = expression (x [1]), ylab = Expression (x [2]), LWD = 2, axle = class (x1), ylim = range (x2), frame.plot = true, access = falls, xx = "i", yaxs = "i") axis (1, labels = FALSE, lwd.ticks = 2) axis (2, labels = FALSE, lwd.ticks = 2) abline (v = .7, col = 1, lwd = 2, lty = 2) text (2, -2, labels = expression (x [1] == 0.7)) # dotted F & LT; Function (x1, x2) bivariate.normal (t (cbind (x1, x2)), mu, sigma) x.s & lt; -seq (= min (x1), = max (x1), by = 0.1) vals & lt; -f (x1 = 0.7, x2 = xs) rows (Wal-Abees (min (x1)), xs, lt = 2, lw = 2) # marginal probability distribution: http://mpdc.mae.cornell.edu/ Courses / MAE714 / biv-normal.pdf # Please check this, I'm not sure that this is correct. Marginal X1 & lt; -function (x) exp ((- (x-mu [1]) ^ 2) / 2 * (sigma [1,2] ^ 2)) / (sigma [1,2] * sqrt (2 * pi)) Marginal xx & lt; -function (x) exp ((- (x-mu [1]) ^ 2) / 2 * (sigma [2,1] ^ 2)) / (sigma [2,1] * sqrt (2 * pi)) # On left side solid wall and lt; -Margin X 2 (x) line (wal-abs (min (x1)), xs, lti = 1, lw = 2) bottom solid solid wall and lieutenant; - Marginalized. X1 (xs) line (xs, wal-abs (min2), lt = 1, lw = 2)
Comments
Post a Comment