This is worse than before and getting pretty silly.  Now you are calling outer 
with a function that only takes one argument.  

R might be hard for you, but mind reading is even harder for most of us.  To 
get help you need to explain clearly and sensibly what it is you want to do.

Look at your code.  You generate (the same) random numbers every time and do 
not use them.  diag(cor(x,y)) is always a vector of ones.  So p is the same at 
every stage of the loop as well.  You put q_1 and q_2 inside the loop, but only 
use the outside.  This is not R, this is just a failure to think clearly about 
what you are doing.

-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of jethi
Sent: Sunday, 26 September 2010 5:29 PM
To: r-help@r-project.org
Subject: Re: [R] the function doesn´t work


hi, sorry but i can´t remove the problem.but i change the programm a little
bit. i didn´t work with r programm before, so its really hard for me to find
my problems. :) 


N=5
n=100


p_0=c(1/5,1-1/5)

power = function(k1) {
set.seed(1000)
H=matrix(0,nrow=N,ncol=1)

for(i in 1:N) {

 x <- matrix(rnorm(n, 0, 0.5), ncol =m1)
 y <- matrix(rnorm(n, 0, 0.8), ncol = m1)
 l <- diag(cor(x, y))



q_1 = qnorm(0.05, 0, 0.05)
   q_2 = qnorm(1 - 0.05, 0, 0.05)
p <- (l^2)/sum(l^2)

H[i] <- sum(p_0*log(p_0))  - sum(p * log(p))

}
1- mean(q_1 <= H & H <= q_2)

}
m1=seq(0,n/2,len=10)
k1=1/m1
output <- power(k1)
f=outer(k1,Vectorize(power))
-- 
View this message in context: 
http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714123.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

______________________________________________
R-help@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.

Reply via email to