Title: | Power Analyses for Interaction Effects in Cross-Sectional Regressions |
---|---|
Description: | Power analysis for regression models which test the interaction of two or three independent variables on a single dependent variable. Includes options for correlated interacting variables and specifying variable reliability. Two-way interactions can include continuous, binary, or ordinal variables. Power analyses can be done either analytically or via simulation. Includes tools for simulating single data sets and visualizing power analysis results. The primary functions are power_interaction_r2() and power_interaction() for two-way interactions, and power_interaction_3way_r2() for three-way interactions. Please cite as: Baranger DAA, Finsaas MC, Goldstein BL, Vize CE, Lynam DR, Olino TM (2023). "Tutorial: Power analyses for interaction effects in cross-sectional regressions." <doi:10.1177/25152459231187531>. |
Authors: | David Baranger [aut, cre] (<https://orcid.org/0000-0002-6659-357X>, davidbaranger.com), Brandon Goldstein [ctb], Megan Finsaas [ctb], Thomas Olino [ctb], Colin Vize [ctb], Don Lynam [ctb] |
Maintainer: | David Baranger <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.2 |
Built: | 2024-11-06 05:12:59 UTC |
Source: | https://github.com/dbaranger/interactionpower |
Computes how much variable correlations need to be adjusted so that they have the desired correlation structure after transformation. Intended for internal use only.
compute_adjustment( r.x1.y, r.x2.y, r.x1x2.y, r.x1.x2, N.adjustment = 1e+06, tol = 0.005, iter = 10, k.x1, k.x2, k.y )
compute_adjustment( r.x1.y, r.x2.y, r.x1x2.y, r.x1.x2, N.adjustment = 1e+06, tol = 0.005, iter = 10, k.x1, k.x2, k.y )
r.x1.y |
Internal use only |
r.x2.y |
Internal use only |
r.x1x2.y |
Internal use only |
r.x1.x2 |
Internal use only |
N.adjustment |
Internal use only |
tol |
Internal use only |
iter |
Internal use only |
k.x1 |
Internal use only |
k.x2 |
Internal use only |
k.y |
Internal use only |
Correlation adjustments.
compute_adjustment(r.x1.y = .2,r.x2.y = .2,r.x1x2.y = .1,r.x1.x2 = .2, k.x1 = 0,k.x2=0,k.y=2)
compute_adjustment(r.x1.y = .2,r.x2.y = .2,r.x1x2.y = .1,r.x1.x2 = .2, k.x1 = 0,k.x2=0,k.y=2)
Prints or plots the correlation matrix for a 3-way interaction
cor.mat.3way(power.results, row.num = 1, return.plot = FALSE)
cor.mat.3way(power.results, row.num = 1, return.plot = FALSE)
power.results |
Data frame of results from power_interaction_3way_r2(). |
row.num |
Which row to show? Can only be a single number. Default is 1. |
return.plot |
Return a matrix (FALSE, default), or a plot (TRUE)? |
A matrix or a ggplot2 object
power_analysis = power_interaction_3way_r2(detailed_results = TRUE,N = c(1000), r.x1.y = .2,r.x2.y = .3,r.x3.y = .1,r.x1x2.y = .01,r.x1x3.y = .05,r.x2x3.y = .1, b.x1x2x3 = 0.1,r.x1.x2 = .1,r.x1.x3 = .1,r.x2.x3 = .1, rel.x1 = 1,rel.x2 = 1,rel.x3 = 1,rel.y = 1 ) cor.mat.3way(power_analysis)
power_analysis = power_interaction_3way_r2(detailed_results = TRUE,N = c(1000), r.x1.y = .2,r.x2.y = .3,r.x3.y = .1,r.x1x2.y = .01,r.x1x3.y = .05,r.x2x3.y = .1, b.x1x2x3 = 0.1,r.x1.x2 = .1,r.x1.x3 = .1,r.x2.x3 = .1, rel.x1 = 1,rel.x2 = 1,rel.x3 = 1,rel.y = 1 ) cor.mat.3way(power_analysis)
Simulate a single data set with an interaction (y ~ x1 + x2 + x1*x2). All values other than 'N' are population-level effects - the values within any single simulated data set will vary around the defined values.
generate_interaction( N, r.x1.y, r.x2.y, r.x1x2.y, r.x1.x2, rel.x1 = 1, rel.x2 = 1, rel.y = 1, k.x1 = 0, k.x2 = 0, k.y = 0, adjust.correlations = TRUE, tol = 0.005, iter = 10, N.adjustment = 1e+06, r.x1.y.adjust = NULL, r.x2.y.adjust = NULL, r.x1.x2.adjust = NULL, r.x1x2.y.adjust = NULL, internal.adjust = FALSE, skew.x1 = NA, skew.x2 = NA, skew.y = NA )
generate_interaction( N, r.x1.y, r.x2.y, r.x1x2.y, r.x1.x2, rel.x1 = 1, rel.x2 = 1, rel.y = 1, k.x1 = 0, k.x2 = 0, k.y = 0, adjust.correlations = TRUE, tol = 0.005, iter = 10, N.adjustment = 1e+06, r.x1.y.adjust = NULL, r.x2.y.adjust = NULL, r.x1.x2.adjust = NULL, r.x1x2.y.adjust = NULL, internal.adjust = FALSE, skew.x1 = NA, skew.x2 = NA, skew.y = NA )
N |
Sample size. Must be a positive integer. Has no default value. |
r.x1.y |
Pearson's correlation between x1 and y. Must be between -1 and 1. Has no default value. |
r.x2.y |
Pearson's correlation between x2 and y. Must be between -1 and 1. Assumed to be the 'moderator' in some functions. Has no default value. |
r.x1x2.y |
Pearson's correlation between the interaction term x1x2 (x1 * x2) and y. Must be between -1 and 1. Has no default value. |
r.x1.x2 |
Pearson's correlation between x1 and x2. Must be between -1 and 1. Has no default value. |
rel.x1 |
Reliability of x1 (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
rel.x2 |
Reliability of x2 (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
rel.y |
Reliability of xy (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
k.x1 |
Number of discrete values for x1. Can be used to make a variable binary or ordinal. |
k.x2 |
Number of discrete values for x2. Can be used to make a variable binary or ordinal. |
k.y |
Number of discrete values for y.Can be used to make a variable binary or ordinal. |
adjust.correlations |
If variables are ordinal or binary, should correlations be adjusted so that output data has the specified correlation structure? Default is TRUE. |
tol |
Correlation adjustment tolerance. When adjust.correlations = TRUE, correlations are adjusted so that the population correlation is within r='tol' of the target. Default = 0.005. |
iter |
Max number of iterations to run the correlation adjustment for. Typically only a couple are needed. Default = 10. |
N.adjustment |
Sample size to use when adjusting correlations. Default = 1000000. |
r.x1.y.adjust |
Internal use only. |
r.x2.y.adjust |
Internal use only. |
r.x1.x2.adjust |
Internal use only. |
r.x1x2.y.adjust |
Internal use only. |
internal.adjust |
Internal use only. |
skew.x1 |
No longer supported. |
skew.x2 |
No longer supported. |
skew.y |
No longer supported. |
A data frame containing variables 'x1', 'x2', 'y', and 'x1x2'. 'x1x2' is x1*x2. The correlations between these variables are drawn from the defined population-level values. Output variables are all z-scored (mean=0, sd=1).
dataset <- generate_interaction(N = 10,r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3)
dataset <- generate_interaction(N = 10,r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3)
power_interaction_r2_covs()
Companion function to 'power_interaction_r2_covs()'. Generates a formatted list for users to specify the analysis parameters.
generate.interaction.cov.input(c.num)
generate.interaction.cov.input(c.num)
c.num |
Number of covariates in the model. |
A list to be used with the 'power_interaction_r2_covs()' function.
ex1 = generate.interaction.cov.input(c.num=2) ex1$correlations$r.y.x1x2 = c(0.1,0.2,0.3)
ex1 = generate.interaction.cov.input(c.num=2) ex1$correlations$r.y.x1x2 = c(0.1,0.2,0.3)
Expanded variable names so that plots look nicer.
data(name_key)
data(name_key)
A data frame with 25 rows and 2 variables
Transforms a vector with a normal distribution to a binomial distribution with two values.
norm2ordinal(x, k)
norm2ordinal(x, k)
x |
Input vector |
k |
Number of discrete values (e.g., 2=binary, 5=likert scale) |
A ordinal or binary variable
norm2ordinal(x = rnorm(n = 100,mean = 0,sd = 1),k=2)
norm2ordinal(x = rnorm(n = 100,mean = 0,sd = 1),k=2)
Plots a single simulated interaction data set
plot_interaction(data, q = 3)
plot_interaction(data, q = 3)
data |
Output of generate_interaction(). |
q |
Simple slope quantiles. Default is 2. X2 is the default moderator, unless X1 is already binary. Must be a positive integer > 1. |
A ggplot2 object
dataset <- generate_interaction(N = 250,r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3) plot_interaction(dataset,q=3)
dataset <- generate_interaction(N = 250,r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3) plot_interaction(dataset,q=3)
Plot the output of power_interaction().
plot_power_curve( power_data, x = NULL, group = NULL, facets = NULL, power_target = 0.8 )
plot_power_curve( power_data, x = NULL, group = NULL, facets = NULL, power_target = 0.8 )
power_data |
Data frame of results from power_interaction(). Can accept the raw results if up to 3 parameters were varied during simulation. Any more and data should be filtered first. |
x |
Optional, the x-axis of the plot. Default is the first variable after 'pwr'. |
group |
Optional, grouping variable for the line color. Default is the second variable after 'pwr', if present. |
facets |
Optional, grouping variable for plot facets. Default is the third variable after 'pwr' if present. |
power_target |
The target power. Default is 80%. |
A ggplot2 object
power_analysis <- power_interaction(n.iter = 10,N = seq(100,300,by=100), r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3,detailed_results = TRUE) plot_power_curve(power_analysis)
power_analysis <- power_interaction(n.iter = 10,N = seq(100,300,by=100), r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3,detailed_results = TRUE) plot_power_curve(power_analysis)
Plots the simple slope min and max estimates from power_interaction().
plot_simple_slope(power_data, x = NULL, facets = NULL)
plot_simple_slope(power_data, x = NULL, facets = NULL)
power_data |
Data frame of results from power_interaction(). Can accept the raw results if up to 2 parameters were varied during simulation. Any more and data should be filtered first. |
x |
Optional, the x-axis of the plot. Default is the first variable after 'pwr'. |
facets |
Optional, grouping variable for plot facets. Default is the second variable after 'pwr' if present. |
A ggplot2 object
power_analysis <- power_interaction(n.iter = 10,N = seq(100,300,by=100), r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3,detailed_results = TRUE) plot_simple_slope(power_analysis)
power_analysis <- power_interaction(n.iter = 10,N = seq(100,300,by=100), r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3,detailed_results = TRUE) plot_simple_slope(power_analysis)
Uses regression to estimate the value needed to attain the target power, given a set of simulation results.
power_estimate(power_data, x, power_target)
power_estimate(power_data, x, power_target)
power_data |
Output of power_interaction(). |
x |
The name of the target variable as a character string. |
power_target |
The desired power level. Must be between 0 and 1 (e.g., 0.8 for 80% power). |
A data frame containing the value of x that achieves the target power for each combination of settings. Will return NA if target power is outside the simulation data.
simulation_results = power_interaction_r2(N=seq(100,300,by=10), r.x1.y=0.2, r.x2.y=.2,r.x1x2.y=0.2,r.x1.x2=.2) power_estimate(power_data = simulation_results, x = "N", power_target = .8)
simulation_results = power_interaction_r2(N=seq(100,300,by=10), r.x1.y=0.2, r.x2.y=.2,r.x1x2.y=0.2,r.x1.x2=.2) power_estimate(power_data = simulation_results, x = "N", power_target = .8)
Power analysis for interaction models, by simulation. A set of n.iter simulations is run for each unique combination of model settings.
power_interaction( n.iter, N, r.x1.y, r.x2.y, r.x1x2.y, r.x1.x2, rel.x1 = 1, rel.x2 = 1, rel.y = 1, k.x1 = 0, k.x2 = 0, k.y = 0, adjust.correlations = TRUE, alpha = 0.05, q = 2, cl = NULL, ss.IQR = 1.5, N.adjustment = 1e+06, detailed_results = FALSE, full_simulation = FALSE, tol = 0.005, iter = 10, skew.x1 = NA, skew.x2 = NA, skew.y = NA )
power_interaction( n.iter, N, r.x1.y, r.x2.y, r.x1x2.y, r.x1.x2, rel.x1 = 1, rel.x2 = 1, rel.y = 1, k.x1 = 0, k.x2 = 0, k.y = 0, adjust.correlations = TRUE, alpha = 0.05, q = 2, cl = NULL, ss.IQR = 1.5, N.adjustment = 1e+06, detailed_results = FALSE, full_simulation = FALSE, tol = 0.005, iter = 10, skew.x1 = NA, skew.x2 = NA, skew.y = NA )
n.iter |
Number of iterations. The number of simulations to run for each unique setting combination. Must be a positive integer. |
N |
Sample size. Must be a positive integer. Has no default value. Can be a single value or a vector of values. |
r.x1.y |
Pearson's correlation between x1 and y. Must be between -1 and 1.. Has no default value. Can be a single value or a vector of values. |
r.x2.y |
Pearson's correlation between x2 and y. Must be between -1 and 1.. Assumed to be the 'moderator' in some functions. Has no default value. Can be a single value or a vector of values. |
r.x1x2.y |
Pearson's correlation between the interaction term x1x2 (x1 * x2) and y. Must be between -1 and 1.. Has no default value. Can be a single value or a vector of values. |
r.x1.x2 |
Pearson's correlation between x1 and x2. Must be between -1 and 1.. Has no default value. Can be a single value or a vector of values. |
rel.x1 |
Reliability of x1 (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
rel.x2 |
Reliability of x2 (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
rel.y |
Reliability of xy (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
k.x1 |
Number of discrete values for x1. Can be used to make a variable binary or ordinal. |
k.x2 |
Number of discrete values for x2. Can be used to make a variable binary or ordinal. |
k.y |
Number of discrete values for y. Can be used to make a variable binary or ordinal. |
adjust.correlations |
If variables are ordinal or binary, should correlations be adjusted so that output data has the specified correlation structure? Default is TRUE. |
alpha |
The alpha. At what p-value is the interaction deemed significant? Default is 0.05. |
q |
Simple slopes. How many quantiles should x2 be split into for simple slope testing? Default is 2. Simple slope testing returns the effect-size (slope) of y~x1 for the two most extreme quantiles of x2. If q=3 then the two slopes are y~x1 for the bottom 33% of x2, and the top 33% of x2. |
cl |
Number of clusters to use for running simulations in parallel (recommended). Default is 1 (i.e. not in parallel). |
ss.IQR |
Simple slope IQR. Multiplier when estimating the distribution of simple slopes within each simulation setting. Default is 1.5. |
N.adjustment |
Sample size for simulations where correlation matrix is corrected to allow for binary/ordinal variables. Default is 1000000 |
detailed_results |
Default is FALSE. Should detailed results be reported? |
full_simulation |
Default is FALSE. If TRUE, will return a list that includes the full per-simulation results. |
tol |
Correlation adjustment tolerance. When adjust.correlations = TRUE, correlations are adjusted so that the population correlation is within r='tol' of the target. Default = 0.005. |
iter |
Max number of iterations to run the correlation adjustment for. Typically only a couple are needed. Default = 10. |
skew.x1 |
No longer supported. |
skew.x2 |
No longer supported. |
skew.y |
No longer supported. |
A data frame containing the power (% significant results) for each unique setting combination. If full_simulation = TRUE will return a list, with one data frame that includes power, and a second that includes raw simulation results.
power_interaction(n.iter=10, N=10,r.x1.y=0.2, r.x2.y=.2,r.x1x2.y=0.5,r.x1.x2=.2)
power_interaction(n.iter=10, N=10,r.x1.y=0.2, r.x2.y=.2,r.x1x2.y=0.5,r.x1.x2=.2)
Power analysis for 3-way interaction models, computed via change in R2. Valid for interactions with continuous, normally distributed, variables. Either b.x1x2x3
or f2
can be used to specify the magnitude of the interaction effect size.
power_interaction_3way_r2( N, b.x1x2x3, r.x1.y, r.x2.y, r.x3.y, r.x1x2.y, r.x1x3.y, r.x2x3.y, r.x1.x2, r.x1.x3, r.x2.x3, rel.x1 = 1, rel.x2 = 1, rel.x3 = 1, rel.y = 1, alpha = 0.05, detailed_results = FALSE, cl = NULL )
power_interaction_3way_r2( N, b.x1x2x3, r.x1.y, r.x2.y, r.x3.y, r.x1x2.y, r.x1x3.y, r.x2x3.y, r.x1.x2, r.x1.x3, r.x2.x3, rel.x1 = 1, rel.x2 = 1, rel.x3 = 1, rel.y = 1, alpha = 0.05, detailed_results = FALSE, cl = NULL )
N |
Sample size. Must be a positive integer. Has no default value. Can be a single value or a vector of values. |
b.x1x2x3 |
Regression coefficient of the 3-way interaction term x1x2x3. Should not be specified if |
r.x1.y |
Pearson's correlation between x1 and y. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
r.x2.y |
Pearson's correlation between x2 and y. Must be between -1 and 1. Assumed to be the 'moderator' in some functions. Has no default value. Can be a single value or a vector of values. |
r.x3.y |
Pearson's correlation between x3 and y. Must be between -1 and 1. Assumed to be the 'moderator' in some functions. Has no default value. Can be a single value or a vector of values. |
r.x1x2.y |
Pearson's correlation between the interaction term x1x2 (x1 * x2) and y. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
r.x1x3.y |
Pearson's correlation between the interaction term x1x2 (x1 * x3) and y. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
r.x2x3.y |
Pearson's correlation between the interaction term x1x2 (x2 * x3) and y. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
r.x1.x2 |
Pearson's correlation between x1 and x2. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
r.x1.x3 |
Pearson's correlation between x1 and x3. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
r.x2.x3 |
Pearson's correlation between x2 and x3. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
rel.x1 |
Reliability of x1 (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
rel.x2 |
Reliability of x2 (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
rel.x3 |
Reliability of x3 (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
rel.y |
Reliability of xy (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
alpha |
The alpha. At what p-value is the interaction deemed significant? Default is 0.05. |
detailed_results |
Default is FALSE. Should detailed results be reported? Returns regression slopes, f2, r2, and the full correlation matrix. |
cl |
Number of clusters to use for running simulations in parallel. Default is NULL (i.e. not in parallel). Useful when running several thousand analyses at once. |
A data frame containing the power for each unique setting combination.
power_interaction_3way_r2(N=1000,r.x1.y = .1,r.x2.y = .2,r.x3.y = .3, r.x1x2.y = .05,r.x1x3.y = .07,r.x2x3.y = .09,b.x1x2x3 =0.01, r.x1.x2 = .2,r.x1.x3 = .4,r.x2.x3 = .3)
power_interaction_3way_r2(N=1000,r.x1.y = .1,r.x2.y = .2,r.x3.y = .3, r.x1x2.y = .05,r.x1x3.y = .07,r.x2x3.y = .09,b.x1x2x3 =0.01, r.x1.x2 = .2,r.x1.x3 = .4,r.x2.x3 = .3)
Power analysis for interaction models, computed via change in R2. Valid for interactions with continuous, normally distributed, variables.
power_interaction_r2( N, r.x1.y, r.x2.y, r.x1x2.y, r.x1.x2, rel.x1 = 1, rel.x2 = 1, rel.y = 1, alpha = 0.05, detailed_results = FALSE )
power_interaction_r2( N, r.x1.y, r.x2.y, r.x1x2.y, r.x1.x2, rel.x1 = 1, rel.x2 = 1, rel.y = 1, alpha = 0.05, detailed_results = FALSE )
N |
Sample size. Must be a positive integer. Has no default value. Can be a single value or a vector of values. |
r.x1.y |
Pearson's correlation between x1 and y. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
r.x2.y |
Pearson's correlation between x2 and y. Must be between -1 and 1. Assumed to be the 'moderator' in some functions. Has no default value. Can be a single value or a vector of values. |
r.x1x2.y |
Pearson's correlation between the interaction term x1x2 (x1 * x2) and y. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
r.x1.x2 |
Pearson's correlation between x1 and x2. Must be between -1 and 1. Has no default value. Can be a single value or a vector of values. |
rel.x1 |
Reliability of x1 (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
rel.x2 |
Reliability of x2 (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
rel.y |
Reliability of xy (e.g. test-retest reliability, ICC, Cronbach's alpha). Default is 1 (perfect reliability). Must be greater than 0 and less than or equal to 1. |
alpha |
The alpha. At what p-value is the interaction deemed significant? Default is 0.05. |
detailed_results |
Default is FALSE. Should detailed results be reported? |
A data frame containing the power for each unique setting combination.
power_interaction_r2(N=seq(100,300,by=10),r.x1.y=0.2, r.x2.y=.2,r.x1x2.y=0.2,r.x1.x2=.2)
power_interaction_r2(N=seq(100,300,by=10),r.x1.y=0.2, r.x2.y=.2,r.x1x2.y=0.2,r.x1.x2=.2)
Analytic power analysis of an interaction model with covariates. Additional covariate x main effect interaction terms are additionally added.
power_interaction_r2_covs( cov.input, N, alpha = 0.05, detailed_results = FALSE, cl = NULL )
power_interaction_r2_covs( cov.input, N, alpha = 0.05, detailed_results = FALSE, cl = NULL )
cov.input |
Output of 'power_interaction_r2_covs()'. Variable correlations and reliabilities are set by first modifying this list. |
N |
Sample size. Must be a positive integer. Has no default value. Can be a single value or a vector of values. |
alpha |
The alpha. At what p-value is the interaction deemed significant? Default is 0.05. |
detailed_results |
Default is FALSE. Should detailed results be reported? |
cl |
Number of clusters to use for running simulations in parallel. Default is NULL (i.e. not in parallel). Useful when running several thousand analyses at once. |
A data frame containing the analytic power for each unique setting combination.
ex1 = generate.interaction.cov.input(c.num=2) ex1$correlations$r.y.x1x2 = c(0.1,0.2,0.3) power_interaction_r2_covs(cov.input = ex1,N=100)
ex1 = generate.interaction.cov.input(c.num=2) ex1$correlations$r.y.x1x2 = c(0.1,0.2,0.3) power_interaction_r2_covs(cov.input = ex1,N=100)
Prints or plots the simple slopes for a 3-way interaction
simple.slopes.3way(power.results, row.num = 1, return.plot = FALSE)
simple.slopes.3way(power.results, row.num = 1, return.plot = FALSE)
power.results |
Data frame of results from power_interaction_3way_r2(). |
row.num |
Which row to show? Can only be a single number. Default is 1. |
return.plot |
Return a matrix (FALSE, default), or a plot (TRUE)? |
A matrix or a ggplot2 object
power_analysis = power_interaction_3way_r2(detailed_results = TRUE,N = c(1000), r.x1.y = .2,r.x2.y = .3,r.x3.y = .1,r.x1x2.y = .01,r.x1x3.y = .05,r.x2x3.y = .1, b.x1x2x3 = 0.1,r.x1.x2 = .1,r.x1.x3 = .1,r.x2.x3 = .1, rel.x1 = 1,rel.x2 = 1,rel.x3 = 1,rel.y = 1 ) simple.slopes.3way(power_analysis)
power_analysis = power_interaction_3way_r2(detailed_results = TRUE,N = c(1000), r.x1.y = .2,r.x2.y = .3,r.x3.y = .1,r.x1x2.y = .01,r.x1x3.y = .05,r.x2x3.y = .1, b.x1x2x3 = 0.1,r.x1.x2 = .1,r.x1.x3 = .1,r.x2.x3 = .1, rel.x1 = 1,rel.x2 = 1,rel.x3 = 1,rel.y = 1 ) simple.slopes.3way(power_analysis)
Test the interaction from a single simulated data set.
test_interaction( data, alpha = 0.05, detailed_results = FALSE, q = 2, simple = FALSE )
test_interaction( data, alpha = 0.05, detailed_results = FALSE, q = 2, simple = FALSE )
data |
Simulated data set. Output of 'generate_interaction()'. |
alpha |
The alpha. At what p-value is the interaction deemed significant? Default is 0.05. |
detailed_results |
Should results beyond the linear model (change in R2, simple slopes, correlations, and confidence intervals) be returned? Default is FALSE. |
q |
Simple slopes. How many quantiles should x2 be split into for simple slope testing? Default is 2. Simple slope testing returns the effect-size (slope) of y~x1 for the two most extreme quantiles of x2. If q=3 then the two slopes are y~x1 for the bottom 33% of x2, and the top 33% of x2. |
simple |
For internal use. Default is FALSE. |
Either a named list or a data frame containing the results of the regression y~x1+x2+x1*x2, the pearson's correlation between y, x1,x2, and x1x2, and the slopes of the simple slopes.
dataset <- generate_interaction(N = 250,r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3) test_interaction(data = dataset, alpha=0.05, q=2)
dataset <- generate_interaction(N = 250,r.x1.y = 0,r.x2.y = .1,r.x1x2.y = -.2,r.x1.x2 = .3) test_interaction(data = dataset, alpha=0.05, q=2)