Package 'powerbydesign'

Title: Power Estimates for ANOVA Designs
Description: Functions for bootstrapping the power of ANOVA designs based on estimated means and standard deviations of the conditions. Please refer to the documentation of the boot.power.anova() function for further details.
Authors: Frank Papenmeier [aut, cre]
Maintainer: Frank Papenmeier <[email protected]>
License: GPL (>= 3)
Version: 1.0.5
Built: 2024-11-23 05:18:24 UTC
Source: https://github.com/cran/powerbydesign

Help Index


Bootstrap the Power of an ANOVA Design

Description

This function bootstraps the power of each effect in an ANOVA design for a given range of sample sizes. Power is computed by randomly drawing samples from a multivariate normal distribution specified according to the values supplied by the design.anova object. Power is defined as the proportion of bootstrap iterations the p-values of each effect lie below the supplied alpha level. Note that this function runs many ANOVAs which might be slow for large sample size ranges or bootstrap iterations (see Details below). Further note that this function does not check for assumptions such as sphericity.

Usage

boot.power.anova(design, n_from, n_to, num_iterations_bootstrap, alpha = 0.05)

Arguments

design

object of type design.anova

n_from

numeric, lower boundary of sample size range (inclusive) ; Refers to N per between condition

n_to

numeric, upper boundary of sample size range (inclusive) ; Refers to N per between condition

num_iterations_bootstrap

numeric, number of bootstrap iterations for each sample size

alpha

numeric, alpha level

Details

Note that this function requires the computation of many ANOVAs and therefore becomes slow with increasing sample size ranges and bootstrap iterations. It is therefore suggested to first use a very low number of bootstrap iterations, such as 10, in order to determine a sensible sample size range for the power of interest. Once done, use this small sample size range and dramatically increase the bootstrap iterations, such as 3000, in order to determine more reliable power estimates. Because the power-by-samplesize function is monotonically increasing, a zigzag of power values with increasing sample sizes indicates that the selected bootstrap iterations are too low.

Value

list containing power-by-samplesize data.frames for each effect

See Also

design.anova, plot.power_by_samplesize

Examples

## Not run: 
design <- design.anova(
   between = list(age = c("young","old"),
                  sex = c("male","female")),
   within = list(condition = c("cond1","cond2","cond3")),
   default_within_correlation = 0.7
)

power_by_samplesize <- boot.power.anova(
   design,
   n_from = 40,
   n_to = 60,
   num_iterations_bootstrap = 1000
)

plot(power_by_samplesize,
     crit_power = 0.9,
     plot_dir = "power_plots")

## End(Not run)

Define an ANOVA Design

Description

Constructs an "design.anova" object required by the boot.power.anova function.

Usage

design.anova(
  between = list(),
  within = list(),
  default_within_correlation = 0,
  save_input_as = NULL,
  silent_load = FALSE
)

Arguments

between

list, between-subjects factors including its levels

within

list, within-subjects factors including its levels

default_within_correlation

numeric, default within-subjects correlation the correlation matrix is populated with (for designs including within-subjects factors)

save_input_as

character, file name prefix of the files the input values entered by the user are save to. File names are constructed as paste0(save_input_as,"_cor_matrix.csv") and paste0(save_input_as,"_means_and_sds.csv")

silent_load

boolean, FALSE (default): always show input dialogs (even if data was successfully loaded from a file); TRUE: show input dialogs only if file did not yet exist and break with error if data from file does not match the design

Details

Based on the supplied within-subjects factors and between-subjects factors, this function constructs all conditions of the ANOVA design and opens two dialog windows querying for the expected correlation matrix and cell means (+ standard deviations) for all conditions.

The first dialog window queries for the correlation matrix of the conditions. If you have a pure between-subjects design, you may instantly close this window. Otherwise, enter the expected correlations between all conditions that include within-subjects manipulations. Using the "default_within_correlation" parameter, a default value can be set. You should fill in only the lower triangle of the correlation matrix and only the values not containing NAs.

The second dialog window queries for the means and standard deviations expected for each condition.

Use the "save_input_as" parameter in order to define a file name prefix of the files where the function saves your input values. This will populate the dialog windows with the saved values on the next execution of this function. If the parameter is NULL, input values will not be saved. NOTE: You must delete the respective files if you want to change the design.

Value

object of type design.anova

See Also

boot.power.anova

Examples

## Not run: 
design <- design.anova(
   between = list(age = c("young","old"),
                  sex = c("male","female")),
   within = list(condition = c("cond1","cond2","cond3")),
   default_within_correlation = 0.7,
   save_input_as = "myexp1",
   silent_load = T
)

## End(Not run)

Plot Power Results

Description

Plots the power-by-samplesize data.frames returned by the power functions.

Usage

## S3 method for class 'power_by_samplesize'
plot(x, crit_power = NULL, plot_dir = NULL, ...)

Arguments

x

list, results of a power function

crit_power

numeric, critical power value one is looking for (adds a line and the critical sample size to the plot)

plot_dir

character, name of an existing directory where the power plots should be saved to (leaving it NULL will plot to the default device)

...

additional parameters, not used at the moment

See Also

boot.power.anova