[R] the function doesn´t work

2010-09-26 Thread jethi

hey, my function doesn´t work. can somebody help me?
the graphic doesn´t work and also the function. thnx a lot.

N=10
n=100

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

power = function(p,m) {
set.seed(1000)
H=matrix(0,nrow=N,ncol=1)
for(i in 1:N) {
 x - matrix(rnorm(n, 0, 0.5), ncol = m)
 y - matrix(rnorm(n, 0, 0.8), ncol = m)
 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)
}
m=seq(10,50,len=10)
f=outer(p,m,Vectorize(power))
persp(p,m,power,theta=-50,phi=30,d=4,border=black)
-- 
View this message in context: 
http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714105.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.


Re: [R] the function doesn´t work

2010-09-26 Thread jethi

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.


Re: [R] the function doesn´t work

2010-09-26 Thread jethi

i´m really sorry, once again. ok i will try to explain what i have to
programm. i want to programm a powerfunction. 
i have to research if the correlations in a bivariate random sample are
homogeneous.  for that i saperate the random sample in m blocks and
calculate the correlation of each block(partial sample). than i look at the
random variable p=cor(x1,y1)^2/sum(cor(x,y)^2) which is a probability. my
null hypothesis is that all correlations are homogeneous. if we have this
situation the entropy take the value log(m).
my test based on the entropy. so my teststatic is H=log(m)-sum(p*log(p)). 
the following programm was actually, which i have worked the most of the
time. i hope that i don´t confuse u too much.
i of course i hope u understand my problem and my theme.
n=1000
m=2
k=n/m
N=100
myfun - function(n, m, alpha = .05, seeder = 1000) {
l=matrix(0,nrow=m,ncol=N)
for(i in 1:N){
set.seed(i)
for(j in 1:m){
x=rnorm(n,0,0.5)
y=rnorm(n,0,0.8)
l[j,i]=cor((x[(((j-1)*k)+1):(((j-1)*k)+k)]),
(y[(((j-1)*k)+1):(((j-1)*k)+k)]))
}
}

gute - function(x,m) {
q_1 - qnorm(alpha, 0, 0.05)
 
q_2 - qnorm(1 - alpha, 0, 0.05)
 
p=matrix(0,nrow=m,ncol=N)
H=matrix(0,nrow=N,ncol=1)
for(i in 1:N){
for (j in 1:m){
p[j,i]=x[j]^2/sum(x[,i]^2)
}
H[i]=log(m)-sum(p[,i]*log(p[,i]))
}
   1 - mean(q_1 = H  H = q_2)
}
output - gute(x = l,m=m)
 return(output)
}

-- 
View this message in context: 
http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714137.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.


Re: [R] the function doesn´t work

2010-09-26 Thread jethi

thanks a lot for ur patience and understandig, josh. ok perhaps it would be
help me to change my programm by step by step. the first important thing of
my programm is to caluculate the correlation of each block of a radom
variable. 

so i have a n bivariate random sample wich i saperate in m blocks and
calculate the correlation. i  designe a matrix for that. so that i watch not
one n bivariate random sample, but N bivariate random sample. (its important
to watch a matrix because for my powerfunction later)

so i programm my correlationfunction like that

N=10
n=100
m=5
k=n/m
l=matrix(0,nrow=m,ncol=N)
for(i in 1:N){

for(j in 1:m){
x=rnorm(n,0,0.5)
y=rnorm(n,0,0.8)
l
l[j,i]=cor((x[(((j-1)*k)+1):(((j-1)*k)+k)]),
(y[(((j-1)*k)+1):(((j-1)*k)+k)]))
}
}
 i think their is  a mistake, am i right? if i watch this matrix, i don´t
exactliy know which correlations are to which random sample, do i? i hope u
have still time to help me.

regards 
jethi


-- 
View this message in context: 
http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714702.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.


Re: [R] the function doesn´t work

2010-09-26 Thread jethi

thnx again. now i understand my big problem. ok so now a want to watch the
probabilities p, which are do this for example
p[1,1]=cor(x1,y1)/(cor(x1,y1)+..+cor(xm,ym)).


so 
N = 10
n = 100
m = 2
k = n/m
l = matrix(0,nrow=m,ncol=N)
p=matrix(0,nrow=m,ncol=N)

for(i in 1:N){
  x=rnorm(n,0,0.5)
  y=rnorm(n,0,0.8)
  for(j in 1:m){
l[j,i] = cor(
   (x[(((j-1)*k)+1):(((j-1)*k)+k)]),
   (y[(((j-1)*k)+1):(((j-1)*k)+k)]))
   

  }
} 
for(i in 1:N){
for (j in 1:m){
p[j,i]=l[j,i]^2/sum(l[,i]^2)
}
}



i didn´t write the matrix in the first loop with l, because if i do that,
he takes at first only the first value. and then the first and the second
value of l. so its wrong. because of it i take a new two loops which make
exactly what i want.

regards
jethi

-- 
View this message in context: 
http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714755.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.


Re: [R] the function doesn´t work

2010-09-26 Thread jethi

hi josh, and really thnx again.

i have now 2 problems . the first one ist if i take ur idea and programm
like u:

N = 10
n = 100
m = 2
k = n/m
l = matrix(0,nrow=m,ncol=N)
p=matrix(0,nrow=m,ncol=N)

alpha = 0.05
q_1 - qnorm(alpha, 0, 0.05)
q_2 - qnorm(1 -alpha, 0, 0.05)
for(i in 1:N){
  x=rnorm(n,0,0.5)
  y=rnorm(n,0,0.8)
  for(j in 1:m){
l[j,i] = cor(
   (x[(((j-1)*k)+1):(((j-1)*k)+k)]),
   (y[(((j-1)*k)+1):(((j-1)*k)+k)]))
   

  }
} 


for(i in 1:N){
for (j in 1:m){
p[j,i]=l[j,i]^2/sum(l[,i]^2)
}
}

p2 - apply(l, 2, function(z) {(z^2)/sum(z^2)})
identical(p, p2)

H=matrix(0,nrow=N,ncol=1)
for(i in 1:N){
H[i]=log(m)-sum(p[,i]*log(p[,i]))
}
H1-apply(p2,2,function(t){(log(m)-sum(t*log(t)))})
identical(H1, H)


it gives me, that identical(H1, H) is False. is it because of H? H is a
matrix and H1 is a list, isn´t it?
ok if i leave H1 out and programm further to get my powerfunction, it gives
me always the value 1. even i change my alpha or the number of n, m or N.:


N = 10
n = 100
m = 2
k = n/m
l = matrix(0,nrow=m,ncol=N)
p=matrix(0,nrow=m,ncol=N)

alpha = 0.05
q_1 - qnorm(alpha, 0, 0.05)
q_2 - qnorm(1 -alpha, 0, 0.05)
for(i in 1:N){
  x=rnorm(n,0,0.5)
  y=rnorm(n,0,0.8)
  for(j in 1:m){
l[j,i] = cor(
   (x[(((j-1)*k)+1):(((j-1)*k)+k)]),
   (y[(((j-1)*k)+1):(((j-1)*k)+k)]))
   

  }
} 
for(i in 1:N){
for (j in 1:m){
p[j,i]=l[j,i]^2/sum(l[,i]^2)
}
}

p2 - apply(l, 2, function(z) {(z^2)/sum(z^2)})
identical(p, p2)

H=matrix(0,nrow=N,ncol=1)
for(i in 1:N){
H[i]=log(m)-sum(p[,i]*log(p[,i]))
}
1-mean(q_1=H  H =q_2)

regards
jethi


-- 
View this message in context: 
http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714815.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.


Re: [R] the function doesn´t work

2010-09-26 Thread jethi

wow thnx a lot josh. so now i understand the most of the things. so my power
function is depent on the number of the blocks m. how u said, if i take
m=0.8 or lower i get a different value than a 1. ofcourse  a number between
0 or 1. but i can just take positive interger number for m, because m
representet die value for the blocks and they could be only a positiv
number. moreover the graphic show that my H will never reach log(m) because
like u said p are probilities. so if i would now plot the powerfunction for
different m(positiv integer), the graph would be a constant value. am i
right?

thank u very very much. its help me a lot.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714875.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.


Re: [R] Power Function

2010-09-25 Thread jethi


hi, the part with the power function does not work. this is the   gute  
function in my programm. because i´m not shure on what dependet my power 
function gute. and ofcourse the graphik does not work. thnx a lot:)

regards
Kaja

Date: Fri, 24 Sep 2010 19:21:17 -0700
From: ml-node+2653667-1721823656-167...@n4.nabble.com
To: kart...@hotmail.com
Subject: Re: Power Function



Hi,


What part of your code does not work or does not do what you want?  I

am guessing that you want gute to return more than a single value

(which is what it does in your code).  Can you show us an example of

the results you would like?


Best regards,


Josh




I reworked some of your code to simplify, clean, and wrap it all in a function:


myfun - function(n, m, alpha = .05, seeder = 1000) {

  set.seed(seeder)

  x - matrix(rnorm(n, 0, 0.5), ncol = m)

  y - matrix(rnorm(n, 0, 0.8), ncol = m)

  l - diag(cor(x, y))

  cat(Correlations between two random variables \n, l, fill = TRUE)

  gute - function(x, m, alpha) {

q_1 - qnorm(alpha, 0, 0.05)

q_2 - qnorm(1 - alpha, 0, 0.05)

p - (x^2)/sum(x^2)

H - log(m) - sum(p * log(p), na.rm = TRUE)

1 - mean(q_1 = H  H = q_2)

  }

  dat - seq(0, 1, length.out = 10)

  output - gute(x = dat, m = m, alpha = alpha)

  return(output)

}


This results in:


 myfun(100, 5)

Correlations between two random variables

 -0.5887829 0.07042411 -0.06082638

0.2395193 -0.1038213

[1] 1



On Fri, Sep 24, 2010 at 5:26 PM, jethi [hidden email] wrote:



 Hi, at first, i´m from germany, so sorry for my bad english. but i need ur

 help in R to programm a power function  and to make at last a graphik of it.



 i have already tried my best. but it doesn´t work.the topic is: the

 homogeneity test of correlation based entropy.



 so it means, that i have to check if all correlations of a bivariate random

 vectors are same or not. for that i saperate the  n bivariate random vectors

 (x1,y1),...,(xn,yn)  in blocks  m so, so that i at first calculate  the

 correlation in a  block. n=m*k. the numbers of the blocks m are

 user-defined. the test value is the entropy. pls help me!!!





 set.seed(1000)

 n=100

 m=5

 k=n/m



 x=rnorm(n,0,0.5)

 y=rnorm(n,0,0.8)





  #alpha/2 Quantil

  q_1=qnorm(0.05,0,0.05)



  #1-alpha/2 Quantile

  q_2=qnorm(0.95,0,0.05)





  l=matrix(0,nrow=m,ncol=1)

 for(i in 1:m){





 l[i]=print(cor((x[(((i-1)*k)+1):(((i-1)*k)+k)]),

 (y[(((i-1)*k)+1):(((i-1)*k)+k)])))





 }

 güte=function(l){

 p=matrix(0,nrow=m,ncol=1)

 for(i in 1:m){

 p[i]=l[i]^2/sum(l^2)



 }

 H=log(m)-sum(p*log(p))

 1-mean(q_1=H  H =q_2)

 }





 l=seq(0,1,len=10)











 plot(l,güte, type=o,pch=20,ylim=c(0,1),col=red)

 --

 View this message in context: 
 http://r.789695.n4.nabble.com/Power-Function-tp2631929p2631929.html
 Sent from the R help mailing list archive at Nabble.com.



 __

 [hidden email] 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/

__

[hidden email] mailing list


PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.







View message @ 
http://r.789695.n4.nabble.com/Power-Function-tp2631929p2653667.html


To unsubscribe from Power Function, click here.


  
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Power-Function-tp2631929p2694493.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
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.


Re: [R] Power Function

2010-09-25 Thread jethi

hey, how can i plot this function?

n=1000
m=2
k=n/m
N=100
myfun - function(n, m, alpha = .05, seeder = 1000) {
l=matrix(0,nrow=m,ncol=N)
for(i in 1:N){
set.seed(i)
for(j in 1:m){
x=rnorm(n,0,0.5)
y=rnorm(n,0,0.8)
l[j,i]=cor((x[(((j-1)*k)+1):(((j-1)*k)+k)]),
(y[(((j-1)*k)+1):(((j-1)*k)+k)]))
}
}

gute - function(x) {
q_1 - qnorm(alpha, 0, 0.05)
 
q_2 - qnorm(1 - alpha, 0, 0.05)
 
p=matrix(0,nrow=m,ncol=N)
H=matrix(0,nrow=N,ncol=1)
for(i in 1:N){
for (j in 1:m){
p[j,i]=x[j]^2/sum(x[,i]^2)
}
H[i]=log(m)-sum(p[,i]*log(p[,i]))
}
   1 - mean(q_1 = H  H = q_2)
}
output - gute(x = l)
 return(output)
}

regards
jethi
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Power-Function-tp2631929p2713799.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] 3D plot

2010-09-25 Thread jethi

hey, how can i plot this function??? thanks for ur help

n=1000
m=2
k=n/m
N=100
myfun - function(n, m, alpha = .05, seeder = 1000) {
l=matrix(0,nrow=m,ncol=N)
for(i in 1:N){
set.seed(i)
for(j in 1:m){
x=rnorm(n,0,0.5)
y=rnorm(n,0,0.8)
l[j,i]=cor((x[(((j-1)*k)+1):(((j-1)*k)+k)]),
(y[(((j-1)*k)+1):(((j-1)*k)+k)]))
}
}

for(i in 1:N){
for (j in 1:m){
gute - function() {
q_1 - qnorm(alpha, 0, 0.05)
 
q_2 - qnorm(1 - alpha, 0, 0.05)
 
p=matrix(0,nrow=m,ncol=N)
H=matrix(0,nrow=N,ncol=1)

p[j,i]=x[j]^2/sum(x[,i]^2)
}
H[i]=log(m)-sum(p[,i]*log(p[,i]))
}
   1 - mean(q_1 = H  H = q_2)
}
output - gute(a = l[,i])
 return(output)
}

regards 
jethi
-- 
View this message in context: 
http://r.789695.n4.nabble.com/3D-plot-tp2713818p2713818.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.


Re: [R] 3D plot

2010-09-25 Thread jethi

hi steve, thnx for ur reply. but my problem is, that i have a matrix as a
functions value and as a result i get a single number. so  how can i plot
this? and it would be nice if u read over my function, because i´m not sure
if it correct. anyway thnx
regards 
jethi
-- 
View this message in context: 
http://r.789695.n4.nabble.com/3D-plot-tp2713818p2713856.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.


Re: [R] 3D plot

2010-09-25 Thread jethi

hey,  is there anybody who can help me? its very urgent because i have to
send my bachelor thesis on monday. pls help me
-- 
View this message in context: 
http://r.789695.n4.nabble.com/3D-plot-tp2713818p2713909.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] Power Function

2010-09-24 Thread jethi

Hi, at first, i´m from germany, so sorry for my bad english. but i need ur
help in R to programm a power function  and to make at last a graphik of it.

i have already tried my best. but it doesn´t work.the topic is: the
homogeneity test of correlation based entropy. 

so it means, that i have to check if all correlations of a bivariate random
vectors are same or not. for that i saperate the  n bivariate random vectors 
(x1,y1),...,(xn,yn)  in blocks  m so, so that i at first calculate  the
correlation in a  block. n=m*k. the numbers of the blocks m are 
user-defined. the test value is the entropy. pls help me!!!


set.seed(1000)
n=100
m=5
k=n/m

x=rnorm(n,0,0.5)
y=rnorm(n,0,0.8)


 #alpha/2 Quantil
 q_1=qnorm(0.05,0,0.05) 
 
 #1-alpha/2 Quantile
 q_2=qnorm(0.95,0,0.05)


 l=matrix(0,nrow=m,ncol=1)
for(i in 1:m){


l[i]=print(cor((x[(((i-1)*k)+1):(((i-1)*k)+k)]),
(y[(((i-1)*k)+1):(((i-1)*k)+k)])))


}
güte=function(l){
p=matrix(0,nrow=m,ncol=1)
for(i in 1:m){
p[i]=l[i]^2/sum(l^2)

}
H=log(m)-sum(p*log(p))
1-mean(q_1=H  H =q_2)
}


l=seq(0,1,len=10)





plot(l,güte, type=o,pch=20,ylim=c(0,1),col=red)
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Power-Function-tp2631929p2631929.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.