pwrss.t.contrasts | R Documentation |
Calculates power or sample size for one-, two-, three-Way ANCOVA contrasts and multiple comparisons. The pwrss.t.contrast()
function allows a single contrast. For multiple contrast testing (multiple comparisons) use the pwrss.t.contrasts()
function. The pwrss.t.contrasts()
function also allows adjustment to alpha due to multiple testing. All arguments are the same as with the earlier function except that it accepts an object returned from the pwrss.f.ancova.shieh()
function for convenience. Beware that, in this case, all other arguments are ignored except alpha
and adjust.alpha
.
The pwrss.t.contrasts()
function returns a data frame with as many rows as number of contrasts and eight columns with names 'contrast', 'comparison', 'psi', 'd', 'ncp', 'df', 'n.total', and 'power'. 'psi' is the contrast estimate. 'd'
is the standardized contrast estimate. Remaining parameters are explained elsewhere.
Note that R has a partial matching feature which allows you to specify shortened versions of arguments, such as mu
or mu.vec
instead of mu.vector
, or such as k
or k.cov
instead of k.covariates
.
Formulas are validated using examples and tables in Shieh (2017).
power.t.contrast(mu.vector,
sd.vector,
contrast.vector,
n.vector = NULL, p.vector = NULL,
r.squared = 0, k.covariates = 1,
power = NULL, alpha = 0.05,
tukey.kramer = FALSE,
ceiling = TRUE, verbose = TRUE, pretty = FALSE)
power.t.contrasts(x = NULL,
mu.vector = NULL,
sd.vector = NULL,
n.vector = NULL, p.vector = NULL,
r.squared = 0, k.covariates = 1,
contrast.matrix = NULL,
power = NULL, alpha = 0.05,
adjust.alpha = c("none", "tukey", "bonferroni",
"holm", "hochberg", "hommel",
"BH", "BY", "fdr"),
ceiling = TRUE, verbose = TRUE, pretty = FALSE)
x |
object; an object returned from |
mu.vector |
vector; adjusted means (or estimated marginal means) for each level of a factor. Ignored when 'x' is specified. |
sd.vector |
vector; unadjusted standard deviations for each level of a factor. Ignored when 'x' is specified. |
n.vector |
vector; sample sizes for each level of a factor. Ignored when 'x' is specified. |
p.vector |
vector; proportion of total sample size in each level of a factor. These proportions should sum to one. Ignored when 'x' is specified. |
r.squared |
explanatory power of covariates (R-squared) in the ANCOVA model. Ignored when 'x' is specified. |
k.covariates |
Number of covariates in the ANCOVA model. Ignored when 'x' is specified. |
contrast.vector |
vector; a single contrast in the form of a vector with as many elements as number of levels or groups (or cells in factorial designs). Ignored when 'x' is specified. |
contrast.matrix |
vector or matrix; contrasts should not be confused with the model (design) matrix. Rows of contrast matrix indicate independent vector of contrasts summing to zero. The default contrast matrix is constructed using deviation coding scheme (a.k.a. effect coding). Columns in the contrast matrix indicate number of levels or groups (or cells in factorial designs). Ignored when 'x' is specified. |
power |
statistical power, defined as the probability of correctly rejecting a false null hypothesis, denoted as |
alpha |
type 1 error rate, defined as the probability of incorrectly rejecting a true null hypothesis, denoted as |
tukey.kramer |
logical; |
adjust.alpha |
character; one of the methods in c("none", "tukey", "bonferroni", "holm", "hochberg", "hommel", "BH", "BY", "fdr") to control Type 1 error. See |
ceiling |
logical; |
verbose |
logical; |
pretty |
logical; whether the output should show Unicode characters (if encoding allows for it). |
parms |
list of parameters used in calculation. |
test |
type of the statistical test (T-Test). |
psi |
contrast-weighted mean difference. |
d |
contrast-weighted standardized mean difference. |
df |
degrees of freedom. |
t.alpha |
critical values. |
ncp |
non-centrality parameter for the alternative. |
null.ncp |
non-centrality parameter for the null. |
power |
statistical power |
n.total |
total sample size. |
Shieh, G. (2017). Power and sample size calculations for contrast analysis in ANCOVA. Multivariate Behavioral Research, 52(1), 1-11. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/00273171.2016.1219841")}
###################################################################
####################### planned contrasts #######################
###################################################################
#########################
## dummy coding scheme ##
#########################
contrast.object <- factorial.contrasts(factor.levels = 3, # one factor w/ 3 levels
coding = "treatment") # use dummy coding scheme
# get contrast matrix from the contrast object
contrast.matrix <- contrast.object$contrast.matrix
# calculate sample size given design characteristics
ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means
sd.vector = c(1, 1, 1), # unadjusted standard deviations
p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1
contrast.matrix = contrast.matrix,
r.squared = 0.50,
k.covariates = 1,
alpha = 0.05, power = 0.80)
# power of planned contrasts, adjusted for alpha level
power.t.contrasts(ancova.design, adjust.alpha = "fdr")
###########################
## Helmert coding scheme ##
###########################
contrast.object <- factorial.contrasts(factor.levels = 3, # one factor w/ 4 levels
coding = "helmert") # use helmert coding scheme
# get contrast matrix from the contrast object
contrast.matrix <- contrast.object$contrast.matrix
# calculate sample size given design characteristics
ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means
sd.vector = c(1, 1, 1), # unadjusted standard deviations
p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1
contrast.matrix = contrast.matrix,
r.squared = 0.50,
k.covariates = 1,
alpha = 0.05, power = 0.80)
# power of planned contrasts
power.t.contrasts(ancova.design)
##############################
## polynomial coding scheme ##
##############################
contrast.object <- factorial.contrasts(factor.levels = 3, # one factor w/ 4 levels
coding = "poly") # use polynomial coding scheme
# get contrast matrix from the contrast object
contrast.matrix <- contrast.object$contrast.matrix
# calculate sample size given design characteristics
ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means
sd.vector = c(1, 1, 1), # unadjusted standard deviations
p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1
contrast.matrix = contrast.matrix,
r.squared = 0.50,
k.covariates = 1,
alpha = 0.05, power = 0.80)
# power of the planned contrasts
power.t.contrasts(ancova.design)
######################
## custom contrasts ##
######################
# custom contrasts
contrast.matrix <- rbind(
cbind(A1 = 1, A2 = -0.50, A3 = -0.50),
cbind(A1 = 0.50, A2 = 0.50, A3 = -1)
)
# labels are not required for custom contrasts,
# but they make it easier to understand power.t.contrasts() output
# calculate sample size given design characteristics
ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means
sd.vector = c(1, 1, 1), # unadjusted standard deviations
p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1
contrast.matrix = contrast.matrix,
r.squared = 0.50,
k.covariates = 1,
alpha = 0.05, power = 0.80)
# power of the planned contrasts
power.t.contrasts(ancova.design)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.