Hi, I' am 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")tests<-c("t","Wil!
 coxon")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)}}}}

A prize an hour, 24 hours a day. Try Big Snap now! 
_________________________________________________________________
[[elided Hotmail spam]]

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

Reply via email to