italic
bold
code
superscript2
–strikethrough–
Horizontal line:
block quote
block quote with bold and italic text
list
list
list
list
Equation using LaTeX formatting:
\(\pi*r^{2}\)
Insert a code chunk with
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.0 v dplyr 1.0.5
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 4.0.3
## Warning: package 'tibble' was built under R version 4.0.4
## Warning: package 'dplyr' was built under R version 4.0.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x ggplot2::%+%() masks psych::%+%()
## x ggplot2::alpha() masks psych::alpha()
## x purrr::compose() masks flextable::compose()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
penguins %>%
group_by(sex) %>%
drop_na(sex) %>%
summarize(mean = mean(body_mass_g))
## # A tibble: 2 x 2
## sex mean
## <fct> <dbl>
## 1 female 3862.
## 2 male 4546.
detach("package:tidyverse", unload = TRUE) #unloading for purposes of next chunk
library(tidyverse)
penguins %>%
group_by(sex) %>%
drop_na(sex) %>%
summarize(mean = mean(body_mass_g))
## # A tibble: 2 x 2
## sex mean
## <fct> <dbl>
## 1 female 3862.
## 2 male 4546.
penguins %>%
group_by(sex) %>%
drop_na(sex) %>%
summarize(mean = mean(body_mass_g))
## # A tibble: 2 x 2
## sex mean
## <fct> <dbl>
## 1 female 3862.
## 2 male 4546.
penguins %>%
group_by(sex) %>%
drop_na(sex) %>%
summarize(mean = mean(body_mass_g))
## # A tibble: 2 x 2
## sex mean
## <fct> <dbl>
## 1 female 3862.
## 2 male 4546.
species | female | male |
Adelie | 73 | 73 |
Chinstrap | 34 | 34 |
Gentoo | 58 | 61 |
There are a number of packages that are useful for making tables, especially from statistical results. Let’s run a few analyses and see.
The default t-test output is a mess
##
## Two Sample t-test
##
## data: body_mass_g by sex
## t = -8.5417, df = 331, p-value = 4.897e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -840.8014 -526.0222
## sample estimates:
## mean in group female mean in group male
## 3862.273 4545.685
We can use the broom::tidy package to get the model estimates and with a little renaming make a nice table:
mean diff | female | male | t | p.value | parameter | conf.low | conf.high | method | alternative |
-683 | 3,862 | 4,546 | -8.5 | 4.9e-16 | 331 | -841 | -526 | Two Sample t-test | two.sided |
There are a number of ways to make a regression table, including the use of broom::tidy. The modelsummary package makes it even easier! The result below is just the basic output. There are a lot of customization options, includng which model statistics are or are not included.
This is output as a flextable so it can be knitted in Word.
| Model 1 | Model 2 |
(Intercept) | 3862.273 | -1500.029 |
(56.829) | (575.822) | |
sexmale | 683.412 | 387.224 |
(80.009) | (48.138) | |
bill_depth_mm | 67.575 | |
(19.821) | ||
bill_length_mm | 18.189 | |
(7.136) | ||
flipper_length_mm | 16.239 | |
(2.939) | ||
islandDream | -13.103 | |
(58.541) | ||
islandTorgersen | -48.064 | |
(60.922) | ||
speciesChinstrap | -260.306 | |
(88.551) | ||
speciesGentoo | 987.761 | |
(137.238) | ||
Num.Obs. | 333 | 333 |
R2 | 0.181 | 0.875 |
R2 Adj. | 0.178 | 0.872 |
AIC | 5340.0 | 4727.2 |
BIC | 5351.4 | 4765.3 |
Log.Lik. | -2666.979 | -2353.621 |
F | 72.961 | 284.079 |
This example extracts eigenvalues from a simple psych and makes it into a table.
Property | MR1 | MR2 | MR3 | MR4 |
SS loadings | 2.18 | 0.58 | 0.117 | 0.00 |
Proportion Var | 0.54 | 0.15 | 0.029 | 0.00 |
Cumulative Var | 0.54 | 0.69 | 0.720 | 0.72 |
Proportion Explained | 0.76 | 0.20 | 0.041 | 0.00 |
Cumulative Proportion | 0.76 | 0.96 | 1.000 | 1.00 |
The psych output for an EFA can get quite messy and be hard to work with. I wrote the function fa_table to easily display the results and remove loadings under a specified cut value.
item | MR1 | MR2 | MR3 | MR4 | Communality | Uniqueness | Complexity |
body_mass_g | 0.932 | 0.80 | 0.201 | 1.0 | |||
flipper_length_mm | 0.791 | 0.99 | 0.005 | 1.3 | |||
bill_length_mm | 0.718 | 0.58 | 0.416 | 1.3 | |||
bill_depth_mm | 0.606 | 0.50 | 0.498 | 1.1 |
SEM estimates can be displayed like any other dataframe. You can use semPlot or lavaanPlot to easily display path diagrams, too.
lhs | op | rhs | est | se | z | pvalue | ci.lower | ci.upper | std.all |
visual | =~ | x1 | 1.00 | 0.000 | 1.000 | 1.00 | 0.77 | ||
visual | =~ | x2 | 0.55 | 0.100 | 5.6 | 2.8e-08 | 0.358 | 0.75 | 0.42 |
visual | =~ | x3 | 0.73 | 0.109 | 6.7 | 2.3e-11 | 0.516 | 0.94 | 0.58 |
textual | =~ | x4 | 1.00 | 0.000 | 1.000 | 1.00 | 0.85 | ||
textual | =~ | x5 | 1.11 | 0.065 | 17.0 | 0.0e+00 | 0.985 | 1.24 | 0.86 |
textual | =~ | x6 | 0.93 | 0.055 | 16.7 | 0.0e+00 | 0.817 | 1.03 | 0.84 |
speed | =~ | x7 | 1.00 | 0.000 | 1.000 | 1.00 | 0.57 | ||
speed | =~ | x8 | 1.18 | 0.165 | 7.2 | 8.6e-13 | 0.857 | 1.50 | 0.72 |
speed | =~ | x9 | 1.08 | 0.151 | 7.2 | 8.4e-13 | 0.785 | 1.38 | 0.67 |
x1 | ~~ | x1 | 0.55 | 0.114 | 4.8 | 1.3e-06 | 0.326 | 0.77 | 0.40 |
x2 | ~~ | x2 | 1.13 | 0.102 | 11.1 | 0.0e+00 | 0.934 | 1.33 | 0.82 |
x3 | ~~ | x3 | 0.84 | 0.091 | 9.3 | 0.0e+00 | 0.667 | 1.02 | 0.66 |
x4 | ~~ | x4 | 0.37 | 0.048 | 7.8 | 7.3e-15 | 0.278 | 0.46 | 0.27 |
x5 | ~~ | x5 | 0.45 | 0.058 | 7.6 | 2.1e-14 | 0.332 | 0.56 | 0.27 |
x6 | ~~ | x6 | 0.36 | 0.043 | 8.3 | 2.2e-16 | 0.272 | 0.44 | 0.30 |
x7 | ~~ | x7 | 0.80 | 0.081 | 9.8 | 0.0e+00 | 0.640 | 0.96 | 0.68 |
x8 | ~~ | x8 | 0.49 | 0.074 | 6.6 | 4.9e-11 | 0.342 | 0.63 | 0.48 |
x9 | ~~ | x9 | 0.57 | 0.071 | 8.0 | 1.1e-15 | 0.427 | 0.70 | 0.56 |
visual | ~~ | visual | 0.81 | 0.145 | 5.6 | 2.6e-08 | 0.524 | 1.09 | 1.00 |
textual | ~~ | textual | 0.98 | 0.112 | 8.7 | 0.0e+00 | 0.760 | 1.20 | 1.00 |
speed | ~~ | speed | 0.38 | 0.086 | 4.5 | 8.5e-06 | 0.215 | 0.55 | 1.00 |
visual | ~~ | textual | 0.41 | 0.074 | 5.6 | 2.8e-08 | 0.264 | 0.55 | 0.46 |
visual | ~~ | speed | 0.26 | 0.056 | 4.7 | 3.2e-06 | 0.152 | 0.37 | 0.47 |
textual | ~~ | speed | 0.17 | 0.049 | 3.5 | 4.3e-04 | 0.077 | 0.27 | 0.28 |
It’s easy to include references in a R Markdown document. You will need to set a citation style (and include a CSL file) and a bibliography file (you can export these from Zotero, Mendely, etc.) in the YAML. It looks like this:
bibliography: example.bib
csl: apa.csl
Then you can easily write references using square brackets and the @ symbol. There is also an RStudio addin called citr that allows you do search your .bib file and insert citations via point-and-click.
Blah blah (see Rocconi et al., 2020, pp. 33–35; also Morrow & Ackermann, 2012, ch. 1).
Blah blah (Rocconi et al., 2020, pp. 33–35, 38–39).
Blah blah (Morrow & Ackermann, 2012; Rocconi et al., 2020).
Blah blah (see Rocconi et al., 2020, pp. 33–35; also Morrow & Ackermann, 2012, ch. 1).
Blah blah (Morrow & Ackermann, 2012, pp. 33–35, 38–39).
Blah blah (Morrow & Ackermann, 2012; Rocconi et al., 2020).
The reference list will appear at the end by default or you can place it manuualy using <div id="refs"></div>.
Morrow, J., & Ackermann, M. (2012). Intention to persist and retention of first-year students: The importance of motivation and sense of belonging. College Student Journal, 46(3), 483–491.
Rocconi, L. M., Liu, X., & Pike, G. R. (2020). The impact of person-environment fit on grades, perceived gains, and satisfaction: An application of holland’s theory. Higher Education, 1–18.
Write a book using bookdown
Make a website using blogdown