Description Usage Arguments Details Value References Examples
View source: R/calc_contrast.R
Calculate contrast analysis for factorial designs
1 2 3 4 5 6 7 8 9 |
dv |
dependent variable. Values must be numeric. |
between |
independent variable that divides the data into independent groups. Vector must be a factor. |
lambda_between |
contrast weights must be a named numeric.
Names must match the levels of |
within |
independent variable which divides the data into dependent groups. This must be a factor. |
lambda_within |
contrast must be a named numeric.
Names must match the levels of |
ID |
identifier for cases or subjects is needed for within- and mixed contrastanalysis. |
data |
optional argument for the |
For multi-factorial designs, the lambda weights of the factors must be connected.
Calculates the significance of the contrast analysis. given.
Rosenthal, R., Rosnow, R.L., & Rubin, D.B. (2000). Contrasts and effect sizes in behavioral research: A correlational approach. New York: Cambridge University Press.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | # Example for between-subjects design Table 3.1 from
# Rosenthal, Rosnow and Rubin (2001)
tab31 <- data.frame(
Val = c(2, 6, 8, 4,10, 6, 8, 10, 4, 12, 8,
16, 10, 14, 12, 12, 18, 14, 20, 16),
Let = as.factor(rep(c("A", "B", "C", "D"), c(5, 5, 5, 5)))
)
contr_bw <- calc_contrast(
dv = Val,
between = Let,
lambda_between = c("A" = -3, "B" = -1, "C" = 1, "D" = 3),
data = tab31)
contr_bw
summary(contr_bw)
# Example for within-subjects design Calculation 16.6 from
# Sedlmeier and Renkewitz (2018, p. 537)
sedlmeier537 <- data.frame(
Var = c(27, 25, 30, 29, 30, 33, 31, 35,
25, 26, 32, 29, 28, 30, 32, 34,
21, 25, 23, 26, 27, 26, 29, 31,
23, 24, 24, 28, 24, 26, 27, 32),
within = as.factor(rep(1:4,c(8,8,8,8))),
ID = as.factor(rep(1:8,4)))
contr_wi <- calc_contrast(
dv = Var,
within = within,
ID = ID,
lambda_within = c("1" = 0.25, "2" = -.75, "3" = 1.25, "4" = -.75),
data=sedlmeier537
)
contr_wi
summary(contr_wi, ci=.90)
# Exampel for mixed-designs Table 5.3 from
# Rosenthal, Rosnow and Rubin (2001)
tab53 <- data.frame(
Var = c(3, 1, 4, 4, 5, 5, 6, 5, 7, 2, 2, 5,
5, 6, 7, 6, 6, 8, 3, 1, 5, 4, 5, 6,
7, 6, 8, 3, 2, 5, 6, 6, 7, 8, 8, 9),
bw = as.factor(rep(rep(LETTERS[1:3], c(3, 3, 3)), 4)),
wi = as.factor(rep(1:4, c(9, 9, 9, 9))),
ID = as.factor(rep(1:9, 4 ))
)
lambda_within <- c("1" = -3, "2" = -1, "3" = 1, "4" = 3)
lambda_between <-c("A" = -1, "B" = 0, "C" = 1)
contr_mx <- calc_contrast(dv = Var, between = bw,
lambda_between = lambda_between,
within = wi,
lambda_within = lambda_within,
ID = ID, data = tab53
)
contr_mx
summary(contr_mx)
|
Contrast Analysis for between factor design
F(1,16) = 28.9; p = 6.183e-05
Contrasts: A = -3; B = -1; C = 1; D = 3
r_effectsize = 0.797
$`F-Table`
SS df MS F p
contrast 289 1 289 28.9 0
within 160 16 10 NA NA
total 455 19 NA NA NA
$Effects
effects
r_effectsize 0.797
r_contrast 0.802
r_alerting 0.990
Contrast Analysis for within factor design
L-Values: Mean = -1.625 ; SD = 2.409
t(7) = -1.908; p = 0.95096843
Contrasts: 1 = 0.25; 2 = -0.75; 3 = 1.25; 4 = -0.75
g_contrast = -0.675
$`L-Statistics`
Mean SE df p CI-lower CI-upper
[1,] -1.625 0.8517314 7 0.9509684 -3.238672 -0.01132786
$Effects
[,1]
r-contrast 0.3241617
g-contrast -0.6745369
Contrast Analysis for Mixed-Design:
F(1,6) = 20.211; p = 0.004
Contrasts: A = -1 B = 0 C = 1
r_effectsize = 0.871
$F_Table
SS df MS F p
contrast 42.667 1 42.667 20.211 0.004
within 12.667 6 2.111 NA NA
total 56.222 8 NA NA NA
$Effects
effect
r_effectsize 0.871
r_contrast 0.878
r_alerting 0.990
$Within_Groups
M SE
A 2.000000 0.5773503
B 4.000000 1.0000000
C 7.333333 0.8819171
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.