jtools
jtools: Analysis and Presentation of Social Scientific Data - Published in JOSS (2024)
Science Score: 93.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 4 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org -
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
r
r-package
social-sciences
Scientific Fields
Earth and Environmental Sciences
Physical Sciences -
40% confidence
Last synced: 6 months ago
·
JSON representation
Repository
Tools for summarizing/visualizing regressions and other helpful stuff
Basic Info
- Host: GitHub
- Owner: jacob-long
- License: gpl-3.0
- Language: R
- Default Branch: master
- Homepage: https://jtools.jacob-long.com
- Size: 72.5 MB
Statistics
- Stars: 167
- Watchers: 5
- Forks: 23
- Open Issues: 22
- Releases: 4
Topics
r
r-package
social-sciences
Created about 9 years ago
· Last pushed over 1 year ago
Metadata Files
Readme
Changelog
Contributing
License
README.Rmd
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = FALSE,
comment = "#>",
fig.path = "man/figures/",
fig.width = 6.5,
fig.height = 4,
render = knitr::normal_print,
# dev.args=list(type="cairo"),
# dev = "CairoPNG",
dpi = 175,
retina = 1
)
library(jtools)
```
# jtools
[](https://cran.r-project.org/package=jtools)
[](https://cran.r-project.org/package=jtools)
[](https://bestpractices.coreinfrastructure.org/projects/2527)
[](https://github.com/jacob-long/jtools/actions)
[](https://ci.appveyor.com/project/jacob-long/JTools)
[](https://app.codecov.io/gh/jacob-long/jtools)
[](https://doi.org/10.21105/joss.06610)
[](https://www.gnu.org/licenses/gpl-3.0)
This package consists of a series of functions created by the author (Jacob)
to automate otherwise tedious research tasks. At this juncture, the unifying
theme is the more efficient presentation of regression analyses. There are
a number of functions for other programming and statistical purposes as
well. Support for the `survey` package's `svyglm` objects as well as weighted
regressions is a common theme throughout.
**Notice:** As of `jtools` version 2.0.0, all functions dealing with
interactions (e.g., `interact_plot()`, `sim_slopes()`, `johnson_neyman()`) have
been moved to a new package, aptly named
[`interactions`](https://interactions.jacob-long.com).
## Installation
For the most stable version, simply install from CRAN.
```r
install.packages("jtools")
```
If you want the latest features and bug fixes then you can download from
Github. To do that you will need to have `devtools` installed if you don't
already:
```r
install.packages("devtools")
```
Then install the package from Github.
```r
devtools::install_github("jacob-long/jtools")
```
To see what features are on the roadmap, check the issues
section of the repository, especially the "enhancement" tag. Closed issues
may be of interest, too, since they may be fixed in the Github version but not
yet submitted to CRAN.
## Usage
Here's a synopsis of the current functions in the package:
### Console regression summaries (`summ()`)
`summ()` is a replacement for `summary()` that provides the user several options
for formatting regression summaries. It supports `glm`, `svyglm`, and `merMod`
objects as input as well. It supports calculation and reporting of
robust standard errors via the `sandwich` package.
Basic use:
```{r}
data(movies)
fit <- lm(metascore ~ budget + us_gross + year, data = movies)
summ(fit)
```
It has several conveniences, like re-fitting your model with
scaled variables (`scale = TRUE`). You have the option to leave the
outcome variable in its original scale (`transform.response = TRUE`),
which is the default for scaled models. I'm a fan of Andrew Gelman's 2
SD standardization method, so you can specify by how many standard deviations
you would like to rescale (`n.sd = 2`).
You can also get variance inflation factors (VIFs) and partial/semipartial
(AKA part) correlations. Partial correlations are only available for OLS
models. You may also substitute confidence intervals in place of standard
errors and you can choose whether to show p values.
```{r}
summ(fit, scale = TRUE, vifs = TRUE, part.corr = TRUE, confint = TRUE, pvals = FALSE)
```
Cluster-robust standard errors:
```{r}
data("PetersenCL", package = "sandwich")
fit2 <- lm(y ~ x, data = PetersenCL)
summ(fit2, robust = "HC3", cluster = "firm")
```
Of course, `summ()` like `summary()` is best-suited for interactive use. When
it comes to sharing results with others, you want sharper output and probably
graphics. `jtools` has some options for that, too.
### LaTeX-, Word-, and RMarkdown-friendly regression summary tables (`export_summs()`)
For tabular output, `export_summs()` is an interface to the `huxtable`
package's `huxreg()` function that preserves the niceties of `summ()`,
particularly its facilities for robust standard errors and standardization.
It also concatenates multiple models into a single table.
```{r eval = F}
fit <- lm(metascore ~ log(budget), data = movies)
fit_b <- lm(metascore ~ log(budget) + log(us_gross), data = movies)
fit_c <- lm(metascore ~ log(budget) + log(us_gross) + runtime, data = movies)
coef_names <- c("Budget" = "log(budget)", "US Gross" = "log(us_gross)",
"Runtime (Hours)" = "runtime", "Constant" = "(Intercept)")
export_summs(fit, fit_b, fit_c, robust = "HC3", coefs = coef_names)
```
```{r echo = FALSE, results = 'asis', warning = FALSE, eval = T}
# huxtable doesn't render right for the github_document, seems to thinks it's
# in the console
fit <- lm(metascore ~ log(budget), data = movies)
fit_b <- lm(metascore ~ log(budget) + log(us_gross), data = movies)
fit_c <- lm(metascore ~ log(budget) + log(us_gross) + runtime, data = movies)
coef_names <- c("Budget" = "log(budget)", "US Gross" = "log(us_gross)",
"Runtime (Hours)" = "runtime", "Constant" = "(Intercept)")
e <- export_summs(fit, fit_b, fit_c, robust = "HC3", coefs = coef_names)
huxtable::print_html(e)
```
In RMarkdown documents, using `export_summs()` and the chunk option
`results = 'asis'` will give you nice-looking tables in HTML and PDF
output. Using the `to.word = TRUE` argument will create a Microsoft Word
document with the table in it.
### Plotting regression summaries (`plot_coefs()` and `plot_summs()`)
Another way to get a quick gist of your regression analysis is to
plot the values of the coefficients and their corresponding uncertainties
with `plot_summs()` (or the closely related `plot_coefs()`).
Like with `export_summs()`, you can still get your scaled
models and robust standard errors.
```{r}
coef_names <- coef_names[1:3] # Dropping intercept for plots
plot_summs(fit, fit_b, fit_c, robust = "HC3", coefs = coef_names)
```
And since you get a `ggplot` object in return, you can tweak and theme as
you wish.
Another way to visualize the uncertainty of your coefficients is via the
`plot.distributions` argument.
```{r}
plot_summs(fit_c, robust = "HC3", coefs = coef_names, plot.distributions = TRUE)
```
These show the 95% interval width of a normal distribution for each estimate.
`plot_coefs()` works much the same way, but without support for `summ()`
arguments like `robust` and `scale`. This enables a wider range of
models that have support from the `broom` package but not for `summ()`.
### Plotting model predictions (`effect_plot()`)
Sometimes the best way to understand your model is to look at the predictions
it generates. Rather than look at coefficients, `effect_plot()` lets you plot
predictions across values of a predictor variable alongside the observed data.
```{r}
effect_plot(fit_c, pred = runtime, interval = TRUE, plot.points = TRUE)
```
And a new feature in version `2.0.0` lets you plot *partial residuals*
instead of the raw observed data, allowing you to assess model quality after
accounting for effects of control variables.
```{r}
effect_plot(fit_c, pred = runtime, interval = TRUE, partial.residuals = TRUE)
```
Categorical predictors, polynomial terms, (G)LM(M)s, weighted data, and much
more are supported.
### Other stuff
There are several other things that might interest you.
* `gscale()`: Scale and/or mean-center data, including `svydesign` objects
* `scale_mod()` and `center_mod()`: Re-fit models with scaled and/or
mean-centered data
* `wgttest()` and `pf_sv_test()`, which are combined in `weights_tests()`:
Test the ignorability of sample weights in regression models
* `svycor()`: Generate correlation matrices from `svydesign` objects
* `theme_apa()`: A mostly APA-compliant `ggplot2` theme
* `theme_nice()`: A nice `ggplot2` theme
* `add_gridlines()` and `drop_gridlines()`: `ggplot2` theme-changing
convenience functions
* `make_predictions()`: an easy way to generate hypothetical predicted data
from your regression model for plotting or other purposes.
Details on the arguments can be accessed via the R documentation
(`?functionname`).
There are now vignettes documenting just about everything you can do as well.
## Contributing
I'm happy to receive bug reports, suggestions, questions, and (most of all)
contributions to fix problems and add features. I prefer you use the Github
issues system over trying to reach out to me in other ways. Pull requests for
contributions are encouraged. If you are considering writing up a bug fix
or new feature, please check out the [contributing guidelines](https://github.com/jacob-long/jtools/blob/master/CONTRIBUTING.md).
Please note that this project is released with a
[Contributor Code of Conduct](https://github.com/jacob-long/jtools/blob/master/CONDUCT.md). By participating in this project
you agree to abide by its terms.
## License
This package is licensed under the
[GPLv3 license](https://spdx.org/licenses/GPL-3.0-or-later.html) or any
later version.
Owner
- Name: Jacob Long
- Login: jacob-long
- Kind: user
- Location: Columbia, South Carolina
- Company: University of South Carolina
- Website: https://jacob-long.com
- Twitter: jacobandrewlong
- Repositories: 5
- Profile: https://github.com/jacob-long
I'm an Assistant Professor in the School of Journalism and Mass Communications at the University of South Carolina.
JOSS Publication
jtools: Analysis and Presentation of Social Scientific Data
Published
September 06, 2024
Volume 9, Issue 101, Page 6610
Authors
Tags
social science regressionGitHub Events
Total
- Issues event: 4
- Watch event: 4
- Issue comment event: 6
- Fork event: 2
Last Year
- Issues event: 4
- Watch event: 4
- Issue comment event: 6
- Fork event: 2
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Jacob Long | j****c@g****m | 1,054 |
| Noah Greifer | n****r@g****m | 3 |
| Duncan Murdoch | m****n@g****m | 2 |
| victorhartman | v****n@g****m | 1 |
| NickCH-K | 4****K | 1 |
| Alan O'Callaghan | a****n@o****m | 1 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 99
- Total pull requests: 10
- Average time to close issues: about 1 year
- Average time to close pull requests: about 1 month
- Total issue authors: 85
- Total pull request authors: 6
- Average comments per issue: 1.54
- Average comments per pull request: 0.5
- Merged pull requests: 9
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 4
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 4
- Pull request authors: 0
- Average comments per issue: 1.25
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- mattmoo (4)
- jacob-long (3)
- mattysimonson (3)
- misken (2)
- martinzuba (2)
- e-leib (2)
- samuelsaari (2)
- blueja5 (2)
- ChrisWaloszek (2)
- ghost (2)
- tci1 (1)
- MbaliNen (1)
- JJery-web (1)
- victorhartman (1)
- DonaKireta (1)
Pull Request Authors
- jacob-long (8)
- victorhartman (2)
- olivroy (2)
- alanocallaghan (1)
- NickCH-K (1)
- dmurdoch (1)
Top Labels
Issue Labels
bug (48)
enhancement (33)
external-bug (3)
question (1)
Pull Request Labels
Dependencies
DESCRIPTION
cran
- R >= 3.5.0 depends
- brms * enhances
- quantreg * enhances
- rstanarm * enhances
- crayon * imports
- generics * imports
- ggplot2 >= 3.3.0 imports
- magrittr * imports
- pander * imports
- pkgconfig * imports
- rlang >= 0.3.0 imports
- tibble * imports
- MASS * suggests
- RColorBrewer * suggests
- boot * suggests
- broom * suggests
- broom.mixed * suggests
- ggstance * suggests
- huxtable >= 3.0.0 suggests
- kableExtra * suggests
- knitr * suggests
- lme4 * suggests
- lmerTest * suggests
- methods * suggests
- pbkrtest * suggests
- rmarkdown * suggests
- sandwich * suggests
- scales * suggests
- survey * suggests
- testthat * suggests
- vdiffr * suggests
- weights * suggests
.github/workflows/R-CMD-check.yaml
actions
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/check-r-package v1 composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v1 composite
- r-lib/actions/setup-r-dependencies v1 composite
.github/workflows/pkgdown.yaml
actions
- actions/checkout v2 composite
- nwtgck/actions-netlify v1.1 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- r-lib/actions/setup-tinytex v2 composite
.github/workflows/test-coverage.yaml
actions
- actions/checkout v2 composite
- r-lib/actions/setup-r v1 composite
- r-lib/actions/setup-r-dependencies v1 composite
