[R] FW:

From: Louisa Hay <louisahay_at_msn.com>
Date: Sat, 12 Apr 2008 12:04:20 +0100

Hi, I'm doing a stats project using R to work out the size of a t-test and wilcoxon test depending on the distribution and sample size. I just can't get it to work - I want to put my results from the function size() into an array.At the moment I keep getting the error message:Error in res[distribution, test, samplesize] <- results : subscript out of boundsCan anyone tell me where I'm going wrong, please?! size.power.test<-function(){k<-1000distributions<-c("Normal","Uniform")tests<-c("t","Wilcoxon")samplesizes<-c(10,30,40)res<-array(0,c(length(distributions),length(tests),length(samplesizes)))dimnames(res)<-list(distributions,tests,samplesizes)for(distribution in distributions){for(test in tests){for(samplesize in samplesizes){for(i in 1:k){results<-size()res[distribution,test,samplesize]<-results}output<-size.power.testreturn(output)}}}}size<-function(k=1000,H0=0,mu.true=0,sigma.true=1,alpha=0.05,                x1=-sqrt(3),y1=sqrt(3)){distributions<-c("Normal","Uniform")te!
 sts<-c("t","Wilcoxon")samplesizes<-c(10,30,40)reject1<-numeric(k)for(distribution in distributions){for(test in tests){for(samplesize in samplesizes){for(i in 1:k){if(distribution=="Normal"){#randomly generate data from normal distribution with true meandat<-rnorm(n=samplesize,mean=mu.true,sd=sigma.true)}else{#randomly generate data from a uniform distributiondat<-runif(samplesize,min=x1,max=y1)}if(test=="t"){#perform a t-test on sampleres<-t.test(dat,alternative="two.sided",mu=H0)#record if p-value is less than alphareject1[i]<-(res$p.value<=alpha)}else{#perform a wilcoxon-test on sampleres<-wilcox.test(dat,alternative="two.sided",mu=H0)#record if p-value is less than alphareject1[i]<-(res$p.value<=alpha)}}output<-list(sum(reject1)/k)return(output)}}}}

News, Sports, Entertainment and Weather on your mobile. Text MSN to 63463 Now.

Welcome to the next generation of Windows Live

        [[alternative HTML version deleted]]

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. Received on Sat 12 Apr 2008 - 11:09:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Apr 2008 - 11:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive