For this project I am required to use an R script to simulate the effectiveness of the t-test. I must use a for loop will be used to carry out the following 2000 times:
Would the loop look something like this
i <- 1
for (i <= 2001) {
x <-rf(5,df1=5,df2=10)
b <- df2
p.value <-t.test(x,mu=(b/(b-2))$p.value
i <- i+1
}
In the way you wrote it, it would be a “while” loop.
For loops in R have the following syntax:
Additionally, it might be more efficient to employ an “apply” construct, for example with replicate, and include the df as function arguments:
This is not always true, but it simplifies the recovery of the p.values.