Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

If statement in hypothesis testing with a normal distribution

I have this code that does a hypothesis test that tests H0: mu = 0.3 against H1: mu > 0.3.
I am asked to estimate the probability of the test leading to the non-rejection of H0 when mu = 1.1. I wanted to do an if statement as followed but I don’t know what argument I should use from the t.test

set.seed(1343)
m = 0
accept = 0
valores = numeric(0)
while (m != 150){
  amostra <- rnorm(27, mean = 1.1, 2.8)
  x <- t.test(amostra, mu = 0.3, alternative = "greater", conf.level = 0.96)
  if  (something){
    accept = accept + 1
  }
  m = m + 1
}
prob = accept/m

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Instead of updating the total in the loop, run the loop, save the p-values and after the loop compute the mean of a logical condition. FALSE/TRUE are coded as 0/1 so you will have the proportion you want.

set.seed(1343)
m <- 150
pval <- numeric(m)
for(i in seq_along(pval)) {
  amostra <- rnorm(27, mean = 1.1, 2.8)
  x <- t.test(amostra, mu = 0.3, alternative = "greater", conf.level = 0.96)
  pval[i] <- x$p.value
}
prob <- mean(pval > 0.05)
prob
#> [1] 0.6

Created on 2022-12-07 with reprex v2.0.2

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading