Displaying 20 results from an estimated 193 matches for "mvrnorm".
2004 Feb 02
3
mvrnorm problem
I am trying to simulate draws from a multivariate normal using mvrnorm, and
am getting the following error message:
Error in mu + eS$vectors %*% diag(sqrt(pmax(ev, 0)), p) %*% t(X) :
non-conformable arrays
I do not understand why I am getting this message, since the vector of means
I am giving to the function is 13 by 1 and the variance matrix I am...
2011 Jul 06
1
Create simulated data's using mvrnorm
Hi All
This might be something very trivial but I seem to miss something in the
syntax or logic which makes me keep wandering around the problem without
arriving at a solution.
What I want to do is to simulate a sample data for performing cluster
analysis. I tried to use
x1= mvrnorm(10,rep(0.8,3),diag(3))
x2= mvrnorm(10,rep(0,3),diag(3))
x3= mvrnorm(10,rep(-0.5,3),diag(3))
x=rbind(x1,x2,x3)
I would like use table() to see if the separation is wide apart such that
the first 10 rows of x are clustered together. for eg: when I use table()
and if I get an ouptut like
1...
2011 Jan 22
1
faster mvrnorm alternative
Hello,
does anybody know another faster function for random multivariate normal
variable simulation? I'm using mvrnorm, but as profiling shows, my algorithm
spends approximately 50 % in executing mvrnorm function.
Maybe some of you knows much faster function for multivariate normal
simulation?
I would be very gratefull for advices.
--
View this message in context: http://r.789695.n4.nabble.com/faster-mvrnorm-alte...
2005 May 01
2
eigen() may fail for some symmetric matrices, affects mvrnorm()
Hi all,
Recently our statistics students noticed that their Gibbs samplers were
crashing due to some NaNs in some parameters. The NaNs came from
mvrnorm (Ripley & Venables' MASS package multivariate normal sampling
function) and with some more investigation it turned out that they were
generated by function eigen, the eigenvalue computing function. The
problem did not seem to happen when the option "symmetric" was set to
FALSE...
2008 Jun 26
2
constructing arbitrary (positive definite) covariance matrix
Dear list,
I am trying to use the 'mvrnorm' function from the MASS package for
simulating multivariate Gaussian data with given covariance matrix.
The diagonal elements of my covariance matrix should be the same,
i.e., all variables have the same marginal variance. Also all
correlations between all pair of variables should be identical...
2011 May 07
1
generate multiple mvrnorm samples using apply-like
...below, I want values to have 3 columns: group, x, y
# number of groups, and group means
x <- jitter(seq(2,10,by=2))
y <- x + rnorm(length(x), 0, .5)
means <- cbind(x,y)
Sigma <- matrix(c(6,3,3,2),2,2)
# loop version
n<- 10
values <- NULL
for (i in 1:length(x)) {
val <- mvrnorm(n, means[i,], .5*Sigma, empirical=TRUE)
values <- rbind(values, val)
}
group <- factor(rep(letters[1:length(x)], each=n))
values <- cbind(group=group, values)
> str(values)
num [1:50, 1:3] 1 1 1 1 1 1 1 1 1 1 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$...
2012 Jun 10
2
mvrnorm limits
...owing commands to generate a given dataset:
a <-c(0.348,0.007,0.503,0.58,0.21)
cov <-c(0.0448,0,0,0,0,0.0001,0.0001,0,0,0,-0.0055,-0.0005,0.0495,0,0,0.0218,0.0009,-0.0253,0.1103,0,-0.0102,-0.0007,0.00631,0.0067,0.0132)
b <-matrix(cov,nrow=5, ncol = 5, byrow = TRUE,dimnames = NULL)
g <-mvrnorm(10000,a,b)
is there a way to place limits on the simulated values so that they all remain positive? I am simulating biological variables that should never be 0.
thnaks,
Andras
[[alternative HTML version deleted]]
2005 Jan 06
2
Generating Data mvrnorm and loops
Dear List:
I am generating N datasets using the following
Sigma<-matrix(c(400,80,80,80,80,400,80,80,80,80,400,80,80,80,80,400),4,4
)
mu<-c(100,150,200,250)
N=100
for(i in 1:N)
{
assign(paste("Data.", i, sep=''),
as.data.frame(cbind(seq(1:1000),(mvrnorm(n=1000, mu, Sigma)))))
}
With these datasets, I need to work on some of the variables and then
run each dataset through a linear model. I am having some trouble
working with variables within the loop and wonder if anyone can offer
any pointers.
The first thing I am trying to do is add 2 variabl...
2011 Aug 24
0
How to use mvrnorm?
Dear R community!
I would like to simulate distributions based on a polynomial model. It
consists of 96 values and I want to randomly select new normaly distributed
values around the modeled values. Furthermore, each value should be
correlated with the previous one. Is it correct to therefore use mvrnorm?
How do I define sigma?
Thank you very much for your help.
All the best,
Marianne
--
View this message in context: http://r.789695.n4.nabble.com/How-to-use-mvrnorm-tp3765225p3765225.html
Sent from the R help mailing list archive at Nabble.com.
2011 Feb 24
3
problem in for loop
...2 components?
library(MASS)
> p0 <- seq(0.1, 0.9,by=0.1)
> m <- 10
>
>
> p0 <- p0[7]
>
> ## data generation
>
> mzero <- p0*m
> mone <- m-mzero
> mu1 <- rnorm(mone, 0,1)
> mu <- c(rep(0,mzero), mu1)
>
> var <- diag(m)
> zv <- mvrnorm(n, mu, var)
Error in mvrnorm(n, mu, var) : incompatible arguments
> mone
[1] 3
> mu1
[1] -0.08802108 0.77904786
[[alternative HTML version deleted]]
2008 Jul 05
5
help about random generation of a Normal distribution of several variables
Hello.
Somebody knows how can I generate a set of n random vectors of a
normal distribution of several variables?
For example, I want to generate n=100 random vectors of two dimensions
for a normal with mean c(0,1) and variance matrix:
matrix(c(2,1,1,3),2,2).
Thanks in advance,
Arnau.
2003 May 06
4
Questons about R capabilities
...iable cannot vary from -infinity to +infinity, but are truncated and so are between two finite limits L1 and L2. Does R1.7 have this capability? If so what is (are) the relevant command(s)?
2) I am also interested in sampling from a multivariate normal distribution. I see that R has a command mvrnorm, but when I try to use it, I get a message to the effect that the command is not recognized. Is there something I must do to enable this command, or is it not available in version 1.7?
Thanks,
Howard
[[alternate HTML version deleted]]
2008 Nov 11
1
simulate data with binary outcome and correlated predictors
Hi,
I would like to simulate data with a binary outcome and a set of predictors that are correlated. I want to be able to fix the number of event (Y=1) vs. non-event (Y=0). Thus, I fix this and then simulate the predictors. I have 2 questions:
1. When the predictors are continuous, I can use mvrnorm(). However, if I have continuous, ordinal and binary predictors, I'm not sure how to simulate accurately the relationships between predictors.
2. To specify the coefficients of the regression of Y on predictors, I must specify separately the predictors for Y=1 and Y=0, I can vary the mean and...
2006 May 05
2
Including a single function from a package
Hello all.
I'm building a package where I want to include a function from two
different packages. In particular, I want to include mvrnorm and
hyperg_2F1 from MASS and gsl, respectively (but the specific functions
do not matter). With what I've tried after reading the "Specifying
imports and exports" section from the "Writing R Extensions" manual, I
get an error: "Namespace dependencies not required.&q...
2007 Mar 16
1
ideas to speed up code: converting a matrix of integers to a matrix of normally distributed values
...follow normal distributions (these effects can be correlated;
below I've set their correlation to .5). I have an entire matrix of
integers, and am converting those into two entire matrices of effects.
#HOW I'VE DONE IT SO FAR
To get the correlations between the effects, I've used the mvrnorm
function from "MASS"
To convert the allele names to genetic effects, I've created a
function (make.effect) that resets the set.seed() to the allele name
each time its called.
To get the matrix of genetic effects, I use sapply.
#THE PROBLEM
The problem is that I often need to conve...
2018 Mar 04
2
lmrob gives NA coefficients
Thanks for your reply.
I use mvrnorm from the *MASS* package and lmrob from the *robustbase*
package.
To further explain my data generating process, the idea is as follows. The
explanatory variables are generated my a multivariate normal distribution
where the covariance matrix of the variables is defined by Sigma in my
code, with on...
2004 Sep 22
5
Issue with predict() for glm models
[This email is either empty or too large to be displayed at this time]
2004 Jun 25
2
Simulating from a Multivariate Normal Distribution Using a Correlation Matrix
...to simulate randomly from a multivariate normal distribution using a correlation
matrix, rho. I do not have sigma. I have searched the help archive and the R documentation as
well as doing a standard google search. What I have seen is that one can either use rmvnorm in
the package: mvtnorm or mvrnorm in the package: MASS. I believe I read somewhere that the latter
was more robust. I have seen conflicting (or at least seemingly conflicting to me, a relative
statistics novice), views on whether one can use the correlation matrix with these commands
instead of the covariance matrix. I though...
2018 Mar 04
0
lmrob gives NA coefficients
What is 'd'? What is 'n'?
On Sun, Mar 4, 2018 at 12:14 PM, Christien Kerbert <
christienkerbert at gmail.com> wrote:
> Thanks for your reply.
>
> I use mvrnorm from the *MASS* package and lmrob from the *robustbase*
> package.
>
> To further explain my data generating process, the idea is as follows. The
> explanatory variables are generated my a multivariate normal distribution
> where the covariance matrix of the variables is defined by S...
2018 Mar 03
2
lmrob gives NA coefficients
...embers,
I want to perform an MM-regression. This seems an easy task using the
function lmrob(), however, this function provides me with NA coefficients.
My data generating process is as follows:
rho <- 0.15 # low interdependency
Sigma <- matrix(rho, d, d); diag(Sigma) <- 1
x.clean <- mvrnorm(n, rep(0,d), Sigma)
beta <- c(1.0, 2.0, 3.0, 4.0)
error <- rnorm(n = n, mean = 0, sd = 1)
y <- as.data.frame(beta[1]*rep(1, n) + beta[2]*x.clean[,1] +
beta[3]*x.clean[,2] + beta[4]*x.clean[,3] + error)
xy.clean <- cbind(x.clean, y)
colnames(xy.clean) <- c("x1", "x2&quo...