| Title: | Reproducible Reports in Psychology |
|---|---|
| Description: | Helper functions for producing reports in Psychology (Reproducible Research). Provides required formatted strings (APA style) for use in 'Knitr'/'Latex' integration within *.Rnw files. |
| Authors: | Ian G Mackenzie [cre, aut], Carolin Dudschig [aut] |
| Maintainer: | Ian G Mackenzie <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 4.0.1 |
| Built: | 2026-05-11 07:13:09 UTC |
| Source: | https://github.com/igmmgi/psychreport |
Helper functions for producing reports in Psychology (Reproducible Research). Provides required formatted strings (APA style) for use in 'Knitr'/'Latex' integration within *.Rnw files.
Maintainer: Ian G Mackenzie [email protected]
Authors:
Carolin Dudschig [email protected]
Add simulated ex-gaussian reaction-time (RT) data and binary error (Error = 1, Correct = 0) data to an R DataFrame. This function can be used to create simulated data sets.
addDataDF(dat, RT = NULL, Error = NULL)addDataDF(dat, RT = NULL, Error = NULL)
dat |
DataFrame (see createDF) |
RT |
RT parameters (see rtDist) |
Error |
Error parameters (see errDist) |
DataFrame with RT (ms) and Error (bool) columns
# Example 1: default dataframe dat <- createDF() dat <- addDataDF(dat) hist(dat$RT, 100) table(dat$Error) # Example 2: defined overall RT parameters dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = c(500, 150, 100)) boxplot(dat$RT ~ dat$Comp) table(dat$Comp, dat$Error) # Example 3: defined RT + Error parameters across conditions dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 80, 100), "Comp incomp" = c(550, 80, 140) ), Error = list( "Comp comp" = 5, "Comp incomp" = 10 ) ) boxplot(dat$RT ~ dat$Comp) table(dat$Comp, dat$Error) # Example 4: # create dataframe with defined RT + Error parameters across different conditions dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp", "neutral"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 150, 100), "Comp neutral" = c(550, 150, 100), "Comp incomp" = c(600, 150, 100) ), Error = list( "Comp comp" = 5, "Comp neutral" = 10, "Comp incomp" = 15 ) ) boxplot(dat$RT ~ dat$Comp) table(dat$Comp, dat$Error) # Example 5: # create dataframe with defined RT + Error parameters across different conditions dat <- createDF( nVP = 50, nTrl = 50, design = list( "Hand" = c("left_a", "right_a"), "Side" = c("left_a", "right_a") ) ) dat <- addDataDF(dat, RT = list( "Hand:Side left_a:left_a" = c(400, 150, 100), "Hand:Side left_a:right_a" = c(500, 150, 100), "Hand:Side right_a:left_a" = c(500, 150, 100), "Hand:Side right_a:right_a" = c(400, 150, 100) ), Error = list( "Hand:Side left_a:left_a" = c(5, 4, 2, 2, 1), "Hand:Side left_a:right_a" = c(15, 4, 2, 2, 1), "Hand:Side right_a:left_a" = c(15, 7, 4, 2, 1), "Hand:Side right_a:right_a" = c(5, 8, 5, 3, 1) ) ) boxplot(dat$RT ~ dat$Hand + dat$Side) table(dat$Error, dat$Hand, dat$Side)# Example 1: default dataframe dat <- createDF() dat <- addDataDF(dat) hist(dat$RT, 100) table(dat$Error) # Example 2: defined overall RT parameters dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = c(500, 150, 100)) boxplot(dat$RT ~ dat$Comp) table(dat$Comp, dat$Error) # Example 3: defined RT + Error parameters across conditions dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 80, 100), "Comp incomp" = c(550, 80, 140) ), Error = list( "Comp comp" = 5, "Comp incomp" = 10 ) ) boxplot(dat$RT ~ dat$Comp) table(dat$Comp, dat$Error) # Example 4: # create dataframe with defined RT + Error parameters across different conditions dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp", "neutral"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 150, 100), "Comp neutral" = c(550, 150, 100), "Comp incomp" = c(600, 150, 100) ), Error = list( "Comp comp" = 5, "Comp neutral" = 10, "Comp incomp" = 15 ) ) boxplot(dat$RT ~ dat$Comp) table(dat$Comp, dat$Error) # Example 5: # create dataframe with defined RT + Error parameters across different conditions dat <- createDF( nVP = 50, nTrl = 50, design = list( "Hand" = c("left_a", "right_a"), "Side" = c("left_a", "right_a") ) ) dat <- addDataDF(dat, RT = list( "Hand:Side left_a:left_a" = c(400, 150, 100), "Hand:Side left_a:right_a" = c(500, 150, 100), "Hand:Side right_a:left_a" = c(500, 150, 100), "Hand:Side right_a:right_a" = c(400, 150, 100) ), Error = list( "Hand:Side left_a:left_a" = c(5, 4, 2, 2, 1), "Hand:Side left_a:right_a" = c(15, 4, 2, 2, 1), "Hand:Side right_a:left_a" = c(15, 7, 4, 2, 1), "Hand:Side right_a:right_a" = c(5, 8, 5, 3, 1) ) ) boxplot(dat$RT ~ dat$Hand + dat$Side) table(dat$Error, dat$Hand, dat$Side)
Displays marginal means from model.tables in the command window.
aovDispMeans(aovObj, value = "value", caption = sys.call())aovDispMeans(aovObj, value = "value", caption = sys.call())
aovObj |
Output from aov |
value |
String for column name |
caption |
Required for heading |
NULL (prints means to console)
# Example 1: # create dataframe dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(520, 100, 100))) aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovDispMeans(aovRT)# Example 1: # create dataframe dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(520, 100, 100))) aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovDispMeans(aovRT)
Display formatted ANOVA table in command window.
aovDispTable(aovObj, caption = sys.call())aovDispTable(aovObj, caption = sys.call())
aovObj |
Output from aov |
caption |
Required for heading |
NULL (prints table to console)
# Example 1: # create dataframe dat <- createDF(nVP = 6, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovObj <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovDispTable(aovObj)# Example 1: # create dataframe dat <- createDF(nVP = 6, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovObj <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovDispTable(aovObj)
Add effect size to ANOVA table. Effect sizes: partial eta squared (pes) vs. ges (generalized eta squared).
aovEffectSize(aovObj, effectSize = "pes")aovEffectSize(aovObj, effectSize = "pes")
aovObj |
Output from aov |
effectSize |
Effect size (pes vs. ges) |
list
# Example 1: # create dataframe with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp", "neutral"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 150), "Comp:Side comp:right" = c(500, 150, 150), "Comp:Side incomp:left" = c(550, 150, 150), "Comp:Side incomp:right" = c(550, 150, 150), "Comp:Side neutral:left" = c(525, 150, 150), "Comp:Side neutral:right" = c(525, 150, 150))) aovRT <- aov(RT ~ Comp * Side + Error(VP/(Comp*Side)), dat) aovDispMeans(aovRT) aovRT <- aovEffectSize(aovRT) aovRT <- aovDispTable(aovRT)# Example 1: # create dataframe with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp", "neutral"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 150), "Comp:Side comp:right" = c(500, 150, 150), "Comp:Side incomp:left" = c(550, 150, 150), "Comp:Side incomp:right" = c(550, 150, 150), "Comp:Side neutral:left" = c(525, 150, 150), "Comp:Side neutral:right" = c(525, 150, 150))) aovRT <- aov(RT ~ Comp * Side + Error(VP/(Comp*Side)), dat) aovDispMeans(aovRT) aovRT <- aovEffectSize(aovRT) aovRT <- aovDispTable(aovRT)
Adjust ANOVA table with corrected F (Fc = F/(n-1)^2) and p values for jackkniffed data (see Ulrich and Miller, 2001. Using the jackknife-based scoring method for measuring LRP onset effects in factorial designs. Psychophysiology, 38, 816-827.)
aovJackknifeAdjustment(aovObj, numVPs)aovJackknifeAdjustment(aovObj, numVPs)
aovObj |
Output from aov |
numVPs |
The number of participants |
list
# Example 1: # create dataframe with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 150), "Comp:Side comp:right" = c(500, 150, 150), "Comp:Side incomp:left" = c(500, 150, 150), "Comp:Side incomp:right" = c(500, 150, 150))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovJackknifeAdjustment(aovRT, length(unique(dat$VP))) aovDispTable(aovRT)# Example 1: # create dataframe with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 150), "Comp:Side comp:right" = c(500, 150, 150), "Comp:Side incomp:left" = c(500, 150, 150), "Comp:Side incomp:right" = c(500, 150, 150))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovJackknifeAdjustment(aovRT, length(unique(dat$VP))) aovDispTable(aovRT)
Round digits to n decimal places in ANOVA table
aovRoundDigits(aovObj)aovRoundDigits(aovObj)
aovObj |
Output from aov |
dataframe
# Example 1: # create dataframe with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 150), "Comp:Side comp:right" = c(500, 150, 150), "Comp:Side incomp:left" = c(500, 150, 150), "Comp:Side incomp:right" = c(500, 150, 150))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovRoundDigits(aovRT) aovDispTable(aovRT)# Example 1: # create dataframe with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 150), "Comp:Side comp:right" = c(500, 150, 150), "Comp:Side incomp:left" = c(500, 150, 150), "Comp:Side incomp:right" = c(500, 150, 150))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovRoundDigits(aovRT) aovDispTable(aovRT)
Adjust ANOVA table with corrections for sphericity (Greenhouse-Geisser or Huynh-Feldt). Called by default within aovTable. Note: sphericity corrections require an object with a "Sphericity Corrections" component.
aovSphericityAdjustment(aovObj, type = "GG", adjDF = TRUE)aovSphericityAdjustment(aovObj, type = "GG", adjDF = TRUE)
aovObj |
The returned ANOVA object |
type |
"GG" (Greenhouse-Geisser) or "HF" (Huynh-Feldt) |
adjDF |
TRUE/FALSE Should DFs be adjusted? |
list
# Example 1: # create dataframe with 3(Comp: neutral vs. comp vs. incomp) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("neutral", "comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp neutral" = c(510, 150, 100), "Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovRT <- aovTable(aovRT)# Example 1: # create dataframe with 3(Comp: neutral vs. comp vs. incomp) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("neutral", "comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp neutral" = c(510, 150, 100), "Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovRT <- aovTable(aovRT)
Adjust ANOVA table output. Options include calculation of alternative effect sizes (eta squared, partial eta squared), the calculation of marginal means and formatting options for the ANOVA table (e.g., rounding).
aovTable( aovObj, effectSize = "pes", sphericityCorrections = TRUE, sphericityCorrectionType = "GG", sphericityCorrectionAdjDF = FALSE, removeSumSquares = TRUE )aovTable( aovObj, effectSize = "pes", sphericityCorrections = TRUE, sphericityCorrectionType = "GG", sphericityCorrectionAdjDF = FALSE, removeSumSquares = TRUE )
aovObj |
Output from aov |
effectSize |
Effect size (pes vs. ges) |
sphericityCorrections |
TRUE/FALSE |
sphericityCorrectionType |
"GG" (default) vs. "HF" |
sphericityCorrectionAdjDF |
TRUE/FALSE Should DFs be corrected? |
removeSumSquares |
TRUE/FALSE Remove SSn/SSd columns from the ANOVA table |
list
# Example 1: # create dataframe with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 150), "Comp:Side comp:right" = c(500, 150, 150), "Comp:Side incomp:left" = c(500, 150, 150), "Comp:Side incomp:right" = c(500, 150, 150))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT)# Example 1: # create dataframe with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) factors/levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 150), "Comp:Side comp:right" = c(500, 150, 150), "Comp:Side incomp:left" = c(500, 150, 150), "Comp:Side incomp:right" = c(500, 150, 150))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT)
Take output from base aov function and produce a "tidy" ANOVA table. The output also contains the marginal means.
aovTidyTable(aovObj, data = NULL)aovTidyTable(aovObj, data = NULL)
aovObj |
Output from aov function |
data |
Optional. The original data frame used in the aov call. When provided, sphericity corrections (Mauchly's test, GG/HF epsilon) are computed. |
list
# create dataframe dat <- createDF(nVP = 6, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovObj <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovObj <- aovTable(aovObj) aovObj$ANOVA printTable(aovObj$ANOVA)# create dataframe dat <- createDF(nVP = 6, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovObj <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovObj <- aovTable(aovObj) aovObj$ANOVA printTable(aovObj$ANOVA)
Returns a string with the 95% CI from a t.test in Latex format.
ciStrT(tObj, numDigits = 0, unit = "")ciStrT(tObj, numDigits = 0, unit = "")
tObj |
The returned object from a call to t.test |
numDigits |
The number of digits to round to |
unit |
"" vs. "ms" vs. "mv" vs. "%" |
character
# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) levels dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(600, 100, 100))) tObj <- t.test(dat$RT[dat$Comp == "incomp"], dat$RT[dat$Comp == "comp"], paired = TRUE) ciString <- ciStrT(tObj, unit = "ms")# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) levels dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(600, 100, 100))) tObj <- t.test(dat$RT[dat$Comp == "incomp"], dat$RT[dat$Comp == "comp"], paired = TRUE) ciString <- ciStrT(tObj, unit = "ms")
Create dataframe (see also addDataDF)
createDF( nVP = 20, nTrl = 50, design = list(A = c("A1", "A2"), B = c("B1", "B2")) )createDF( nVP = 20, nTrl = 50, design = list(A = c("A1", "A2"), B = c("B1", "B2")) )
nVP |
Number of participants |
nTrl |
Number of trials per factor/level for each participant |
design |
Factors and levels |
dataframe
# Example 1 dat <- createDF() # Example 2 dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) # Example 3 dat <- createDF(nVP = 50, nTrl = 50, design = list( "Comp" = c("comp", "incomp"), "Side" = c("left", "right", "middle") ))# Example 1 dat <- createDF() # Example 2 dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) # Example 3 dat <- createDF(nVP = 50, nTrl = 50, design = list( "Comp" = c("comp", "incomp"), "Side" = c("left", "right", "middle") ))
Returns required Latex formatted string for effect size (partial eta squared) = XXX for R/knitr integration. Returns values to 2 sig decimal places.
effectsizeValueString(aovObj, effect, effectSize = "pes")effectsizeValueString(aovObj, effect, effectSize = "pes")
aovObj |
Output from aov |
effect |
The effect within the ANOVA table to return |
effectSize |
pes (partial eta squared) vs. ges (generalised eta squared) |
character
# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 100), "Comp:Side comp:right" = c(500, 150, 100), "Comp:Side incomp:left" = c(520, 150, 100), "Comp:Side incomp:right" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT) pesString <- effectsizeValueString(aovRT, "Comp") # partial eta squared pesString <- effectsizeValueString(aovRT, "Comp:Side")# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 100), "Comp:Side comp:right" = c(500, 150, 100), "Comp:Side incomp:left" = c(520, 150, 100), "Comp:Side incomp:right" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT) pesString <- effectsizeValueString(aovRT, "Comp") # partial eta squared pesString <- effectsizeValueString(aovRT, "Comp:Side")
Returns a random vector of 0's (correct) and 1's (incorrect) with defined proportions (default = 10% errors).
errDist(n = 10000, proportion = 10)errDist(n = 10000, proportion = 10)
n |
Number |
proportion |
Approximate proportion of errors in percentage |
double
# Example 1: approx 10% errors x <- errDist(1000) table(x) # Example 2: approx 20% errors x <- errDist(1000, 20) table(x)# Example 1: approx 10% errors x <- errDist(1000) table(x) # Example 2: approx 20% errors x <- errDist(1000, 20) table(x)
Returns required Latex formatted string for F(df1, df2) = XXX for R/knitr integration. For example, F(1, 23) = 3.45. Returns values to 2 sig decimal places.
fValueString(aovObj, effect)fValueString(aovObj, effect)
aovObj |
Output from aov |
effect |
The effect within the ANOVA table to return |
character
# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 100), "Comp:Side comp:right" = c(500, 150, 100), "Comp:Side incomp:left" = c(520, 150, 100), "Comp:Side incomp:right" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT) fString <- fValueString(aovRT, "Comp") fString <- fValueString(aovRT, "Comp:Side")# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 100), "Comp:Side comp:right" = c(500, 150, 100), "Comp:Side incomp:left" = c(520, 150, 100), "Comp:Side incomp:right" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT) fString <- fValueString(aovRT, "Comp") fString <- fValueString(aovRT, "Comp:Side")
Returns formatted string following addition/subtraction.
mathString(str1, str2, operation = "-", numDigits = 0, unit = "ms")mathString(str1, str2, operation = "-", numDigits = 0, unit = "ms")
str1 |
string |
str2 |
string |
operation |
"+", "-", "*", "/" |
numDigits |
number 0 (default) |
unit |
"ms" , "mV" , "mv", or "%" |
character
# Example 1: string <- mathString("550 ms", "480 ms", "-") # Example 2: string <- mathString("2.34", "1.65", "+", numDigits = 2, unit = "mV")# Example 1: string <- mathString("550 ms", "480 ms", "-") # Example 2: string <- mathString("2.34", "1.65", "+", numDigits = 2, unit = "mV")
Returns marginal means from ANOVA object for requested effect in Latex format.
meanStrAov(aovObj, effect, level, unit = "ms", numDigits = 0)meanStrAov(aovObj, effect, level, unit = "ms", numDigits = 0)
aovObj |
Output from aov |
effect |
Effect to return |
level |
Level of effect |
unit |
"ms" vs. "mv" vs. "%" |
numDigits |
Number of decimal places (default 0) |
character
# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 100), "Comp:Side comp:right" = c(500, 150, 100), "Comp:Side incomp:left" = c(520, 150, 100), "Comp:Side incomp:right" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT) meanString <- meanStrAov(aovRT, "Comp", "comp") meanString <- meanStrAov(aovRT, "Comp:Side", "incomp:left")# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 100), "Comp:Side comp:right" = c(500, 150, 100), "Comp:Side incomp:left" = c(520, 150, 100), "Comp:Side incomp:right" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT) meanString <- meanStrAov(aovRT, "Comp", "comp") meanString <- meanStrAov(aovRT, "Comp:Side", "incomp:left")
Returns a string with the mean value from a t.test in Latex format.
meanStrT(tObj, numDigits = 0, unit = "")meanStrT(tObj, numDigits = 0, unit = "")
tObj |
The returned object from a call to t.test |
numDigits |
The number of digits to round to |
unit |
"" vs. "ms" vs. "mv" vs. "%" |
character
# Example 1: # create dataframe and add data dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(600, 100, 100))) tObj <- t.test(dat$RT[dat$Comp == "incomp"], dat$RT[dat$Comp == "comp"], paired = TRUE) tString <- meanStrT(tObj, numDigits = 0, unit = "ms")# Example 1: # create dataframe and add data dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(600, 100, 100))) tObj <- t.test(dat$RT[dat$Comp == "incomp"], dat$RT[dat$Comp == "comp"], paired = TRUE) tString <- meanStrT(tObj, numDigits = 0, unit = "ms")
Normalise within-subjects data by removing between-subjects variability. Each participant's scores are centered on the grand mean.
normData(data, idvar, dvs)normData(data, idvar, dvs)
data |
A dataframe |
idvar |
Column indicating the individual participants |
dvs |
List of numeric data columns to normalise |
dataframe
# Example 1: library(dplyr) dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 80, 100), "Comp incomp" = c(550, 80, 140) ), Error = list( "Comp comp" = 5, "Comp incomp" = 10 ) ) datAggVP <- dat %>% group_by(VP, Comp) %>% summarize( N = n(), RT = mean(RT[Error == 0]), ER = (sum(Error) / N) * 100 ) datAggVP <- normData(datAggVP, "VP", c("RT", "ER"))# Example 1: library(dplyr) dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 80, 100), "Comp incomp" = c(550, 80, 140) ), Error = list( "Comp comp" = 5, "Comp incomp" = 10 ) ) datAggVP <- dat %>% group_by(VP, Comp) %>% summarize( N = n(), RT = mean(RT[Error == 0]), ER = (sum(Error) / N) * 100 ) datAggVP <- normData(datAggVP, "VP", c("RT", "ER"))
Returns numerical value with requested unit in Latex format with numDigits number of decimal places and unit symbol.
numValueString(value, numDigits = 2, unit = "")numValueString(value, numDigits = 2, unit = "")
value |
number |
numDigits |
number 2 (default) |
unit |
"ms", "mv", "mV", or "%" or "" (default) |
character
# Example 1: string <- numValueString(100.341, 0, "ms") # Example 2: string <- numValueString(2.3412, 2, "mv") # Example 3: string <- numValueString(63.9812, 2, "")# Example 1: string <- numValueString(100.341, 0, "ms") # Example 2: string <- numValueString(2.3412, 2, "mv") # Example 3: string <- numValueString(63.9812, 2, "")
Returns Latex formatted table of marginal means from model.tables. Uses printTable (xtable) latex package with some basic defaults. For more examples, see R package xtable
printAovMeans(..., caption = "Mean", digits = 3, dv = "ms")printAovMeans(..., caption = "Mean", digits = 3, dv = "ms")
... |
Output from aov |
caption |
Title for the table |
digits |
Number of digits to round to |
dv |
Name of the dependent variable (e.g., "ms", "%") |
character
# Example 1: # create dataframe dat <- createDF(nVP = 6, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovRT <- aovTable(aovRT) printAovMeans(aovRT, digits = 3, dv = "ms") # latex formatted# Example 1: # create dataframe dat <- createDF(nVP = 6, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovRT <- aovTable(aovRT) printAovMeans(aovRT, digits = 3, dv = "ms") # latex formatted
Returns Latex formatted table from dataframe or ANOVA table. Uses xtable latex package with some basic defaults. For more examples, see R package xtable
printTable(obj, caption = "DF", digits = 3, onlyContents = FALSE)printTable(obj, caption = "DF", digits = 3, onlyContents = FALSE)
obj |
Dataframe or ANOVA table to print |
caption |
Title of the dataframe |
digits |
Number of digits to round to NB. length can be 1, or vector with length equal to the number of numeric columns |
onlyContents |
TRUE/FALSE |
character
# Example 1: # create dataframe dat <- createDF(nVP = 6, nTrl = 1, design = list("Comp" = c("comp", "incomp", "neutral"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100), "Comp neutral" = c(510, 150, 100))) printTable(dat, digits = c(0, 2)) # latex formatted printTable(dat, digits = 0) # latex formatted aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovRT <- aovTable(aovRT) printTable(aovRT$ANOVA) # latex formatted printTable(aovRT$ANOVA, digits = c(0,2,2,2)) # latex formatted# Example 1: # create dataframe dat <- createDF(nVP = 6, nTrl = 1, design = list("Comp" = c("comp", "incomp", "neutral"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100), "Comp neutral" = c(510, 150, 100))) printTable(dat, digits = c(0, 2)) # latex formatted printTable(dat, digits = 0) # latex formatted aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovRT <- aovTable(aovRT) printTable(aovRT$ANOVA) # latex formatted printTable(aovRT$ANOVA, digits = c(0,2,2,2)) # latex formatted
Returns Latex formatted string from a p-value required for R/knitr integration. For example, p = 0.11 or p < 0.01 Returns values to 3 sig decimal places or < .001
pValueString(pVal)pValueString(pVal)
pVal |
p-value between 0 and 1 |
character
# Example 1: pString <- pValueString(0.670) # Example 2: pString <- pValueString(0.1234) # Example 3: pString <- pValueString("0.03")# Example 1: pString <- pValueString(0.670) # Example 2: pString <- pValueString(0.1234) # Example 3: pString <- pValueString("0.03")
Returns p-values summarized using ***, **, *, or exact value when p > .05 (default 2 significant decimal places).
pValueSummary(pVal)pValueSummary(pVal)
pVal |
vector with p-value between 0 and 1 |
character
# Examples: psum <- pValueSummary(0.0067) psum <- pValueSummary(c(0.0001, 0.002, 0.02, 0.1))# Examples: psum <- pValueSummary(0.0067) psum <- pValueSummary(c(0.0001, 0.002, 0.02, 0.1))
Installs (default if required) and loads specified packages.
requiredPackages( packages, installPackages = FALSE, lib = .libPaths()[1], repos = "http://cran.us.r-project.org" )requiredPackages( packages, installPackages = FALSE, lib = .libPaths()[1], repos = "http://cran.us.r-project.org" )
packages |
A list of packages |
installPackages |
TRUE/FALSE Install package if not installed |
lib |
character vector giving the library directories where to install the packages. Recycled as needed. If missing, defaults to the first element of .libPaths() |
repos |
character vector, the base URL(s) of the repositories to use, e.g., the URL of a CRAN mirror such as "https://cloud.r-project.org". For more details on supported URL schemes see url. Can be NULL to install from local files, directories or URLs: this will be inferred by extension from pkgs if of length one. |
Returns value(s) from a distribution appropriate to simulate reaction times. The distribution is a combined exponential and gaussian distribution called an exponentially modified Gaussian (EMG) distribution or ex-gaussian distribution.
rtDist(n = 10000, gaussMean = 600, gaussSD = 50, expRate = 200)rtDist(n = 10000, gaussMean = 600, gaussSD = 50, expRate = 200)
n |
Number of observations |
gaussMean |
Mean of the gaussian distribution |
gaussSD |
SD of the gaussian distribution |
expRate |
Rate of the exponential function |
double
# Example 1: x <- rtDist() hist(x, 100) # Example 2: x <- rtDist(n = 20000, gaussMean = 800, gaussSD = 50, expRate = 100) hist(x, 100)# Example 1: x <- rtDist() hist(x, 100) # Example 2: x <- rtDist(n = 20000, gaussMean = 800, gaussSD = 50, expRate = 100) hist(x, 100)
Returns required Latex formatted string for sphericity epsilon values (HF, GG) = XXX for R/knitr integration. Returns values to 2 sig decimal places.
sphericityValueString(aovObj, effect)sphericityValueString(aovObj, effect)
aovObj |
The returned ANOVA object |
effect |
The effect within the ANOVA table to return |
character
# Example 1 # create dataframe and add data with 3(Comp: neutral vs. comp vs. incomp) levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("neutral", "comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp neutral" = c(510, 150, 100), "Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovRT <- aovTable(aovRT) sphericityValueString(aovRT, "Comp")# Example 1 # create dataframe and add data with 3(Comp: neutral vs. comp vs. incomp) levels dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("neutral", "comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp neutral" = c(510, 150, 100), "Comp comp" = c(500, 150, 100), "Comp incomp" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp + Error(VP/(Comp)), dat) aovRT <- aovTable(aovRT) sphericityValueString(aovRT, "Comp")
Returns Latex formatted string from ANOVA required for R/knitr integration. For example,
Returns values to 2 sig decimal places and < 0.01, < 0.001 for p values.
statStrAov(aovObj, effect)statStrAov(aovObj, effect)
aovObj |
Output from aov |
effect |
The effect required from the anova table |
# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 100), "Comp:Side comp:right" = c(500, 150, 100), "Comp:Side incomp:left" = c(520, 150, 100), "Comp:Side incomp:right" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT) aovString <- statStrAov(aovRT, "Comp") aovString <- statStrAov(aovRT, "Comp:Side")# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) and 2(Side: left vs. right) dat <- createDF(nVP = 20, nTrl = 1, design = list("Comp" = c("comp", "incomp"), "Side" = c("left", "right"))) dat <- addDataDF(dat, RT = list("Comp:Side comp:left" = c(500, 150, 100), "Comp:Side comp:right" = c(500, 150, 100), "Comp:Side incomp:left" = c(520, 150, 100), "Comp:Side incomp:right" = c(520, 150, 100))) aovRT <- aov(RT ~ Comp*Side + Error(VP/(Comp*Side)), dat) aovRT <- aovTable(aovRT) aovString <- statStrAov(aovRT, "Comp") aovString <- statStrAov(aovRT, "Comp:Side")
Returns required Latex formatted string T-test required for R/Knitr integration. For example, t(11) = 3.45, p < 0.05. Returns values to 2 sig decimal places and < 0.01, < 0.001 for p values.
statStrT(tObj)statStrT(tObj)
tObj |
The returned object from a call to t.test |
character
# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) levels dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(600, 100, 100))) tObj <- t.test(dat$RT[dat$Comp == "incomp"], dat$RT[dat$Comp == "comp"], paired = TRUE) statStrT <- statStrT(tObj)# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) levels dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(600, 100, 100))) tObj <- t.test(dat$RT[dat$Comp == "incomp"], dat$RT[dat$Comp == "comp"], paired = TRUE) statStrT <- statStrT(tObj)
Aggregate data returning the mean, standard deviation, and standard error
summaryMSDSE(data, factors, dvs, withinCorrection = NULL)summaryMSDSE(data, factors, dvs, withinCorrection = NULL)
data |
A dataframe |
factors |
List of factors over which to aggregate |
dvs |
List of numeric data columns to aggregate |
withinCorrection |
List of dvs which to apply within-subjects correction to the calculation of the standard deviation and standard error. Within-subject correction calculated according to Morey (2008). NB Data should be normed first (see normData). |
dataframe
# Example 1: library(dplyr) dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 80, 100), "Comp incomp" = c(550, 80, 140) ), Error = list( "Comp comp" = 5, "Comp incomp" = 10 ) ) datAggVP <- dat %>% group_by(VP, Comp) %>% summarize( N = n(), RT = mean(RT[Error == 0]), ER = (sum(Error) / N) * 100 ) datAgg <- summaryMSDSE(datAggVP, "Comp", c("RT", "ER")) # Example 2: dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 80, 100), "Comp incomp" = c(550, 80, 140) ), Error = list( "Comp comp" = 5, "Comp incomp" = 10 ) ) datAggVP <- dat %>% group_by(VP, Comp) %>% summarize( N = n(), RT = mean(RT[Error == 0]), ER = (sum(Error) / N) * 100 ) datAggVP <- normData(datAggVP, "VP", c("RT", "ER")) datAgg <- summaryMSDSE( datAggVP, "Comp", c("RT", "ER", "RT_norm", "ER_norm"), c("RT_norm", "ER_norm") )# Example 1: library(dplyr) dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 80, 100), "Comp incomp" = c(550, 80, 140) ), Error = list( "Comp comp" = 5, "Comp incomp" = 10 ) ) datAggVP <- dat %>% group_by(VP, Comp) %>% summarize( N = n(), RT = mean(RT[Error == 0]), ER = (sum(Error) / N) * 100 ) datAgg <- summaryMSDSE(datAggVP, "Comp", c("RT", "ER")) # Example 2: dat <- createDF(nVP = 50, nTrl = 50, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list( "Comp comp" = c(500, 80, 100), "Comp incomp" = c(550, 80, 140) ), Error = list( "Comp comp" = 5, "Comp incomp" = 10 ) ) datAggVP <- dat %>% group_by(VP, Comp) %>% summarize( N = n(), RT = mean(RT[Error == 0]), ER = (sum(Error) / N) * 100 ) datAggVP <- normData(datAggVP, "VP", c("RT", "ER")) datAgg <- summaryMSDSE( datAggVP, "Comp", c("RT", "ER", "RT_norm", "ER_norm"), c("RT_norm", "ER_norm") )
Returns required Latex formatted string for t(df) = XXX for R/knitr integration. Returns values to 2 sig decimal places.
tValueString(tObj)tValueString(tObj)
tObj |
The returned object from a call to t.test |
character
# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) levels dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(600, 100, 100))) tObj <- t.test(dat$RT[dat$Comp == "incomp"], dat$RT[dat$Comp == "comp"], paired = TRUE) tString <- tValueString(tObj)# Example 1: # create dataframe and add data with 2(Comp: comp vs. incomp) levels dat <- createDF(nVP = 50, nTrl = 1, design = list("Comp" = c("comp", "incomp"))) dat <- addDataDF(dat, RT = list("Comp comp" = c(500, 100, 100), "Comp incomp" = c(600, 100, 100))) tObj <- t.test(dat$RT[dat$Comp == "incomp"], dat$RT[dat$Comp == "comp"], paired = TRUE) tString <- tValueString(tObj)