| plot.findn | R Documentation |
Plot of a findn Object
## S3 method for class 'findn'
plot(x, min_n = 1, max_n = NULL, power_lim = 0.95, ...)
x |
object of class |
min_n |
lower limit of the x-axis. |
max_n |
upper limit of the x-axis. The default is |
power_lim |
if |
... |
Further arguments. |
None.
# Function that simulates the outcomes of a two-sample t-test
ttest <- function(mu1 = 0, mu2 = 1, sd, n, k) {
sample1 <- matrix(rnorm(n = ceiling(n) * k, mean = mu1, sd = sd),
ncol = k)
mean1 <- apply(sample1, 2, mean)
sd1_hat <- apply(sample1, 2, sd)
sample2 <- matrix(rnorm(n = ceiling(n) * k, mean = mu2, sd = sd),
ncol = k)
mean2 <- apply(sample2, 2, mean)
sd2_hat <- apply(sample2, 2, sd)
sd_hat <- sqrt((sd1_hat^2 + sd2_hat^2) / 2)
teststatistic <- (mean1 - mean2) / (sd_hat * sqrt(2 / n))
crit <- qt(1 - 0.025, 2*n - 2)
return(mean(teststatistic < -crit))
}
# Create a findn object
res.ttest <- findn(fun = ttest, targ = 0.8, k = 25, start = 100,
init_evals = 100, r = 4, stop = "evals", max_evals = 2000,
level = 0.05, var_a = 0.05, var_b = 1, alpha = 0.025,
alternative = "one.sided", sd = 2, verbose = FALSE)
# plot with default settings
plot(res.ttest, power_lim = 0.95)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.