[R] problem with outer

Joshua Wiley jwiley.psych at gmail.com
Thu Sep 9 00:03:41 CEST 2010


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/



More information about the R-help mailing list