Icewaffle
Icewaffle

Reputation: 19

plot create cutoff line at particular point

consider the following plot:

pwrt<-pwr.t.test(d=.8,n=c(10,20,30,40,50,60,70,80,90,100),sig.level=.05,type="two.sample",alternative="two.sided")

plot(pwrt$n,pwrt$power,type="b",xlab="sample size",ylab="power", main = "Power curve for t-test d = .8")

which creates

enter image description here

I would like to add a vertical line as a 'cutoff' point at power = .9 for example. And also to compute the exact x-value (sample size) for this cutoff point

How do I do this? Any help is much appreciated.

Upvotes: 0

Views: 432

Answers (1)

Ian Campbell
Ian Campbell

Reputation: 24818

You can calculate the sample size for a given power with the same pwr.t.test function.

From help(pwr.t.test):

Exactly one of the parameters 'd','n','power' and 'sig.level' must be passed as NULL, and that parameter is determined from the others.

library(pwr)
N90 <- pwr.t.test(d=.8,power = 0.9,sig.level=.05,type="two.sample",alternative="two.sided")$n
N90
[1] 33.82555

From there, it's simple to add a line and text label.

plot(pwrt$n,pwrt$power,type="b",xlab="sample size",ylab="power", main = "Power curve for t-test d = .8")
abline(v = N90)
text(x = N90 + 7, y = 0.8, labels = paste0("N = ",round(N90,2)))

enter image description here

Upvotes: 1

Related Questions