[R] Function for testing
R. Michael Weylandt
michael.weylandt at gmail.com
Thu Jun 21 16:49:51 CEST 2012
Hi, this has the distinctive sound of homework, so I hesitate to give
too much help, but two things I note immediately.
In defining resx / resy (good preallocation!) you probably mean "n"
instead of "N".
A standard way to check how often a condition occurs is something like:
x <- rnorm(50)
mean(x < 1) # Will give percentage of x values less than 1.
Hope this helps,
Michael
On Thu, Jun 21, 2012 at 8:24 AM, a.b.carter <a.b.carter at hotmail.com> wrote:
> Hi all,
>
> I want to create a sample called x, with length 10 from a N(0,1)
> distribution. Next to that I want to create a sample called y, with length
> 10 from a N(0.5 ,1) distribution. Both samples are undergoing a t.test.
> The outcome must be that I can see how many times for x H0 was rejected. The
> same for y. I am testing under a confidence level of 0.05
> Down below is the function I must use:
>
> pv=function(n=10,N=100,m=1,...){
> resx=numeric(N)
> resy=numeric(N)
> for (i in 1:N){
> x=rnorm(n)
> y=rnorm(n,m)
> resx[i]=t.test(x,...)[[3]]
> resy[i]=t.test(y,...)[[3]]
> }
> z=list(resx,resy)
> names(z)=c("px","py")
> z}
>
> So I compute pv(10,100,0.5) which gives me p-values in px and py. But
> somewhere I must give a statement (I think at the ... but that gives me
> errors) that px<0.05 so I can see how many times H0 was rejected. Thus, the
> values that are computed must be compared with the statement <0.05.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Function-for-testing-tp4634109.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.
More information about the R-help
mailing list