Package 'retrodesign'

Title: Tools for Type S (Sign) and Type M (Magnitude) Errors
Description: Provides tools for working with Type S (Sign) and Type M (Magnitude) errors, as proposed in Gelman and Tuerlinckx (2000) <doi:10.1007/s001800000040> and Gelman & Carlin (2014) <doi:10.1177/1745691614551642>. In addition to simply calculating the probability of Type S/M error, the package includes functions for calculating these errors across a variety of effect sizes for comparison, and recommended sample size given "tolerances" for Type S/M errors. To improve the speed of these calculations, closed forms solutions for the probability of a Type S/M error from Lu, Qiu, and Deng (2018) <doi:10.1111/bmsp.12132> are implemented. As of 1.0.0, this includes support only for simple research designs. See the package vignette for a fuller exposition on how Type S/M errors arise in research, and how to analyze them using the type of design analysis proposed in the above papers.
Authors: Andrew Timm [cre, aut], Andrew Gelman [ctb, cph], John Carlin [ctb, cph], Martijn Weterings [ctb]
Maintainer: Andrew Timm <[email protected]>
License: MIT + file LICENSE
Version: 0.2.2
Built: 2025-02-18 06:12:54 UTC
Source: https://github.com/andytimm/retrodesign

Help Index


retro_design: Calculates Power, Type S, and Type M error

Description

This function name is deprecated in favor of the more clearly named retro_design_closed_form; it won't be removed in any hurry, just trying to move the naming conventions to be clearer and easier to use.

Usage

retro_design(A, s, alpha = 0.05)

Arguments

A

a numeric or list, an estimate of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

Details

Calculates Power, Type S, and Type M error and returns them in a list or df, depending on whether a single true effect size or range is provided. Uses the closed form solution found for the Type-M error found by Lu et al. (2018), and thus is faster than retrodesign. For t distributions, use retrodesign() instead; the closed form solution only applies in the normal case.

Value

either a list of length 3 containing the power, type s, and type M error, or if A is a list, a df that is 4 by length(A), with an effect size and it's corresponding power, type s, and type m errors in each row.

Examples

retrodesign(1,3.28)
retrodesign(list(.2,2,20),8.1)

retro_design_closed_form: Calculates Power, Type S, and Type M error

Description

Calculates Power, Type S, and Type M error and returns them in a list or df, depending on whether a single true effect size or range is provided. Uses the closed form solution found for the Type-M error found by Lu et al. (2018), and thus is faster than retrodesign. For t distributions, use retrodesign() instead; the closed form solution only applies in the normal case.

Usage

retro_design_closed_form(A, s, alpha = 0.05)

Arguments

A

a numeric or list, an estimate of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

Value

either a list of length 3 containing the power, type s, and type M error, or if A is a list, a df that is 4 by length(A), with an effect size and it's corresponding power, type s, and type m errors in each row.

Examples

retrodesign(1,3.28)
retrodesign(list(.2,2,20),8.1)

List retro_design_closed_form

Description

retro_design_closed_form.list is the S3 method of the generic retro_design_closed_form() function, used when a list is passed for A.

Usage

## S3 method for class 'list'
retro_design_closed_form(A, s, alpha = 0.05)

Arguments

A

a list, estimates of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

Value

A df that is 4 by length(A), with an effect size and it's corresponding power, type s, and type m errors in each row.

Examples

retro_design(list(.2,2,20),8.1)

Numeric retro_design_closed_form

Description

retro_design_closed_form.numeric is the S3 method of the generic retro_design_closed_form() function, used when a single numeric is passed for A.

Usage

## S3 method for class 'numeric'
retro_design_closed_form(A, s, alpha = 0.05)

Arguments

A

a numeric, an estimate of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

Value

A list of length 3 containing the power, type s, and type M error.

Examples

retrodesign(1,3.28)
retrodesign(2,8.1)

retrodesign: Calculates Power, Type S, and Type M error

Description

Calculates Power, Type S, and Type M error and returns them in a list or df, depending on whether a single true effect size or range is provided. retro_design() is faster as it uses the closed form solution from Lu et al. (2018), but this function can be used for t distributions, whereas retro_design() cannot. Function originally provided in Gelman and Carlin (2014), modified with permission.

Usage

retrodesign(A, s, alpha = 0.05, df = Inf, n.sims = 10000)

Arguments

A

a numeric or list, an estimate of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

df

a numeric, the degrees of freedom. df=Inf is equivalent to a normal distribution.

n.sims

a numeric, how many times to simulate when calculating Type M error.

Value

either a list of length 3 containing the power, type s, and type M error, or if A is a list, a df that is 4 by length(A), with an effect size and it's corresponding power, type s, and type m errors in each row.

Examples

retrodesign(1,3.28)
retrodesign(list(.2,2,20),8.1)
retrodesign(.5,1,df=10)

List retrodesign

Description

retrodesign.list is the S3 method of the generic retrodesign() function, used when a list is passed for A.

Usage

## S3 method for class 'list'
retrodesign(A, s, alpha = 0.05, df = Inf, n.sims = 10000)

Arguments

A

a list, estimates of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

df

a numeric, the degrees of freedom. df=Inf is equivalent to a normal distribution.

n.sims

a numeric, how many times to simulate when calculating Type M error

Value

A df that is 4 by length(A), with an effect size and it's corresponding power, type s, and type m errors in each row.

Examples

retrodesign(list(.2,2,20), 8.1)
retrodesign(list(.2,2,20), 8.1,df = 10)

Numeric retrodesign

Description

retrodesign.numeric is the S3 method of the generic retrodesign() function, used when a single numeric is passed for A. Martijn Weterings kindly provided code to slightly improve this in the very low N case using the non-central t-distribution.

Usage

## S3 method for class 'numeric'
retrodesign(A, s, alpha = 0.05, df = Inf, n.sims = 10000)

Arguments

A

a numeric, an estimate of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

df

a numeric, the degrees of freedom. df=Inf is equivalent to a normal distribution.

n.sims

a numeric, how many times to simulate when calculating Type M error

Value

A list of length 3 containing the power, type s, and type M error.

Examples

retrodesign(1,3.28)
retrodesign(2,8.1)
retrodesign(.5,1,df=10)

sim_plot: visualize type S/M errors

Description

Graphs type S/M errors resulting from a simulation using the provided parameters (using the same simulation method as retrodesign()). Can optionally display using ggplot.

Usage

sim_plot(A, s, alpha = 0.05, df = Inf, n.sims = 5000, gg = TRUE)

Arguments

A

a numeric, an estimate of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

df

a numeric, the degrees of freedom

n.sims

a numeric, how many times to simulate when calculating Type M error

gg

If TRUE and ggplot2 is installed, uses ggplot2 for graphic

Value

A list of length 3 containing the power, type s, and type M error.

Examples

sim_plot(1,3.28)
sim_plot(.5,1)

type_m

Description

Calculates type m error. Is calculated using simulation, and thus supports t distributions through the df parameter.

Usage

type_m(A, s, alpha = 0.05, df = Inf, n.sims = 10000)

Arguments

A

a numeric or list, estimate(s) of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

df

a numeric, the number of degrees of freedom. df=Inf is equivalent to a normal distribution.

n.sims

a numeric, how many times to simulate when calculating Type M error

Value

either the type m error, a numeric if a single A is provided, or a df of length 2 by A, with the effect size and corresponding type m error in each row.

Examples

type_m(1,3.28)
type_m(list(.2,2,20),8.1)

List type_m

Description

type_m.list is the S3 method of the generic type_m() function, used when a list is passed for A.

Usage

## S3 method for class 'list'
type_m(A, s, alpha = 0.05, df = Inf, n.sims = 10000)

Arguments

A

a list, estimates of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

df

a numeric, the number of degrees of freedom. df=Inf is equivalent to a normal distribution.

n.sims

a numeric, how many times to simulate when calculating Type M error

Value

A df that is 2 by length(A), with an effect size and it's corresponding type m errors in each row.

Examples

type_s(list(.2,2,20),8.1)

Numeric type_m

Description

this is the S3 method of the generic type_m() function, used when a numeric is passed for A.

Usage

## S3 method for class 'numeric'
type_m(A, s, alpha = 0.05, df = Inf, n.sims = 1e+05)

Arguments

A

a numeric, estimate of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

df

a numeric, the number of degrees of freedom. df=Inf is equivalent to a normal distribution.

n.sims

a numeric, how many times to simulate when calculating Type M error

Value

either the type m, a numeric if a single A is provided, or a df of length 2 by A, with the effect size and corresponding type m error in each row.

Examples

type_m(1,3.28)

type_s

Description

Calculates type s error.

Usage

type_s(A, s, alpha = 0.05)

Arguments

A

a numeric or list, estimate(s) of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

Value

either the type S, a numeric if a single A is provided, or a df of length 2 by A, with the effect size and corresponding type S error in each row.

Examples

type_s(1,3.28)
type_s(list(.2,2,20),8.1)

List type_s

Description

type_s.list is the S3 method of the generic type_s() function, used when a list is passed for A.

Usage

## S3 method for class 'list'
type_s(A, s, alpha = 0.05)

Arguments

A

a list, estimates of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

Value

A df that is 2 by length(A), with an effect size and it's corresponding type s errors in each row.

Examples

type_s(list(.2,2,20),8.1)

Numeric type_s

Description

this is the S3 method of the generic type_s() function, used when a numeric is passed for A.

Usage

## S3 method for class 'numeric'
type_s(A, s, alpha = 0.05)

Arguments

A

a numeric, estimate of the true effect size

s

a numeric, standard error of the estimate

alpha

a numeric, the statistical significance threshold

Value

either the type S, a numeric if a single A is provided, or a df of length 2 by A, with the effect size and corresponding type S error in each row.

Examples

type_s(1,3.28)