[R] problem with outer

David Winsemius dwinsemius at comcast.net
Thu Sep 9 04:29:31 CEST 2010


On Sep 8, 2010, at 6:59 PM, tuggi wrote:

>
> hello,
>
> tank you very very much. it solves my first problem. i hope you can  
> help me
> also with the second problem.
> it was like this.
>
>
> p_11=seq(0,1,0.1)
> p_12=seq(0,1,0.1)
> then i get also this error message:
> Error in rmultinom(n - q + 1, size = 1, prob = rbind(p_11, p_12, (1  
> -  :
>  non-positive probability

It seems to be a very informative error message. The first element of  
seq(0,1,0.1) is going to be zero and rmultinom doesn't accept non-zero  
probabilities. If you would explain what you _were_ trying to  
accomplish it might be possible to say more, but without some  
explication we would be "stumbling around in the dark". Furthermore I  
wonder whether you really meant to offer a matrix to rmultinom for  
probabilities? The help page says "prob" should be a vector.

OK, I will stumble around:
If you want one random draw one one item from into n-q+1 equally  
probable bins, then wouldn't you use:

rmultinom(n - q + 1, size = 1, prob = rep(0.1, 10) )
 > rmultinom(1, size = 1, prob = rep(0.1, 10) )
       [,1]
  [1,]    0
  [2,]    0
  [3,]    0
  [4,]    0
  [5,]    0
  [6,]    0
  [7,]    0
  [8,]    0
  [9,]    1
[10,]    0

If you want 10 draws:

 >  rmultinom(10, size = 1, prob = rep(0.1, 10) )
       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,]    1    0    0    0    0    0    0    0    0     1
  [2,]    0    0    0    0    0    0    0    0    0     0
  [3,]    0    1    1    0    0    0    0    0    0     0
  [4,]    0    0    0    1    0    0    0    0    0     0
  [5,]    0    0    0    0    0    0    0    0    1     0
  [6,]    0    0    0    0    0    0    0    0    0     0
  [7,]    0    0    0    0    1    1    0    0    0     0
  [8,]    0    0    0    0    0    0    1    0    0     0
  [9,]    0    0    0    0    0    0    0    1    0     0
[10,]    0    0    0    0    0    0    0    0    0     0

And if you want 1 sample of 100 items:
 >  rmultinom(1, size = 100, prob = rep(0.1, 10) )
       [,1]
  [1,]   10
  [2,]   10
  [3,]   12
  [4,]   12
  [5,]    8
  [6,]   11
  [7,]    9
  [8,]    6
  [9,]    7
[10,]   15

But as I said that's a WAG at where you might be having problems.

-- 
David.

>
> i try to solve this problem with a if  order like this:
>
> p_11=seq(0,1,0.1)
> p_12=seq(0,1,0.1)
> guete = function(p_11,p_12) { if(p_11+p_12<1)
> set.seed(1000)
> S_vek=matrix(0,nrow=N,ncol=1)
> for(i in 1:N) {
> X_0=rmultinom(q-1,size=1,prob=p_0)
> X_1=rmultinom(n-q+1,size=1,prob=cbind(p_11,p_12,(1-p_11-p_12)))
> N_0=apply(X_0[,(n-2*k-L+1):(n-k-L)],1,sum)
> N_1=apply(X_1[,(n-q-k+2):(n-q+1)],1,sum)
> S_vek[i]=((sum(((N_1-k*cbind(p_11,p_12,(1-p_11-p_12)))^2)/ 
> k*cbind(p_11,p_12,(1-p_11-p_12))))/(sum(((N_0-k*p_0)^2)/k*p_0)))-1
> }
> 1-mean(f_1<=S_vek & S_vek <=f_2)
> }
>
>
> f=outer(p_11,p_12,Vectorize(guete))
>
> but i get the error message:
> Error  in rmultinom(n - q + 1, size = 1, prob = cbind(p_11, p_12, (1  
> -  :
>  non-positive probability.
>
> thank for your helps.
> Tuggi
>
>
> -- 
> View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532157.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list