Title: | Create American Psychological Association (APA) Style Tables |
---|---|
Description: | A common task faced by researchers is the creation of APA style (i.e., American Psychological Association style) tables from statistical output. In R a large number of function calls are often needed to obtain all of the desired information for a single APA style table. As well, the process of manually creating APA style tables in a word processor is prone to transcription errors. This package creates Word files (.doc files) and latex code containing APA style tables for several types of analyses. Using this package minimizes transcription errors and reduces the number commands needed by the user. |
Authors: | David Stanley [aut, cre] |
Maintainer: | David Stanley <[email protected]> |
License: | MIT License + file LICENSE |
Version: | 3.0.0 |
Built: | 2025-01-26 04:57:06 UTC |
Source: | https://github.com/dstanley4/apatables |
A data set from Field et al (2012)
data(album)
data(album)
A data frame with 200 rows and 4 variables:
Amount spent of adverts, thousands of pounds
Album sales in thousands
Number of times songs from album played on radio week prior to release
Attractiveness rating of band members
https://studysites.sagepub.com/dsur/study/
Field, A., Miles, J., & Field, Z. (2012) Discovering Statistics Using R. Sage: Chicago.
Creates a table of means and standard deviations for a 1-way ANOVA design in APA style
apa.1way.table( iv, dv, data, filename = NA, table.number = 0, show.conf.interval = FALSE, landscape = FALSE )
apa.1way.table( iv, dv, data, filename = NA, table.number = 0, show.conf.interval = FALSE, landscape = FALSE )
iv |
Name of independent variable column in data frame |
dv |
Name of dependent variable column in data frame |
data |
Project data frame name |
filename |
(optional) Output filename document filename (must end in .rtf or .doc only) |
table.number |
Integer to use in table number output line |
show.conf.interval |
(TRUE/FALSE) Display confidence intervals in table. |
landscape |
(TRUE/FALSE) Make RTF file landscape |
APA table object
# Example 1: 1-way from Field et al. (2012) Discovery Statistics Using R table1 <- apa.1way.table(iv = dose, dv = libido, data = viagra, table.number = 1) apa.save(filename = "table1.doc", table1) # Create a table for your PDF # Include the line below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) # delete demo file if (file.exists("table1.doc")) { file.remove("table1.doc") }
# Example 1: 1-way from Field et al. (2012) Discovery Statistics Using R table1 <- apa.1way.table(iv = dose, dv = libido, data = viagra, table.number = 1) apa.save(filename = "table1.doc", table1) # Create a table for your PDF # Include the line below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) # delete demo file if (file.exists("table1.doc")) { file.remove("table1.doc") }
Creates a table of means and standard deviations for a 2-way ANOVA design in APA style
apa.2way.table( iv1, iv2, dv, data, filename = NA, table.number = 0, show.conf.interval = FALSE, show.marginal.means = FALSE, landscape = TRUE )
apa.2way.table( iv1, iv2, dv, data, filename = NA, table.number = 0, show.conf.interval = FALSE, show.marginal.means = FALSE, landscape = TRUE )
iv1 |
Name of independent variable 1 column in data frame |
iv2 |
Name of independent variable 2 column in data frame |
dv |
Name of dependent variable column in data frame |
data |
Project data frame name |
filename |
(optional) Output filename document filename (must end in .rtf or .doc only) |
table.number |
Integer to use in table number output line |
show.conf.interval |
(TRUE/FALSE) Display confidence intervals in table. Negates show.marginal.means = TRUE. |
show.marginal.means |
(TRUE/FALSE) Show marginal means in output. Only used if show.conf.interval = FALSE. |
landscape |
(TRUE/FALSE) Make RTF file landscape |
APA table object
# Example 2: 2-way from Fidler & Thompson (2001) table2 <- apa.2way.table(iv1 = a, iv2 = b, dv = dv, data = fidler_thompson, landscape = TRUE, table.number = 2) # Example 3: 2-way from Field et al. (2012) Discovery Statistics Using R table3 <- apa.2way.table(iv1 = gender, iv2 = alcohol, dv = attractiveness, data = goggles, table.number = 3) # Save both Table 2 and Table 3 in a single .doc document apa.save(filename = "my_tables.doc", table2, table3) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table2) apa.knit.table.for.pdf(table3) # delete demo file if (file.exists("my_tables.doc")) { file.remove("my_tables.doc") }
# Example 2: 2-way from Fidler & Thompson (2001) table2 <- apa.2way.table(iv1 = a, iv2 = b, dv = dv, data = fidler_thompson, landscape = TRUE, table.number = 2) # Example 3: 2-way from Field et al. (2012) Discovery Statistics Using R table3 <- apa.2way.table(iv1 = gender, iv2 = alcohol, dv = attractiveness, data = goggles, table.number = 3) # Save both Table 2 and Table 3 in a single .doc document apa.save(filename = "my_tables.doc", table2, table3) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table2) apa.knit.table.for.pdf(table3) # delete demo file if (file.exists("my_tables.doc")) { file.remove("my_tables.doc") }
Creates a fixed-effects ANOVA table in APA style
apa.aov.table( lm_output, filename, table.number = 0, conf.level = 0.9, type = 3 )
apa.aov.table( lm_output, filename, table.number = 0, conf.level = 0.9, type = 3 )
lm_output |
Regression (i.e., lm) result objects. Typically, one for each block in the regression. |
filename |
(optional) Output filename document filename (must end in .rtf or .doc only) |
table.number |
Integer to use in table number output line |
conf.level |
Level of confidence for interval around partial eta-squared (.90 or .95). A value of .90 is the default, this helps to create consistency between the CI overlapping with zero and conclusions based on the p-value. |
type |
Sum of Squares Type. Type II or Type III; specify, 2 or 3, respectively. Default value is 3. |
APA table object
Smithson, M. (2001). Correct confidence intervals for various regression effect sizes and parameters: The importance of noncentral distributions in computing intervals. Educational and Psychological Measurement, 61(4), 605-632.
Fidler, F., & Thompson, B. (2001). Computing correct confidence intervals for ANOVA fixed-and random-effects effect sizes. Educational and Psychological Measurement, 61(4), 575-604.
#Example 1: 1-way from Field et al. (2012) Discovery Statistics Using R options(contrasts = c("contr.helmert", "contr.poly")) lm_output <- lm(libido ~ dose, data = viagra) table1 <- apa.aov.table(lm_output, table.number = 4) # Example 2: 2-way from Fidler & Thompson (2001) # You must set these contrasts to ensure values match SPSS options(contrasts = c("contr.helmert", "contr.poly")) lm_output <- lm(dv ~ a*b, data = fidler_thompson) table2 <- apa.aov.table(lm_output, table.number = 5) #Example 3: 2-way from Field et al. (2012) Discovery Statistics Using R # You must set these contrasts to ensure values match SPSS options(contrasts = c("contr.helmert", "contr.poly")) lm_output <- lm(attractiveness ~ gender*alcohol, data = goggles) table3 <- apa.aov.table(lm_output, table.number = 6) # Save all three table in the same .doc document apa.save(filename = "my_tables.doc", table1, table2, table3) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) apa.knit.table.for.pdf(table2) apa.knit.table.for.pdf(table3) # delete demo file if (file.exists("my_tables.doc")) { file.remove("my_tables.doc") }
#Example 1: 1-way from Field et al. (2012) Discovery Statistics Using R options(contrasts = c("contr.helmert", "contr.poly")) lm_output <- lm(libido ~ dose, data = viagra) table1 <- apa.aov.table(lm_output, table.number = 4) # Example 2: 2-way from Fidler & Thompson (2001) # You must set these contrasts to ensure values match SPSS options(contrasts = c("contr.helmert", "contr.poly")) lm_output <- lm(dv ~ a*b, data = fidler_thompson) table2 <- apa.aov.table(lm_output, table.number = 5) #Example 3: 2-way from Field et al. (2012) Discovery Statistics Using R # You must set these contrasts to ensure values match SPSS options(contrasts = c("contr.helmert", "contr.poly")) lm_output <- lm(attractiveness ~ gender*alcohol, data = goggles) table3 <- apa.aov.table(lm_output, table.number = 6) # Save all three table in the same .doc document apa.save(filename = "my_tables.doc", table1, table2, table3) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) apa.knit.table.for.pdf(table2) apa.knit.table.for.pdf(table3) # delete demo file if (file.exists("my_tables.doc")) { file.remove("my_tables.doc") }
Creates a correlation table in APA style with means and standard deviations
apa.cor.table( data, filename = NA, table.number = 0, show.conf.interval = TRUE, show.sig.stars = TRUE, show.pvalue = TRUE, landscape = TRUE )
apa.cor.table( data, filename = NA, table.number = 0, show.conf.interval = TRUE, show.sig.stars = TRUE, show.pvalue = TRUE, landscape = TRUE )
data |
Project data frame |
filename |
(optional) Output filename document filename (must end in .rtf or .doc only) |
table.number |
Integer to use in table number output line |
show.conf.interval |
(TRUE/FALSE) Display confidence intervals in table. This argument is deprecated and will be removed from later versions. |
show.sig.stars |
(TRUE/FALSE) Display stars for significance in table. |
show.pvalue |
(TRUE/FALSE) Display p-value in table. |
landscape |
(TRUE/FALSE) Make RTF file landscape |
APA table object
# View top few rows of attitude data set head(attitude) # Use apa.cor.table function table1 <- apa.cor.table(attitude) # Save Table 1 in a .doc document apa.save(filename = "table1.doc", table1) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) # delete demo file if (file.exists("table1.doc")) { file.remove("table1.doc") }
# View top few rows of attitude data set head(attitude) # Use apa.cor.table function table1 <- apa.cor.table(attitude) # Save Table 1 in a .doc document apa.save(filename = "table1.doc", table1) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) # delete demo file if (file.exists("table1.doc")) { file.remove("table1.doc") }
Creates a d-values for all paired comparisons in APA style
apa.d.table( iv, dv, data, filename = NA, table.number = 0, show.conf.interval = TRUE, landscape = TRUE )
apa.d.table( iv, dv, data, filename = NA, table.number = 0, show.conf.interval = TRUE, landscape = TRUE )
iv |
Name of independent variable column in data frame for all paired comparisons |
dv |
Name of dependent variable column in data frame for all paired comparisons |
data |
Project data frame name |
filename |
(optional) Output filename document filename (must end in .rtf or .doc only) |
table.number |
Integer to use in table number output line |
show.conf.interval |
(TRUE/FALSE) Display confidence intervals in table. This argument is deprecated and will be removed from later versions. |
landscape |
(TRUE/FALSE) Make RTF file landscape |
APA table object
# View top few rows of viagra data set from Discovering Statistics Using R head(viagra) # Use apa.d.table function table1 <- apa.d.table(iv = dose, dv = libido, data = viagra) # Save Table 1 in a .doc document apa.save(filename = "table1.doc", table1) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) # delete demo file if (file.exists("table1.doc")) { file.remove("table1.doc") }
# View top few rows of viagra data set from Discovering Statistics Using R head(viagra) # Use apa.d.table function table1 <- apa.d.table(iv = dose, dv = libido, data = viagra) # Save Table 1 in a .doc document apa.save(filename = "table1.doc", table1) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) # delete demo file if (file.exists("table1.doc")) { file.remove("table1.doc") }
Creates an ANOVA table in APA style based output of ezANOVA command from ez package
apa.ezANOVA.table( ez.output, correction = "GG", table.title = "", filename, table.number = 0 )
apa.ezANOVA.table( ez.output, correction = "GG", table.title = "", filename, table.number = 0 )
ez.output |
Output object from ezANOVA command from ez package |
correction |
Type of sphercity correction: "none", "GG", or "HF" corresponding to none, Greenhouse-Geisser and Huynh-Feldt, respectively. |
table.title |
String containing text for table title |
filename |
(optional) Output filename document filename (must end in .rtf or .doc only) |
table.number |
Integer to use in table number output line |
APA table object
if (requireNamespace("ez", quietly = TRUE)){ if (requireNamespace("apaTables", quietly = TRUE)){ if (requireNamespace("tidyr", quietly = TRUE)){ # # ** Example 1: Between Participant Predictors # goggles <- apaTables::goggles # Use ezANOVA # Be sure use the options command, as below, to ensure sufficient digits options(digits = 10) goggles_results <- ez::ezANOVA(data = goggles, dv = attractiveness, between = .(gender, alcohol), participant , detailed = TRUE) # Make APA table - save after all 3 examples goggles_table <- apa.ezANOVA.table(goggles_results) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(goggles_table) # # ** Example 2: Within Participant Predictors # drink_attitude_wide <- apaTables::drink_attitude_wide # Convert data from wide format to long format where one row represents one OBSERVATION. # Wide format column names MUST represent levels of each variable separated by an underscore. # See vignette for further details. drink_attitude_long <- tidyr::pivot_longer(drink_attitude_wide, cols = beer_positive:water_neutral, names_to = c("drink", "imagery"), names_sep = "_", values_to = "attitude") drink_attitude_long$drink <- as.factor(drink_attitude_long$drink) drink_attitude_long$imagery <- as.factor(drink_attitude_long$imagery) # Set contrasts to match Field et al. (2012) textbook output alcohol_vs_water <- c(1, 1, -2) beer_vs_wine <- c(-1, 1, 0) negative_vs_other <- c(1, -2, 1) positive_vs_neutral <- c(-1, 0, 1) contrasts(drink_attitude_long$drink) <- cbind(alcohol_vs_water, beer_vs_wine) contrasts(drink_attitude_long$imagery) <- cbind(negative_vs_other, positive_vs_neutral) # Use ezANOVA # Be sure use the options command, as below, to ensure sufficient digits options(digits = 10) drink_attitude_results <- ez::ezANOVA(data = drink_attitude_long, dv = .(attitude), wid = .(participant), within = .(drink, imagery), type = 3, detailed = TRUE) # Make APA table - save after all 3 examples drink_table <- apa.ezANOVA.table(drink_attitude_results) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(drink_table) # # ** Example 3: Between and Within Participant Predictors # dating_wide <- apaTables::dating_wide # Convert data from wide format to long format where one row represents one OBSERVATION. # Wide format column names MUST represent levels of each variable separated by an underscore. # See vignette for further details. dating_long <- tidyr::pivot_longer(dating_wide, cols = attractive_high:ugly_none, names_to = c("looks", "personality"), names_sep = "_", values_to = "date_rating") #' dating_long$looks <- as.factor(dating_long$looks) dating_long$personality <- as.factor(dating_long$personality) # Set contrasts to match Field et al. (2012) textbook output some_vs_none <- c(1, 1, -2) hi_vs_av <- c(1, -1, 0) attractive_vs_ugly <- c(1, 1, -2) attractive_vs_average <- c(1, -1, 0) contrasts(dating_long$personality) <- cbind(some_vs_none, hi_vs_av) contrasts(dating_long$looks) <- cbind(attractive_vs_ugly, attractive_vs_average) # Use ezANOVA options(digits = 10) dating_results <-ez::ezANOVA(data = dating_long, dv = .(date_rating), wid = .(participant), between = .(gender), within = .(looks, personality), type = 3, detailed = TRUE) # Make APA table - save after all 3 examples dating_table <- apa.ezANOVA.table(dating_results) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(dating_table) # # Saving all three tables # apa.save("tables_ezANOVA.doc", goggles_table, drink_table, dating_table) # delete demo file if (file.exists("tables_ezANOVA.doc")) { file.remove("tables_ezANOVA.doc") } }}}
if (requireNamespace("ez", quietly = TRUE)){ if (requireNamespace("apaTables", quietly = TRUE)){ if (requireNamespace("tidyr", quietly = TRUE)){ # # ** Example 1: Between Participant Predictors # goggles <- apaTables::goggles # Use ezANOVA # Be sure use the options command, as below, to ensure sufficient digits options(digits = 10) goggles_results <- ez::ezANOVA(data = goggles, dv = attractiveness, between = .(gender, alcohol), participant , detailed = TRUE) # Make APA table - save after all 3 examples goggles_table <- apa.ezANOVA.table(goggles_results) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(goggles_table) # # ** Example 2: Within Participant Predictors # drink_attitude_wide <- apaTables::drink_attitude_wide # Convert data from wide format to long format where one row represents one OBSERVATION. # Wide format column names MUST represent levels of each variable separated by an underscore. # See vignette for further details. drink_attitude_long <- tidyr::pivot_longer(drink_attitude_wide, cols = beer_positive:water_neutral, names_to = c("drink", "imagery"), names_sep = "_", values_to = "attitude") drink_attitude_long$drink <- as.factor(drink_attitude_long$drink) drink_attitude_long$imagery <- as.factor(drink_attitude_long$imagery) # Set contrasts to match Field et al. (2012) textbook output alcohol_vs_water <- c(1, 1, -2) beer_vs_wine <- c(-1, 1, 0) negative_vs_other <- c(1, -2, 1) positive_vs_neutral <- c(-1, 0, 1) contrasts(drink_attitude_long$drink) <- cbind(alcohol_vs_water, beer_vs_wine) contrasts(drink_attitude_long$imagery) <- cbind(negative_vs_other, positive_vs_neutral) # Use ezANOVA # Be sure use the options command, as below, to ensure sufficient digits options(digits = 10) drink_attitude_results <- ez::ezANOVA(data = drink_attitude_long, dv = .(attitude), wid = .(participant), within = .(drink, imagery), type = 3, detailed = TRUE) # Make APA table - save after all 3 examples drink_table <- apa.ezANOVA.table(drink_attitude_results) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(drink_table) # # ** Example 3: Between and Within Participant Predictors # dating_wide <- apaTables::dating_wide # Convert data from wide format to long format where one row represents one OBSERVATION. # Wide format column names MUST represent levels of each variable separated by an underscore. # See vignette for further details. dating_long <- tidyr::pivot_longer(dating_wide, cols = attractive_high:ugly_none, names_to = c("looks", "personality"), names_sep = "_", values_to = "date_rating") #' dating_long$looks <- as.factor(dating_long$looks) dating_long$personality <- as.factor(dating_long$personality) # Set contrasts to match Field et al. (2012) textbook output some_vs_none <- c(1, 1, -2) hi_vs_av <- c(1, -1, 0) attractive_vs_ugly <- c(1, 1, -2) attractive_vs_average <- c(1, -1, 0) contrasts(dating_long$personality) <- cbind(some_vs_none, hi_vs_av) contrasts(dating_long$looks) <- cbind(attractive_vs_ugly, attractive_vs_average) # Use ezANOVA options(digits = 10) dating_results <-ez::ezANOVA(data = dating_long, dv = .(date_rating), wid = .(participant), between = .(gender), within = .(looks, personality), type = 3, detailed = TRUE) # Make APA table - save after all 3 examples dating_table <- apa.ezANOVA.table(dating_results) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(dating_table) # # Saving all three tables # apa.save("tables_ezANOVA.doc", goggles_table, drink_table, dating_table) # delete demo file if (file.exists("tables_ezANOVA.doc")) { file.remove("tables_ezANOVA.doc") } }}}
Create output for papaja
apa.knit.table.for.papaja(table_object, latex_font_size = "footnotesize")
apa.knit.table.for.papaja(table_object, latex_font_size = "footnotesize")
table_object |
Previously constructed apaTable object |
latex_font_size |
A strijg that indicates normalsize, small, footnotesize, scriptsize |
Save status
Create latex output for an apaTables object
apa.knit.table.for.pdf( table_object, table_note = NULL, table_title = NULL, line_spacing = 1 )
apa.knit.table.for.pdf( table_object, table_note = NULL, table_title = NULL, line_spacing = 1 )
table_object |
Previously constructed apaTable object |
table_note |
Replace default table note with this text |
table_title |
Replace default table title with this text |
line_spacing |
Line spacing multiplier for table |
Save status
Creates a regresion table in APA style
apa.reg.table(..., filename = NA, table.number = 0, prop.var.conf.level = 0.95)
apa.reg.table(..., filename = NA, table.number = 0, prop.var.conf.level = 0.95)
... |
Regression (i.e., lm) result objects. Typically, one for each block in the regression. |
filename |
(optional) Output filename document filename (must end in .rtf or .doc only) |
table.number |
Integer to use in table number output line |
prop.var.conf.level |
Level of confidence (.90 or .95, default .95) for interval around sr2, R2, and Delta R2. Use of .90 confidence level helps to create consistency between the CI overlapping with zero and conclusions based on the p-value for that block (or block difference). |
APA table object
sr2 and delta R2 confidence intervals calculated via:
Alf Jr, E. F., & Graf, R. G. (1999). Asymptotic confidence limits for the difference between two squared multiple correlations: A simplified approach. Psychological Methods, 4(1), 70.
Note that Algina, Keselman, & Penfield (2008) found this approach can under some circumstances lead to inaccurate CIs on proportion of variance values. You might consider using the Algina, Keselman, & Penfield (2008) approach via the apa.reg.boot.table function
# View top few rows of goggles data set # from Discovering Statistics Using R head(album) # Single block example blk1 <- lm(sales ~ adverts + airplay, data=album) apa.reg.table(blk1) table1 <- apa.reg.table(blk1,table.number = 1) # Two block example, more than two blocks can be used blk1 <- lm(sales ~ adverts, data=album) blk2 <- lm(sales ~ adverts + airplay + attract, data=album) table2 <- apa.reg.table(blk1, blk2, table.number = 2) # Interaction product-term test with blocks blk1 <- lm(sales ~ adverts + airplay, data=album) blk2 <- lm(sales ~ adverts + airplay + I(adverts * airplay), data=album) table3 <- apa.reg.table(blk1, blk2, table.number = 3) # Interaction product-term test with blocks and additional product terms blk1<-lm(sales ~ adverts + airplay, data=album) blk2<-lm(sales ~ adverts + airplay + I(adverts*adverts) + I(airplay*airplay), data=album) blk3<-lm(sales~adverts+airplay+I(adverts*adverts)+I(airplay*airplay)+I(adverts*airplay),data=album) table4 <- apa.reg.table(blk1,blk2,blk3, table.number = 4) #Interaction product-term test with single regression (i.e., semi-partial correlation focus) blk1 <- lm(sales ~ adverts + airplay + I(adverts * airplay), data=album) table5 <- apa.reg.table(blk1, table.number = 5) # Save Table 1 in a .doc document apa.save(filename = "regression_tables.doc", table1, table2, table3, table4, table5) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) apa.knit.table.for.pdf(table2) apa.knit.table.for.pdf(table3) apa.knit.table.for.pdf(table4) apa.knit.table.for.pdf(table5) # delete demo file if (file.exists("regression_tables.doc")) { file.remove("regression_tables.doc") }
# View top few rows of goggles data set # from Discovering Statistics Using R head(album) # Single block example blk1 <- lm(sales ~ adverts + airplay, data=album) apa.reg.table(blk1) table1 <- apa.reg.table(blk1,table.number = 1) # Two block example, more than two blocks can be used blk1 <- lm(sales ~ adverts, data=album) blk2 <- lm(sales ~ adverts + airplay + attract, data=album) table2 <- apa.reg.table(blk1, blk2, table.number = 2) # Interaction product-term test with blocks blk1 <- lm(sales ~ adverts + airplay, data=album) blk2 <- lm(sales ~ adverts + airplay + I(adverts * airplay), data=album) table3 <- apa.reg.table(blk1, blk2, table.number = 3) # Interaction product-term test with blocks and additional product terms blk1<-lm(sales ~ adverts + airplay, data=album) blk2<-lm(sales ~ adverts + airplay + I(adverts*adverts) + I(airplay*airplay), data=album) blk3<-lm(sales~adverts+airplay+I(adverts*adverts)+I(airplay*airplay)+I(adverts*airplay),data=album) table4 <- apa.reg.table(blk1,blk2,blk3, table.number = 4) #Interaction product-term test with single regression (i.e., semi-partial correlation focus) blk1 <- lm(sales ~ adverts + airplay + I(adverts * airplay), data=album) table5 <- apa.reg.table(blk1, table.number = 5) # Save Table 1 in a .doc document apa.save(filename = "regression_tables.doc", table1, table2, table3, table4, table5) # Create a table for your PDF # Include the lines below in your rmarkdown or Quarto document apa.knit.table.for.pdf(table1) apa.knit.table.for.pdf(table2) apa.knit.table.for.pdf(table3) apa.knit.table.for.pdf(table4) apa.knit.table.for.pdf(table5) # delete demo file if (file.exists("regression_tables.doc")) { file.remove("regression_tables.doc") }
Save previously constructed APA table objects in a single .doc file
apa.save(filename, ..., paper = "us")
apa.save(filename, ..., paper = "us")
filename |
Filename (e.g., my.tables.doc) |
... |
apaTable objects to be saved |
paper |
Use "us" or "a4". Default is "us". |
Save status
library(apaTables) table1 <- apa.1way.table(iv = dose, dv = libido, data = viagra, table.number = 1) table2 <- apa.2way.table(iv1 = gender, iv2 = alcohol, dv = attractiveness, data = goggles, table.number = 1) apa.save(filename = "my.tables.doc", table1, table2) # delete demo file if (file.exists("my.tables.doc")) { file.remove("my.tables.doc") }
library(apaTables) table1 <- apa.1way.table(iv = dose, dv = libido, data = viagra, table.number = 1) table2 <- apa.2way.table(iv1 = gender, iv2 = alcohol, dv = attractiveness, data = goggles, table.number = 1) apa.save(filename = "my.tables.doc", table1, table2) # delete demo file if (file.exists("my.tables.doc")) { file.remove("my.tables.doc") }
A common task faced by researchers is the creation of APA style (i.e., American Psychological Association style) tables from statistical output. In R a large number of function calls are often needed to obtain all of the desired information for a single APA style table. As well, the process of manually creating APA style tables in a word processor is prone to transcription errors. This package creates Word files (.doc files) and latex code containing APA style tables for several types of analyses. Using this package minimizes transcription errors and reduces the number commands needed by the user. Examples are provided in this documentation and at http://www.StatsCanBeFun.com.
Bugs and feature requests can be reported at: https://github.com/dstanley4/apaTables/issues
Tutorial at: https://dstanley4.github.io/apaTables/articles/apaTables.html
Currently, the following tables can be created:
Correlation tables - Correlation tables (with confidence intervals and descriptive statistics) are created from data frames using apa.cor.table
.
Single "block" regression tables - Single "block" regression tables are created from a regression object using apa.reg.table
.
Multiple "block" regression tables - Multiple "block" regression tables are created from regression objects using apa.reg.table
.
ANOVA tables - An ANOVA F-table can be created via apa.aov.table
from a regression object (i.e. lm output or aov output). Cell mean/standard deviation tables for 1- and 2-way designs are created from data frames using apa.1way.table
and apa.2way.table
.
ezANOVA tables from ez package - An ANOVA F-table from ezANOVA output can be created via apa.ezANOVA.table
.
Standardized mean difference (i.e., d-value) tables (with confidence intervals and descriptive statistics) illustrating all possible paired comparisons using a single independent variable are created from data frames using apa.d.table
.
Package: | apaTables |
Type: | Package |
Version: | 3.0.0 |
Date: | 2023-06-29 |
License: | MIT |
Author: | David J. Stanley [email protected] |
Maintainer: | David J. Stanley [email protected] |
A data set from Field et al (2012)
data(dating_wide)
data(dating_wide)
A data frame with 20 rows and 11 columns. Gender is a between subjects variable. Looks and Personality are within subject variables. Both gender and particpant are factors.
Factor: Participant ID number
Factor: Gender: Male/Female
Date rating where looks=attractive and personality=high
Date rating where looks=average and personality=high
Date rating where looks=ugly and personality=high
Date rating where looks=attractive and personality=some
Date rating where looks=average and personality=some
Date rating where looks=ugly and personality=some
Date rating where looks=attractive and personality=none
Date rating where looks=average and personality=none
Date rating where looks=ugly and personality=none
https://studysites.sagepub.com/dsur/study/
Field, A., Miles, J., & Field, Z. (2012) Discovering Statistics Using R. Sage: Chicago.
A data set from Field et al (2012)
data(drink_attitude_wide)
data(drink_attitude_wide)
A data frame with 20 rows and 10 columns. Drink and Imagery are within subject variables. Particpant is a factor.
Factor: Participant ID number
Attitude where drink=beer and imagery=positive
Attitude where drink=beer and imagery=negative
Attitude where drink=beer and imagery=neutral
Attitude where drink=wine and imagery=positive
Attitude where drink=wine and imagery=negative
Attitude where drink=wine and imagery=neutral
Attitude where drink=water and imagery=positive
Attitude where drink=water and imagery=negative
Attitude where drink=water and imagery=neutral
https://studysites.sagepub.com/dsur/study/
Field, A., Miles, J., & Field, Z. (2012) Discovering Statistics Using R. Sage: Chicago.
A data set from Howell (2012)
data(Eysenck)
data(Eysenck)
A data frame with 100 rows and 3 variables:
Young or Old
Experimental learning condition
Level of word recall
https://www.uvm.edu/~statdhtx/methods8/DataFiles/Tab13-2.dat
Howell, D. (2012). Statistical methods for psychology. Cengage Learning.
A data set from Fidler & Thompson (2001)
data(fidler_thompson)
data(fidler_thompson)
A data frame with 24 rows and 3 variables:
Independent variable: a
Independent variable: b
Dependent variable: dv
Fidler, F. & Thompson, B. (2001). Computing correct confidence intervals for ANOVA fixed- and random-effects effect sizes. Educational and Psychological Measurement, 61, 575-604.
Calculates confidence interval for partial eta-squared in a fixed-effects ANOVA
get.ci.partial.eta.squared(F.value, df1, df2, conf.level = 0.9)
get.ci.partial.eta.squared(F.value, df1, df2, conf.level = 0.9)
F.value |
The F-value for the fixed-effect |
df1 |
Degrees of freedom for the fixed-effect |
df2 |
Degrees of freedom error |
conf.level |
Confidence level (0 to 1). For partial eta-squared a confidence level of .90 is traditionally used rather than .95. |
List with confidence interval values (LL and UL)
# Smithson (2001) p. 619 get.ci.partial.eta.squared(F.value=6.00, df1=1, df2=42, conf.level=.90) get.ci.partial.eta.squared(F.value=2.65, df1=6, df2=42, conf.level=.90) get.ci.partial.eta.squared(F.value=2.60, df1=6, df2=42, conf.level=.90) # Fidler & Thompson (2001) Fixed Effects 2x4 p. 594 (Table 6) / p. 596 (Table 8) get.ci.partial.eta.squared(F.value=1.50, df1=1, df2=16, conf.level=.90) get.ci.partial.eta.squared(F.value=4.00, df1=3, df2=16, conf.level=.90) get.ci.partial.eta.squared(F.value=1.50, df1=3, df2=16, conf.level=.90)
# Smithson (2001) p. 619 get.ci.partial.eta.squared(F.value=6.00, df1=1, df2=42, conf.level=.90) get.ci.partial.eta.squared(F.value=2.65, df1=6, df2=42, conf.level=.90) get.ci.partial.eta.squared(F.value=2.60, df1=6, df2=42, conf.level=.90) # Fidler & Thompson (2001) Fixed Effects 2x4 p. 594 (Table 6) / p. 596 (Table 8) get.ci.partial.eta.squared(F.value=1.50, df1=1, df2=16, conf.level=.90) get.ci.partial.eta.squared(F.value=4.00, df1=3, df2=16, conf.level=.90) get.ci.partial.eta.squared(F.value=1.50, df1=3, df2=16, conf.level=.90)
A data set from Field et al (2012)
data(goggles)
data(goggles)
A data frame with 48 rows and 3 variables:
Participant identification number
Gender of participant
Amount alcohol consumed
Perceived attractiveness
https://studysites.sagepub.com/dsur/study/
Field, A., Miles, J., & Field, Z. (2012) Discovering Statistics Using R. Sage: Chicago.
A data set from Field et al (2012)
data(viagra)
data(viagra)
A data frame with 15 rows and 2 variables:
Level of viagra dose
Libido after taking viagra
https://studysites.sagepub.com/dsur/study/
Field, A., Miles, J., & Field, Z. (2012) Discovering Statistics Using R. Sage: Chicago.