search for: dmvnorm

Displaying 20 results from an estimated 37 matches for "dmvnorm".

Did you mean: rmvnorm
2006 Jan 20
2
big difference in estimate between dmvnorm and dnorm, how come?
Dear R community, I was trying to estimate density at point zero of a multivariate distribution (9 dimensions) and for this I was using a multinormal approximation and the function dmvnorm , gtools package. To have a sense of the error I tried to look the mismatch between a unidimensional version of my distribution and estimate density at point zero with function density, dmvnorm and dnorm. At my big surprise dmvnorm and dnorm give very different result and dmvnorm match even bett...
2004 Oct 31
3
strange results with dmvnorm
I am experiencing strange results using dmvnorm. I define a scaled distance matrix from the coordinates bellow and then calculate a covariance matrix using a spherical correlation function. Then with certain combinations of range and sill parameters dmvnorm is returning values greater than 1. Surely the results of dmvnorm should be in the inte...
2013 Jun 06
1
dmvnorm
Summary: + I am writing an R extension that needs to call dmvnorm more than 10,000 times during a model fitting computation. + My extension uses openmp for parallel execution. + As of R 3.0, it is no longer permitted for threads to call the R interpreter because there is a stack overflow check that always trips because the thread's stack is different fro...
2010 Mar 13
2
dmvnorm masked by emdbook
I am using curve3d in the emdbook package to graph a gaussian copula density function generated via the copula package. Unfortunately, it appears that emdbook masks dmvnorm from the package mvtnorm in a way that prohibits copula from generating the gaussian copula. (Sounds very confusing!) For example, > library(copula) > f<-function(x,y) dcopula(normalCopula(0),c(x,y)) > library(emdbook) > curve3d(f) Error in dmvnorm(x, sigma = sigma) : unused argument...
2010 Jun 23
3
integrate dmvtnorm
Hello, everyone, I have a question about integration of product of two densities. Here is the sample code; however the mean of first density is a function of another random variable, which is to be integrated. ## f=function(x) {dmvnorm(c(0.6, 0.8), mean=c(0.75, 0.75/x))*dnorm(x, mean=0.6, sd=0.15)} integrate(f, lower=-Inf, upper=Inf) ## error message Error in dmvnorm(c(0.6, 0.8), mean = c(0.75, 0.75/x)) : mean and sigma have non-conforming size I think it's because the mean in dmvnorm is a function of x.... is there any...
2007 Feb 26
3
returns from dnorm and dmvnorm
Hi All, Why would calls to dnorm and dmvnorm return values that are above 1? For example, > dnorm(0.00003,mean=0, sd=0.1) [1] 3.989423 This is happening on two different installations of R that I have. Thank you. Hailu [[alternative HTML version deleted]]
2011 Aug 30
2
Multivariate Normal: Help wanted!
I have the following function, a MSE calc based on some Multivariate normals: MV.MSE<-function(n,EP,X,S){ (dmvnorm(X,mean=rep(0,2),I+S+EP)-dmvnorm(X,mean=rep(0,2),I+S))^2 + 1/n*(dmvnorm(X,mean=rep(0,2),1+S+EP/2)*det(4*pi*EP)^-.5- (dmvnorm(X,mean=rep(0,2),I+S+EP ))^2)} I can get the MV.MSE for given values of the function e.g MV.MSE(10,diag(0.5,2),c(.25,.25),diag(1,2)) But I would li...
2009 Nov 18
2
Error "system is computationally singular" by using function dmvnorm
Dear R users, i try to use function dmvnorm(x, mean, sigma, log=FALSE) from R package mvtnorm to calculate the probability of x under the multivariate normal distribution with mean equal to mean and covariance matrix sigma. I become the following Error in solve.default(cov, ...) : system is computationally singular: reciprocal condition n...
2001 Aug 30
1
MCMC coding problem
...n <- ntimes/1000 - 1 meanmat <- matrix(0,nrow=len,ncol=d) quantmat <- array(0, dim = c(3,d,len)) count <- 0 # print("Comment out the browser before running with ntimes large!!") browser() for (i in 1:(ntimes-1)) { ystar <- rmvnorm(n=1,mu=y[i,],sigma=phi) numer <- (w*dmvnorm(ystar,mu=rep(0,d),sigma=diag(0,d)) + (1-w)*dmvnorm(ystar,mu=rep(mean,d),sigma=diag(varwt,d)))*dmvnorm(y[i,],mu=ys tar,sigma=phi) denom <- (w*dmvnorm(y[i,],mu=rep(0,d),sigma=diag(0,d)) + (1-w)*dmvnorm(y[i,],mu=rep(mean,d),sigma=diag(varwt,d)))*dmvnorm(ystar,mu=y[ i,],sigma=phi) prob <- nume...
2012 Apr 25
2
comparison of bivariate normal distributions
...ize what I mean hear a little code example: ######################################## library(mvtnorm) c<-data.frame(rnorm(1000,5,sd=1),rnorm(1000,6,sd=1)) c2<-data.frame(rnorm(1000,10,sd=2),rnorm(1000,7,sd=1)) xx=seq(0,20,0.1) yy=seq(0,20,0.1) xmult=cbind(rep(yy,201),rep(xx,each=201)) dens=dmvnorm(xmult,mean(c),cov(c)) dmat=matrix(dens,ncol=length(yy),nrow=length(xx),byrow=F) dens2=dmvnorm(xmult,mean(c2),cov(c2)) dmat2=matrix(dens2,ncol=length(yy),nrow=length(xx),byrow=F) contour(xx,yy,dmat,lwd=2) contour(xx,yy,dmat2,lwd=2,add=T) ############################################## Is their an e...
2008 Oct 01
2
Bivariate normal
Package mvtnorm provides dmvnorm, pmvnorm that can be used to compute Pr(X=x,Y=y) and Pr(X<x,Y<y) for a bivariate normal. Are there functions that would compute Pr(X<x,Y=y)? I'm currently using "integrate" with dmvnorm but it is too slow.
2009 May 22
0
EM algorithm mixture of multivariate
...d) library(MASS) n=100 m1=c(5,-5) m2=c(-3,3) s1=matrix(c(2,1,1,3), 2,2) s2=matrix(c(4,1,1,6), 2,2) alpha=0.3 c1 <- mvrnorm(round(n*alpha),m1,s1) c2 <- mvrnorm(round(n*(1-alpha)),m2,s2) allval <- rbind(c1,c2) x <- allval[sample(n,n),] mixm<- function(x,m1,m2,s1,s2, alpha) { f1<-dmvnorm(x, m1, s1, log=FALSE) f2<-dmvnorm(x, m2, s2, log=FALSE) f=alpha*f1+(1-alpha)*f2 f } plot(x) den<-mixm(x,m1,m2,s1,s2,alpha) scatterplot3d(x[,1],x[,2],den, highlight.3d=TRUE, col.axis="blue", col.grid="lightblue",angle=120, pch=20) em2mn<- function(y...
2009 May 22
0
EM algorithm mixture of multivariate gaussian
...d) library(MASS) n=100 m1=c(5,-5) m2=c(-3,3) s1=matrix(c(2,1,1,3), 2,2) s2=matrix(c(4,1,1,6), 2,2) alpha=0.3 c1 <- mvrnorm(round(n*alpha),m1,s1) c2 <- mvrnorm(round(n*(1-alpha)),m2,s2) allval <- rbind(c1,c2) x <- allval[sample(n,n),] mixm<- function(x,m1,m2,s1,s2, alpha) { f1<-dmvnorm(x, m1, s1, log=FALSE) f2<-dmvnorm(x, m2, s2, log=FALSE) f=alpha*f1+(1-alpha)*f2 f } plot(x) den<-mixm(x,m1,m2,s1,s2,alpha) scatterplot3d(x[,1],x[,2],den, highlight.3d=TRUE, col.axis="blue", col.grid="lightblue",angle=120, pch=20) em2mn<- function(y...
2008 Mar 23
2
problem with 'install.packages'
...FUN(c("mvtnorm", "tools")[[2L]], ...) : DESCRIPTION file of package 'mvtnorm' is missing or broken > ####################################### ## ## Concurrent Rterm session ## ####################################### R version 2.6.2 (2008-02-08) <snip> > dmvnorm(1:2) [1] 0.01306423 [1] ".GlobalEnv" "package:mvtnorm" "package:stats" [4] "package:graphics" "package:grDevices" "package:utils" [7] "package:datasets" "package:methods" "Autoloads"...
2013 Oct 20
5
nlminb() - how do I constrain the parameter vector properly?
Greets, I'm trying to use nlminb() to estimate the parameters of a bivariate normal sample and during one of the iterations it passes a parameter vector to the likelihood function resulting in an invalid covariance matrix that causes dmvnorm() to throw an error. Thus, it seems I need to somehow communicate to nlminb() that the final three parameters in my parameter vector are used to construct a positive semi-definite matrix, but I can't see how to achieve this using the constraint mechanism provided. Additional details are provide...
2008 Mar 22
1
Vectorization Problem
I have the code for the bivariate Gaussian copula. It is written with for-loops, it works, but I wonder if there is a way to vectorize the function. I don't see how outer() can be used in this case, but maybe one can use mapply() or Vectorize() in some way? Could anyone help me, please? ## Density of Gauss Copula rho <- 0.5 #corr R <- rbind(c(1,rho),c(rho,1)) #vcov matrix id <-
2009 Jun 22
1
The gradient of a multivariate normal density with respect to its parameters
...el (with some bugs) if possible. Here?s a simple example of the result I?d like, using numerical differentiation: library(mvtnorm) library(numDeriv) f=function(pars, xx, yy) { mu=pars[1:2] sig1=pars[3] sig2=pars[4] rho=pars[5] sig=matrix(c(sig1^2,rho*sig1*sig2,rho*sig1*sig2,sig2^2),2) dmvnorm(cbind(x,y),mu,sig) } mu1=1 mu2=2 sig1=3 sig2=4 rho=.5 x=2 # or a x vector y=3 # or a y vector jacobian(f,c(mu1,mu2,sig1,sig2,rho),xx=x,yy=y) # (Can replace ?jacobian? with ?grad? if x and y have length 1.) -- Karl Ove Hufthammer
2013 Jan 28
1
Adding 95% contours around scatterplot points with ggplot2
...points by "level" to capture the different density distributions without the visualization being heavily influenced by outliers. I have looked into the code provided here from Hadley https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/85q4SQ9q3V8 using the mvtnorm package and the dmvnorm function, but haven't been able to get it work for my data example. The calculated densities are always zero (at this step of Hadley's code: dgrid$dens <- dmvnorm(as.matrix(dgrid), ex_mu, ex_sigma) ) I appreciate any assistance. Thanks, Nate x<-c(seq(0.15,0.4,length.out=30),seq(0...
2020 Jun 04
2
mclust package installation is preparing for lazy loading and never finishes
...installing *source* package ?mclust? ... ** package ?mclust? successfully unpacked and MD5 sums checked ** using staged installation ** libs gfortran -fno-optimize-sibling-calls -fpic -g -O2 -fdebug-prefix-map=/build/r-base-Do_dS_/r-base-4.0.0=. -fstack-protector-strong -c dmvnorm.f -o dmvnorm.o gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-Do_dS_/r-base-4.0.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c init.c -o init.o gfortran -fno-optimize-...
2008 Mar 23
2
scaling problems in "optim"
Dear R users, I am trying to figure out the control parameter in "optim," especially, "fnscale" and "parscale." In the R docu., ------------------------------------------------------ fnscale An overall scaling to be applied to the value of fn and gr during optimization. If negative, turns the problem into a maximization problem. Optimization is performed on