C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# In R after generating a mvrnorm distribution, Y, what does Y[,1] do?

By : AJ Greene
Date : November 22 2020, 03:01 PM
Does that help You're sampling from a multivariate normal distribution. For example in the bivariate case
code :
``````x <- mvrnorm(
n = 500,
mu = c(1, 2),
Sigma=matrix(c(4, 2, 2, 3), ncol = 2))
``````
``````ggplot(data.frame(x1 = x[, 1], x2 = x[, 2]), aes(x1, x2)) + geom_density_2d()
``````

Share :

## Generating a probability distribution

By : SmallTownOutlaw
Date : March 29 2020, 07:55 AM
This might help you The task you are trying to accomplish is tantamount to drawing a random point from the N-dimensional unit simplex.
code :
``````public static double[] getArray(int n)
{
double a[] = new double[n];
double s = 0.0d;
Random random = new Random();
for (int i = 0; i < n; i++)
{
a [i] = 1.0d - random.nextDouble();
a [i] = -1 * Math.log(a[i]);
s += a[i];
}
for (int i = 0; i < n; i++)
{
a [i] /= s;
}
return a;
}
``````

## generating a log normal distribution using R

By : Katelynn
Date : March 29 2020, 07:55 AM
it helps some times In R you can use rlnorm but why don't you use numpy and do it directly in Python.
Look at this document: http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.lognormal.html

## R: can 'mu' or 'Sigma' be vectorized in MASS::mvrnorm() when generating bivariate normal samples?

By : Oscar Eduardo Plaza
Date : March 29 2020, 07:55 AM
I hope this helps you . Consider the data below, , basic solution
No, it can't be vectorized. Write a for loop.
code :
``````v <- matrix(0, n, 2)
for (i in 1:n) {
sig11 <- sigma1[i]
sig21 <- rho * sqrt(sig11)
Sigma <- matrix(c(sig11, sig21, sig21, 1), 2)
v[i, ] <- mvrnorm(1, c(0,0), Sigma)
}
``````
``````sig11 ^ 2                rho * sig11 * sig22
rho * sig11 * sig22      sig22 ^ 2
``````
``````sig11          0
rho * sig22    sqrt(1 - rho ^ 2) * sig22
``````
``````# mu1, mu2, sig11, sig22, rho can be
## length-n vectors
## scalars
## vectors than can be recycled to be length-n
birnorm <- function (n, mu1, mu2, sig11, sig22, rho) {
x1 <- rnorm(n)
x2 <- rnorm(n)
z1 <- sig11 * x1 + mu1
z2 <- rho * sig22 * x1 + sqrt(1 - rho ^ 2) * sig22 * x2 + mu2
cbind(z1, z2)
}
``````
``````v <- birnorm(3, 0, 0, sqrt(sigma1), 1, 0.4)
``````
``````mvrnorm2 <- function (n, mu, Sigma) {
sig11 <- sqrt(Sigma[1])
sig22 <- sqrt(Sigma[4])
rho <- Sigma[2] / (sig11 * sig22)
birnorm(n, mu[1], mu[2], sig11, sig22, rho)
}
``````
``````mu <- c(0,0)
Sigma <- matrix(c(1,0.5,0.5,1),2)
library(microbenchmark)
microbenchmark(mvrnorm(1000, mu, Sigma), mvrnorm2(1000, mu, Sigma))
``````

## how to use mvrnorm for multiple mean vector in R

By : user3459195
Date : March 29 2020, 07:55 AM
wish help you to fix your issue You can create a sequence to subset mu at every column and sig1 every 3 columns and pass it to mvrnorm function.
code :
``````t(sapply(seq_len(ncol(mu)), function(x) {
ind <- (x - 1) * 3
MASS::mvrnorm(1,mu[,x],sig1[, (ind + 1):(ind + 3)])
}))

#       [,1]   [,2]   [,3]
#[1,] 1.0665 3.5964 4.4052
#[2,] 4.9421 9.7464 9.6109
``````

## Generating a binomial distribution around zero

By : Joachim
Date : March 29 2020, 07:55 AM
I wish this helpful for you What you're doing is fine if you want a "discretized" normal distribution centered around 0. If you want integer values, you should round n*p before subtracting.
But the limit of the binomial distribution is just the normal distribution when n becomes large and with p bounded away from 0 or 1. since n*p is not going to be an integer except for certain values, why not just use the normal distribution?