r - Summarising results of repeated hypothesis tests -


i generating 2 sets of data normal distributions using rnorm(30, 10, 5). testing hypothesis means equal, using t.test, , repeating process 1000 times estimate type 1 error rate.

my code follows:

for(i in 1:1000) {   print(t.test(rnorm(30, 10, 5), rnorm(30, 10, 5),                alternative="two.sided", var.equal=true)$p.value < 0.05) } 

however, returns countless true , false.

i can manually count trues, there easier way?

they're not countless. there 1000 of them ;)

instead of printing result screen, should keep track of in vector.

a simple change want:

sig <- logical(length=1000) for(i in 1:1000) {   sig[i] <- t.test(rnorm(30, 10, 5), rnorm(30, 10, 5),                alternative="two.sided", var.equal=true)$p.value < 0.05 } 

now can tabulate results:

table(sig) ## sig ## false  true  ##   956    44 

a simpler approach use replicate:

table(replicate(1000, t.test(rnorm(30, 10, 5), rnorm(30, 10, 5),    alternative="two.sided", var.equal=true)$p.value < 0.05)) 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -