Re: [R] question regarding qmvnorm

From: Rolf Turner <rolf.turner_at_xtra.co.nz>
Date: Thu, 21 Apr 2011 10:50:37 +1200

On 21/04/11 09:59, li li wrote:
> Dear all,
> I wrote the following function previously. It worked fine with the old
> mvtnorm package.
> Somehow with the updated package, I got a error message when trying to use
> the function.
> I need some help. It is sort of urgent. Can anyone please take a look. The
> function is the following.
> Thank you very much!
> Hannah

(1) In the first instance you should probably contact the maintainer of the mvtnorm package:

     require(utils)
     maintainer("mvtnorm")

(2) The code you enclosed indicates that you don't understand anything about functions. You have m, rho, k, and alpha given as *arguments* to your function, and yet you specify them explicitly within the body of the function. This makes no sense at all.

If you are going to do something it pays to *understand* what you are doing rather than just slapping down some code at random and hoping that it will work.

Delete the first four (non-blank!) lines of your code and then call

cc_f(10,0.1,2,0.5)

This does indeed throw an error --- from uniroot(). As I say, contact the package maintainer.

     cheers,

         Rolf Turner

> library(mvtnorm)
>
> cc_f<- function(m, rho, k, alpha) {
>
> m<- 10
>
> rho<- 0.1
>
> k<- 2
>
> alpha<- 0.05
>
>
> cc_z<- numeric(m)
>
> var<- matrix(c(1,rho,rho,1), nrow=2, ncol=2, byrow=T)
>
> for (i in 1:m){
>
> if (i<= k) {cc_z[i]<- qmvnorm((k*(k-1))/(m*(m-1))*alpha, tail="upper",
> sigma=var)$quantile} else
>
> {cc_z[i]<- qmvnorm((k*(k-1))/((m-i+k)*(m-i+k-1))*alpha, tail
> ="upper", sigma=var)$quantile}
>
> }
>
> cc<- 1-pnorm(cc_z)
>
> return(cc)
>
> }



R-help_at_r-project.org 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. Received on Wed 20 Apr 2011 - 23:02:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Apr 2011 - 23:20:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive