[R] the function doesn´t work
jethi
kartija at hotmail.com
Mon Sep 27 02:13:23 CEST 2010
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.
More information about the R-help
mailing list