[R] the function doesn´t work

Joshua Wiley jwiley.psych at gmail.com
Sun Sep 26 21:43:34 CEST 2010


Dear Kaja,

I've read quite a few of your emails and spent some time trying to
understand what you want, and so have a lot of other people.  I know
this must be very frustrating for you especially because you have a
deadline soon.

I have noticed that in your emails, your explanations of what you are
trying to do are very similar, and for whatever reason, it does not
seem to be making sense to everyone on R-help.  Since sending us the
code you (and others) have written has not been working, I think it is
time for a change.  Three options come to mind.

1) Try to find someone near you to help (perhaps your thesis advisor,
a professor you know, a graduate student, etc.).  Many people in
academia use R and there are quite a few useR groups.  Also, many
universities have a statistical consulting center where you may be
able to seek some advice and help.

2)  Assuming that there is some formula or set of calculations you are
trying to have R do, can you show us what these are?  Most word
processors as well as LaTeX can typeset mathematical formulae, which
you could save to a PDF and upload online.  If we could see these,
perhaps we could point out what part of your code/function does not
match.  If you take this option, be sure to define what all the
variables are.

3) Another way would be to create a very simple dataset, and show all
the calculations you want done by hand.  For example, given the
vectors x = [1  3  2  4]    y = [1  2  3  4]  (I made this up, but you
should pick data that will work), what final result would you expect
from your function?  Knowing this would make it possible to evaluate
the results of your code and figure out why it differs from what you
need it to be.

Right now, we can point to other functions you could try, or make
little changes to your code 'till the cows come home (an Americanism,
I believe, at any rate, it means for a long time) and not get
anywhere.

Best wishes,

Josh

On Sun, Sep 26, 2010 at 12:57 AM, jethi <kartija at hotmail.com> wrote:
>
> 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 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