knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", message = FALSE, warning = FALSE )
This package includes some custom-made functions to facilitate some common statistical procedures as well as extracting and reporting results from various models in RMarkdown articles. Please note that most functions are highly costumized to my personal workflow. They may hence break in more general frameworks or when used in a different, non-intended way...
Most functions require the following packages:
tidyverse
and magrittr
papaja
lavaan
and semTools
These packages should be installed prior to using this package.
You can install the development version from GitHub with:
# install.packages("devtools") devtools::install_github("masurp/pmstats")
library(pmstats) (tab <- zero_order_corr(mtcars[,1:6], digits = 2, sig = T, print = T))
papaja::apa_table(tab, format = "html", align = c("l", rep("r", 6)))
library(lavaan) # Estimate SEM model.sem <- ' # latent variables ind60 =~ x1 + x2 + x3 dem60 =~ y1 + y2 + y3 + y4 dem65 =~ y5 + y6 + y7 + y8 # regressions dem60 ~ a*ind60 dem65 ~ b*ind60 + c*dem60 # residual covariances y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit.sem <- sem(model.sem, data = PoliticalDemocracy) # Extracting results (only regression paths ) results <- result_table(fit.sem, sem_regressions = TRUE, new_labels = c("H1", "H2", "H3"), print = TRUE)
papaja::apa_table(results, format = "html", align = c(rep("c", 3), rep("r", 6)))
# Print specific results for inline reporting print_coeff(results, "H2", se = FALSE, beta = TRUE)
x <- rnorm(500, 2, 1) z <- rnorm(500, 2, 1) y <- 0.5*x + 1.5*(z*x) + rnorm(500, 0, 3.5) # Estimate linear model mod.lm <- lm(y ~ x + z + x:z) summary(mod.lm) # Plot model moderation_plot(mod.lm, x = "x", m = "z")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.