An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120314/e22f773c/attachment.pl>
qmvnorm function
4 messages · Li Li, Rui Barradas
Hello, li li-13 wrote
Dear all, I need to use the "qmvnorm" function in mtvnorm package. Here is the error message I got
qmvnorm(0.05, tail="upper", sigma=var)$quantile
Error in uniroot(pfct, interval = interval) : f() values at end points not of opposite sign There is no problem for 50th quantile.
qmvnorm(0.5, tail="upper", sigma=var)$quantile
[1] -0.5325527 Can anyone give some hint regarding this? Thanks. [[alternative HTML version deleted]]
______________________________________________ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
The problem seems to be in the value of 'var'.
qmvnorm(0.05, tail="upper", sigma=diag(2))$quantile
[1] 0.7600695
qmvnorm(0.05, tail="upper", sigma=diag(5))$quantile
[1] -0.123829
From these results, there is nothing intrisically wrong with the quantile
0.05. In the error message, 'uniroot' is not in an interval with a guaranteed solution, maybe the parameter 'interval' of 'qmvnorm' will put it in the right track. Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/qmvnorm-function-tp4473262p4473364.html Sent from the R help mailing list archive at Nabble.com.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120314/e57a17a7/attachment.pl>
Hello,
Thanks Rui. Sorry I forgot to mention what is the "var" in the previous message. It seems that when the correlation is small, it does not work. See below.
It works in my system: (your first example)
var <- matrix(c(1,0.05,0.05,1), nrow=2, ncol=2, byrow=T)
var
[,1] [,2]
[1,] 1.00 0.05
[2,] 0.05 1.00
qmvnorm(0.05, tail="upper", sigma=var)$quantile
[1] 0.7934487
It also worked with the other two examples. System? Package version?
My system is
R.version
_ platform i386-pc-mingw32 version.string R version 2.14.1 (2011-12-22) And the package mvtnorm version is 0.9-9991, the current CRAN is 0.9-9992 Anyway, I've tried it with the 'interval' parameter. Note the difference in iterations to convergence #var <- matrix(c(1,0.05,0.05,1), nrow=2, ncol=2, byrow=T) #var qmvnorm(0.05, tail="upper", sigma=var) $quantile [1] 0.7934487 $f.quantile [1] -2.719625e-07 attr(,"error") [1] 1e-15 attr(,"msg") [1] "Normal Completion" $iter [1] 12 $estim.prec [1] 6.103516e-05 qmvnorm(0.05, interval=c(0, 5), tail="upper", sigma=var) $quantile [1] 0.793449 $f.quantile [1] -3.152414e-07 attr(,"error") [1] 1e-15 attr(,"msg") [1] "Normal Completion" $iter [1] 9 $estim.prec [1] 6.103516e-05 Your problem seems to be with, at least, 'uniroot'. Give it a help and it might work. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/qmvnorm-function-tp4473262p4473638.html Sent from the R help mailing list archive at Nabble.com.