jerome@hivnet.ubc.ca
2003-Jan-21 01:43 UTC
[Rd] package mvtnorm: sigma parameter in pmvnorm() (PR#2478)
Full_Name: Jerome Asselin Version: 1.6.2 OS: RedHat Linux 7.2 Submission from: (NULL) (142.103.173.179) pmvnorm() may fail for a univariate distribution when its parameter "sigma" is defined as a matrix. It will fail if sigma < 1. library(mvtnorm) #THIS WORKS> pmvnorm(lower=-Inf,upper=2,mean=0,sigma=matrix(1.5))[1] 0.9487648 attr(,"error") [1] 0 attr(,"msg") [1] "univariate: using pnorm" #THIS FAILS> pmvnorm(lower=-Inf,upper=2,mean=0,sigma=matrix(.5))Error in checkmvArgs(lower = lower, upper = upper, mean = mean, corr = corr, : diag(sigma) and lower are of different length #THIS WORKS> pmvnorm(lower=-Inf,upper=2,mean=0,sigma=.5)[1] 0.9976611 attr(,"error") [1] 0 attr(,"msg") [1] "univariate: using pnorm"
Torsten Hothorn
2003-Jan-21 09:33 UTC
[Rd] package mvtnorm: sigma parameter in pmvnorm() (PR#2478)
On Tue, 21 Jan 2003 jerome@hivnet.ubc.ca wrote:> Full_Name: Jerome Asselin > Version: 1.6.2 > OS: RedHat Linux 7.2 > Submission from: (NULL) (142.103.173.179) > > > > pmvnorm() may fail for a univariate distribution when > its parameter "sigma" is defined as a matrix. It will > fail if sigma < 1. >confirmed and fixed in mvtnorm_0.5-8, soon at CRAN. Thanks for the report! Please do NOT file a bug report for contributed packages with priority less than "recommended" since the package maintainers do not have write access to the bugs-database anyway. Moreover, cc the report to the maintainer (which is the default way of reporting bugs in packages). Best, Torsten> library(mvtnorm) > > #THIS WORKS > > pmvnorm(lower=-Inf,upper=2,mean=0,sigma=matrix(1.5)) > [1] 0.9487648 > attr(,"error") > [1] 0 > attr(,"msg") > [1] "univariate: using pnorm" > > #THIS FAILS > > pmvnorm(lower=-Inf,upper=2,mean=0,sigma=matrix(.5)) > Error in checkmvArgs(lower = lower, upper = upper, mean = mean, corr = corr, : > diag(sigma) and lower are of different length > > #THIS WORKS > > pmvnorm(lower=-Inf,upper=2,mean=0,sigma=.5) > [1] 0.9976611 > attr(,"error") > [1] 0 > attr(,"msg") > [1] "univariate: using pnorm" > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-devel > >
ligges@statistik.uni-dortmund.de
2003-Jan-21 09:49 UTC
[Rd] package mvtnorm: sigma parameter in pmvnorm() (PR#2478)
jerome@hivnet.ubc.ca wrote:> Full_Name: Jerome Asselin > Version: 1.6.2 > OS: RedHat Linux 7.2 > Submission from: (NULL) (142.103.173.179) > > > > pmvnorm() may fail for a univariate distribution when > its parameter "sigma" is defined as a matrix. It will > fail if sigma < 1. > > library(mvtnorm) > > #THIS WORKS > >>pmvnorm(lower=-Inf,upper=2,mean=0,sigma=matrix(1.5)) > > [1] 0.9487648 > attr(,"error") > [1] 0 > attr(,"msg") > [1] "univariate: using pnorm" > > #THIS FAILS > >>pmvnorm(lower=-Inf,upper=2,mean=0,sigma=matrix(.5)) > > Error in checkmvArgs(lower = lower, upper = upper, mean = mean, corr = corr, : > diag(sigma) and lower are of different length > > #THIS WORKS > >>pmvnorm(lower=-Inf,upper=2,mean=0,sigma=.5) > > [1] 0.9976611 > attr(,"error") > [1] 0 > attr(,"msg") > [1] "univariate: using pnorm"The bug is in checkmvArgs(): if (!is.null(sigma)) { if (!is.matrix(sigma)) { if (length(sigma) == 1) UNI <- TRUE if (length(sigma) != length(lower)) stop("diag(sigma) and lower are of different length") } else { + if (length(diag(sigma)) != length(lower)) + stop("diag(sigma) and lower are of different length") if (length(sigma) == 1) { UNI <- TRUE sigma <- sigma[1,1] } - if (length(diag(sigma)) != length(lower)) - stop("diag(sigma) and lower are of different length") } } The fix is to change the position of the validation, i.e. before the matrix is coerced to a vector of length 1. Uwe Ligges