0
$\begingroup$

i want to calculate the type i error rate and power for the correlation test for bivariate normal data using Monte Carlo simulation.

But i am getting unexpected values for the type I error and for power. (type I error as 0.864)

i need to know whether i have done some mistake. Can anyone help me?

set.seed(160230)
library("mvtnorm", lib.loc="~/R/win-library/3.4")
sigma= matrix(c(1,0.8,0.8,1),2,2) 
mu <- c(0,0)
#bivariate normal data
sim=replicate(n=1000 , rmvnorm(10,mean=mu , sigma = sigma))

pval1=c()

for(i in 1:1000)
{
 pval1[i]=cor.test(sim[,1,i],sim[,2,i],method = c("pearson"))$p.value

  }
#type1 error rate
mean(pval1<0.05)

#power
mean(pval3>0.05)
$\endgroup$
  • $\begingroup$ As it is your question seems to deal with code, but I think you may be after something more conceptual. So I would kindly suggest you include your results and your interpretation. $\endgroup$ – Antoni Parellada Jun 19 '18 at 23:06
  • $\begingroup$ @AntoniParellada Thank you for the reply. I am not getting any error. I am getting type I error rate as 0.864 , which is very large. $\endgroup$ – Sam88 Jun 19 '18 at 23:09
  • $\begingroup$ Normally type I error rate should be small. But in my case it is very large. I want to know whether it is due to any mistake i did . I am not sure whether my code to get the type I error rate is correct. Specifically $ mean(pval1<0.05) $ $\endgroup$ – Sam88 Jun 19 '18 at 23:16
  • 2
    $\begingroup$ If you change that sample size from 10 to 100, you will get a mean(pval1<0.05) of 1, which is what you expect when you introduce a high linear correlation between the samples - i.e. the p.values are uniformly lower than 0.05, because the correlation is different from zero. $\endgroup$ – Antoni Parellada Jun 19 '18 at 23:46
  • 2
    $\begingroup$ I see that, but just go through carefully, and you'll get it. The code is fine, but your interpretation of the results is not. See, if your interest is in the type I errors, your simulation is a miniature world where you can fabricate the data to your liking. Being that type I errors are the consequence of rejecting the null when the null is actually correct, you may want to simulate samples from a population where there is indeed no correlation. $\endgroup$ – Antoni Parellada Jun 20 '18 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.