Sounds like homework (you are not supposed to post homework-related questions here - read the guidelines). But anyway:
nr.of.rejections=0 for(i in 1:10000){ x=rnorm(10, 0.1, 1) result<-t.test(x,alternative="greater",mu=0,conf.level=0.95)$p.value if(result<0.05) nr.of.rejections = nr.of.rejections+1 } print(paste("Observed number of rejections of Ho:", nr.of.rejections, sep=" ")) observed.rejection.rate = nr.of.rejections/10000 print(paste("Actual rejection rate of Ho:", observed.rejection.rate, sep=" ")) However, it's not Type 1 error rate. It's the observed rejection rate. Type 1 error is probability of rejecting Ho when it is actually TRUE. And in your case (x = rnorm(10,0.1,1) your null hypothesis (that mean = 0) is NOT true because,as you know, in the population the mean is 0.1. Dimitri On Wed, May 5, 2010 at 2:31 PM, level <lev_lamb...@hotmail.co.uk> wrote: > > I have been set a question which i understand statistically but my > inability > with R is preventing me from finishing it.. > > My question is that we to calculate the frequency of Type 1 errors > > starting with x = rnorm(10, 0.1, 1) > > then doing a t-test seeing whether you reject the null hypothesis (Ho mu > = > 0) alternative is mu > 0 > > Then i am supposed to use a for loop to do this procedure 10 000 times > keeping track whether the null has been rejected or not. If anyone can > help > with me it would be great help > > cheers > > -- > View this message in context: > http://r.789695.n4.nabble.com/T-test-for-loop-tp2131458p2131458.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. > -- Dimitri Liakhovitski Ninah.com dimitri.liakhovit...@ninah.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.