Hello, i wrote this function guete and now i want to plot it: but i get this error message. i hope someone can help me. Error in dim(robj) <- c(dX, dY) : dims [product 16] do not match the length of object [1] p_11=seq(0,0.3,0.1) p_12=seq(0.1,0.4,0.1) guete = function(p_11,p_12) { 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) } An other problem i have is when i define 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 i cannot solve this problem too. Thank you for your time and sorry for my english. I am from germany. Tuggi -- View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532074.html Sent from the R help mailing list archive at Nabble.com.
On Wed, Sep 8, 2010 at 2:33 PM, tuggi <tugbagueclue at web.de> wrote:> > Hello, > > i wrote this function guete and now i want to plot it: but i get this error > message. i hope someone can help me. > > Error in dim(robj) <- c(dX, dY) : > ?dims [product 16] do not match the length of object [1] > > p_11=seq(0,0.3,0.1) > p_12=seq(0.1,0.4,0.1) > guete = function(p_11,p_12) { > set.seed(1000) > S_vek=matrix(0,nrow=N,ncol=1)I notice you reference some variables in your function: N, n, q, p_0, k, L, f_1, f_2. Could you define those (and any others) for us? After struggling with this myself, I got into the habit of starting a new R session and testing the code I was going to email, before hand. It helps to notice missing variables, libraries that need to be loaded, etc.> 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)))One other minor point, if you assign: cbind(p_11, p_12, (1 - p_11 - p_12)) to a variable (*outside* the for loop), it should speed things up a bit (you use it 3 times every single loop, I think)> 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) > } > > An other problem i have is when i define > > 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 > > i cannot solve this problem too. > > Thank you for your time and sorry for my english. I am from germany.I'm sure it is much better than my German :-) Josh> > Tuggi > > -- > View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532074.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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
hello, thank you for your answer. here the parameter N=10 q=8 k=q-2 L=5 n=2*k+L+1 p_0=c(0.2,0.4,0.4) f_1=qf(0.05,2,2) f_2=qf(0.95,2,2) tuggi -- View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532132.html Sent from the R help mailing list archive at Nabble.com.
Does outer(p_11,p_12,Vectorize(guete)) do what you want? - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spector at stat.berkeley.edu On Wed, 8 Sep 2010, tuggi wrote:> > hello, > > thank you for your answer. here the parameter > > N=10 > > > q=8 > > > > k=q-2 > > > > L=5 > > > > n=2*k+L+1 > > > p_0=c(0.2,0.4,0.4) > > f_1=qf(0.05,2,2) > > > f_2=qf(0.95,2,2) > > tuggi > -- > View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532132.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. >
Great, that helps. With all those variables, your function worked for me. I did slightly edit it for testing, mostly just adding spaces to make it easier for me to read. N <- 10; q <- 8; k <- q-2; L <- 5; n <- 2 * k + L + 1 p_0 <- c(0.2, 0.4, 0.4) f_1 <- qf(0.05, 2, 2) f_2 <- qf(0.95, 2, 2) p_11 <- seq(0, 0.3, 0.1) p_12 <- seq(0.1, 0.4, 0.1) guete <- function(p_11, p_12) { set.seed(1000) S_vek <- matrix(0, nrow = N, ncol = 1) zz <- cbind(p_11, p_12, (1 - p_11 - p_12)) for(i in 1:N) { X_0 <- rmultinom(q - 1, size = 1, prob = p_0) X_1 <- rmultinom(n - q + 1, size = 1, prob = zz) 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 * zz)^2) / k * zz)) / (sum( ((N_0 - k * p_0)^2) / k * p_0)) ) - 1 } 1 - mean(f_1 <= S_vek & S_vek <= f_2) } guete(p_11 = p_11, p_12 = p_12) For your second problem: 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 the probabilities for rmultinom need to be non-negative. But when you do seq(0, 1, .1), you get some 1s in p_11 and p_12. This means part of your definition for the probs argument is (1 - 1 - 1) = -1. So you need to make sure that that maximum value of p_11 + p_12 is <= 1 (if you are going to subtract both from 1 and use that as a probability). Hope that helps, Josh On Wed, Sep 8, 2010 at 3:24 PM, tuggi <tugbagueclue at web.de> wrote:> > hello, > > thank you for your answer. here the parameter > > ?N=10 > > > ?q=8 > > > > ?k=q-2 > > > > ?L=5 > > > > ?n=2*k+L+1 > > > ?p_0=c(0.2,0.4,0.4) > > f_1=qf(0.05,2,2) > > > f_2=qf(0.95,2,2) > > tuggi > -- > View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532132.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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
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 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.
hello, i hope anyone can help me until tomorow, because i must give me bachelor theses on friday the prof. thanks tuggi -- View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532262.html Sent from the R help mailing list archive at Nabble.com.
The defintion of the sequency of probability was wrong!> p_11=seq(0,1,0.1) > p_12=seq(0,1,0.1)Since your multinomial distribution requires P_11, P_12, P13=1-P_11-P12 be greater than or equal to zero and P_11+P_12+P_13 = 1. In your above definition of P_11[6] =P_12[6]= 0.6, P_11[7] = P_12[7] = 0.7, ..., P_11[10] =P_12[10]=1.0. For these pairs 1-p_11-p_12 < 0! There is why you had the error message!> X_1=rmultinom(n-q+1,size=1,prob=cbind(p_11,p_12,(1-p_11-p_12)))Suggested Solution: Redefine P_11 and P_12 such that P_11[i] + P_12[i] <1 for all i! This will sove your problem! # you choose whatever a and b such that a+b<=1. for example, a = 0.4 b = 0.6 # you need to adjust the increaments to get vectors with equal length. p_11=seq(0,a,0.05*a) p_12=seq(0, b,0.05*b)> > > 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)) > f[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [1,] 1.0 0.9 0.9 0.8 0.8 0.7 0.6 0.6 0.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 0.5 [13,] 0.6 0.6 0.6 0.4 0.3 0.2 0.7 0.6 0.5 0.6 0.4 0.4 0.3 0.3 0.4 0.4 0.6 0.6 0.6 0.7 0.3 [14,] 0.4 0.6 0.6 0.4 0.1 0.7 0.7 0.5 0.6 0.6 0.5 0.4 0.3 0.3 0.4 0.5 0.6 0.5 0.6 0.6 0.2 [15,] 0.4 0.6 0.6 0.4 0.3 0.4 0.4 0.3 0.4 0.5 0.5 0.5 0.3 0.5 0.5 0.5 0.4 0.3 0.4 0.4 0.3 [16,] 0.7 0.3 0.3 0.2 0.2 0.2 0.1 0.1 0.2 0.1 0.1 0.2 0.2 0.1 0.1 0.2 0.1 0.1 0.0 0.3 0.2 [17,] 0.7 0.4 0.4 0.2 0.2 0.2 0.2 0.2 0.2 0.1 0.3 0.3 0.3 0.3 0.1 0.2 0.2 0.2 0.2 0.2 0.2 [18,] 0.8 0.3 0.3 0.2 0.2 0.2 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.2 0.2 0.2 0.3 [19,] 0.8 0.7 0.7 0.6 0.5 0.4 0.4 0.3 0.2 0.2 0.2 0.2 0.2 0.1 0.3 0.4 0.4 0.5 0.5 0.7 0.7 [20,] 0.6 0.4 0.3 0.2 0.3 0.3 0.3 0.3 0.2 0.3 0.3 0.3 0.2 0.3 0.3 0.3 0.3 0.3 0.2 0.3 0.4 [21,] 0.6 0.3 0.4 0.4 0.4 0.3 0.3 0.4 0.4 0.1 0.1 0.1 0.4 0.4 0.3 0.3 0.4 0.4 0.4 0.3 0.5 -- View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532282.html Sent from the R help mailing list archive at Nabble.com.
thank you for your answers, but my problem is that i want plot the function guete for the variables p_11 and p_12 between zero and one. that means that i also want to plot p_11=0.7 and p_12=0.3. but with a=0.4 and b=0.6 and p_11=seq(0,a,0.05*a) and p_12=seq(0,b,0.0*b) i cannot do that. i hope you have an other idea. tuggi -- View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532550.html Sent from the R help mailing list archive at Nabble.com.
Can you set the multinomial prob. to zero for p1+p2+p3 != 1 if you have to use the multinomial distribution in guete(). Otherwise, I would say the problem/guete() itself is problematic. -- View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2533050.html Sent from the R help mailing list archive at Nabble.com.
hello, i don not really understand what you me, sorry. can you describe what you mean. tuggi -- View this message in context: http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2533259.html Sent from the R help mailing list archive at Nabble.com.
On Wed, Sep 8, 2010 at 3:03 PM, Joshua Wiley <jwiley.psych at gmail.com> wrote: <snip>> I got into the habit of starting a > new R session and testing the code I was going to email, before hand. > It helps to notice missing variables, libraries that need to be > loaded, etc.It was rightly pointed out to me that the correct terminology here is "packages", not "libraries". It may be minor, but I wanted to correct my post so that inaccuracies are not propagated in the archives, and to prevent anyone "learning" from my mistake. Josh
Maybe Matching Threads
- getElementsBySelector problem in IE
- [LLVMdev] [Polly] Analysis of the expensive compile-time overhead of Polly Dependence pass
- [LLVMdev] [Polly] Analysis of the expensive compile-time overhead of Polly Dependence pass
- Integration of vector syntax unknown
- How odds ratio is computed in fisher.test()?