I am trying to plot the power function of a sign test. The code I have is already this one:
library(BSDA) # for SIGN.test()
M_values <- seq(-1, 1, by = 0.1)
sign_rank_test_p<-vector("numeric",length=length(M_values))
sign_test_p<-vector("numeric", length=length(M_values))
n<-1000
lower_bounds <- matrix(nrow=n,ncol=length(M_values))
upper_bounds <- matrix(nrow=n,ncol=length(M_values))
center <- matrix(nrow=n,ncol=length(M_values))
for (i in seq_along(M_values)) {
for (j in 1:n){
M <- M_values[i]
value <- rnorm(1, mean = M, sd = 1)
lower_bounds[j,i] <- value-0.01
upper_bounds[j,i] <- value+0.01
center[j,i] <- (lower_bounds[j,i] + upper_bounds[j,i]) / 2
}
sign_test_p[i]<-SIGN.test(center[,i],md=0,alternative = "greater")$p.value
sign_rank_test_p[i]<-wilcox.test(center[,i], mu = 0, alternative = "greater")$p.value
}
# Create a data frame to store the results
results_df <- data.frame(M = M_values,
sign_test_p_value = sign_test_p,
signed_rank_test_p_value = sign_rank_test_p)
This gives the p values for the sign test. We generated 1000 p-values for values of M that is between -1 and 1.
What I want now is to plot the power function for the sign test and take some conclusions about it but I dont know how to do it. Is it with pwr.r.test or power.sign.test?