So this is my updated code but for some reason when I plot Power (P1) against the theta values i'm not getting the correct plot, instead i'm getting a flat line.
c1 <- 1.5
c2 <- 6
n <- 10
set.seed(1) #Ensures same random numbers are generated each time
P1 <- vector("numeric", length = 1000) #Create vector for first power function
P2 <- vector("numeric", length = 1000) #Create vector for second power function
TS1 <- vector("numeric", length = 1000) #Create vector for first test statistic
TS2 <- vector("numeric", length = 1000) #Create vector for second test statistic
for (theta in seq(0,2)) {
for (i in 1:1000) {
y <- rnorm(1000, theta, 1) #Generate random values of y from normal distribution using mean = theta, sd = 1
TS1[i] = mean(y)*sqrt(n)/(sd(y)) #Define first test statistic
TS2[i] = sum(y > 0) #Define second test statistic
}
P1[theta] <- mean(TS1 > c1) #Calculates power for each test statistic for power function 1
P2[theta] <- mean(TS2 > c2) #Calculates power for each test statistic for power function 2
}
thetaVals <- seq(0, 2, length.out =1000)
plot(thetaVals, P1, type ="p", xlab ="theta")
plot(thetaVals, P2, type ="p", xlab ="theta")