[R] question regarding qmvnorm

Rolf Turner rolf.turner at xtra.co.nz
Thu Apr 21 00:50:37 CEST 2011


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)
>
>                               }



More information about the R-help mailing list