Version Note: Up-to-date with v0.5.0
knitr::opts_chunk$set(message=FALSE,warning = FALSE, comment = NA) old.hooks <- fansi::set_knit_hooks(knitr::knit_hooks)
library(psycModel)
TLDR:
1) It's a beginner-friendly R package for statistical analysis in social science.
2) Fitting models, plotting, checking the goodness of fit, and identifying model assumption violations all in one place.
3) Beautiful and easy-to-read output. Check out this example now.
The model_summary
function will produce all of the relevant test statistics for regression models. See an example below.
mod_1 = lm(data = iris, Petal.Length ~ Petal.Width*Sepal.Length) # you can also check assumption_plot by setting assumption_plot = TRUE model_summary(mod_1,assumption_plot = F)
Since our models have an interaction, we may want to visualize it. Let's create an interaction plot first. You can modify the plot using some of the settings. You can also try out the polynomial regression plots and the ANOVA plots.
interaction_plot(mod_1,verbose = F) # verbose is set to TRUE by default to show the plot data. # You can also modify the interaction_plot(mod_1, response_var_name = 'Petal Length', # you can rename the variable names (e.g., getting rid of the dot) predict_var1_name = 'Petal Width', predict_var2_name = 'Sepal Length', predict_var1_level = c(0.44,1.19,1.96), # you may want to show the mean of the variable predict_var1_level_name = c('-1 SD','Mean','+1 SD'), # you may also want to adjust the labels to be more intuitive verbose = F)
After obtaining the interaction plot, you may also want to get the simple slopes of the interaction.
simple_slope(mod_1)
This package can also help you in preparing a table that includes means, standard deviations, and correlations. For additional options, refer to ?descriptive_table
.
descriptive_table(iris,c(Petal.Width,Sepal.Length,Petal.Length)) descriptive_table(iris,c(Petal.Width,Sepal.Length,Petal.Length),descriptive_indicator = c('mean','sd','cor','missing','kurtosis')) # you can request more parameters optionally
You can get the Cronbach alphas very simply (it will call the psych::alpha()
function). If you need, you can also get separate Cronbach alphas by groups (e.g., when using multilevel analyses).
cronbach_alpha(x1:x3,x4:x6,x7:x9, var_name = c('visual','textual','verbal'), data = lavaan::HolzingerSwineford1939) cronbach_alpha(x1:x3,x4:x6,x7:x9, var_name = c('visual','textual','verbal'), group = 'sex', data = lavaan::HolzingerSwineford1939)
CFA model is fitted using lavaan::cfa()
. You can pass multiple factor (in the below example, x1, x2, x3 represent one factor, x4,x5,x6 represent another factor etc.). It will show you the fit measure, factor loading, and goodness of fit based on cut-off criteria (you should review literature for the cut-off criteria as the recommendations are subjected to changes). You can also try measurement_invariance()
.
cfa_summary( data = lavaan::HolzingerSwineford1939, x1:x3, x4:x6, x7:x9 )
if you want to produce these beautiful output in R Markdown. Calls this function and see the most up-to-date advice.
knit_to_Rmd()
This conclude my briefed discussion of this package. I hope you enjoy the package, and please let me know if you have any feedback. If you like it, please considering giving a star on GitHub. Thank you.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.