Skip to content

Commit

Permalink
Merge pull request #13 from brianmsm/update-version-to-0.1.4
Browse files Browse the repository at this point in the history
Update version to 0.1.4
  • Loading branch information
brianmsm authored Nov 12, 2024
2 parents b5ed93f + 8be36d7 commit 9a42e1a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: psymetrics
Type: Package
Title: Tools for Psychometric Analysis
Version: 0.1.3
Version: 0.1.4
Authors@R:
person(
given = "Brian",
Expand Down
21 changes: 21 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# psymetrics 0.1.4

## New Features

- **save_table()**: A new utility function for saving tables generated from model outputs to different formats, starting with Word (`.docx`). This function automatically checks for the necessary packages (`flextable` and `officer`) and provides formatting for tables in accordance with APA style. Key features:
- Default template in landscape orientation.
- Options to customize the file path and template.
- Digit precision control, with options for different font styles and cell alignment.

- **plot() method for lavaan objects**: Introduced a `plot` method specifically designed for `lavaan` objects, enabling users to easily visualize key model results. Supported plots:
- **Factor Loadings Plot** (`type = "loadings"`): Displays standardized factor loadings for CFA models with options to display confidence intervals and adjust axis limits.
- **Residuals Plot** (`type = "residuals"`) (future): Will display residuals for model diagnostics and evaluation.
- **Path Diagram Plot** (`type = "path"`) (future): Will generate path diagrams for SEM models.

The factor loadings plot includes parameters for sorting and grouping items, along with flexible display options for confidence intervals and standardized estimates.

## Bug Fixes and Improvements

- **Internal Function Enhancements**: Improved `prepare_table` function for consistent table formatting across different outputs. This includes automatic rounding and character conversion for key columns (`NOBS`, `NPAR`, `Chi2_df`) where applicable.
- **Improved Handling of Global Variables**: Adopted `.data` pronoun within `ggplot2` to avoid unnecessary global variable bindings and improve compatibility with `R CMD check`.

# psymetrics 0.1.3

## New Features
Expand Down
29 changes: 26 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
output: github_document
editor_options:
chunk_output_type: console
---

<!-- README.md is generated from README.Rmd. Please edit that file -->
Expand All @@ -15,8 +17,8 @@ knitr::opts_chunk$set(

# psymetrics

<!-- badges: start -->
<!-- badges: end -->
<!-- badges: start --> <!-- badges: end -->
<img src="man/figures/hexlogo.png" align="right" width="120" />

The goal of psymetrics is to provide tools for extracting and visualizing psychometric model fit indices. It is compatible with models created using packages like lavaan, psych, and mirt.

Expand All @@ -26,7 +28,7 @@ You can install the development version of psymetrics from [GitHub](https://gith

``` r
# install.packages("pak")
pak::pak("brianmsm/[email protected].3")
pak::pak("brianmsm/[email protected].4")
```

## Getting Fit Indices
Expand Down Expand Up @@ -91,4 +93,25 @@ print(fit_table, format = "markdown")
cat(print(fit_table, format = "markdown"), sep = "\n")
```

## Saving Fit Indices to Word

The `save_table()` function allows you to export the fit indices to a Word document (.docx) with APA-style formatting and optional templates for vertical or landscape orientation.

```{r}
#| eval: false
# Save the fit comparison table to Word
save_table(fit_table, path = "model_fit.docx", orientation = "landscape")
```

The exported document will have a clean and professional format that you can directly include in reports or presentations.

## Plotting Factor Loadings

You can visualize the factor loadings of your model with the `plot_factor_loadings()` function. This function creates a dot plot of standardized factor loadings, with the option to display confidence intervals for each loading.

```{r}
plot_factor_loadings(fit)
```

In this example, plot_factor_loadings() displays the factor loadings for each item on the respective factors, with confidence intervals. The plot can be adjusted to automatically scale the x-axis or group items by factor.

46 changes: 40 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<!-- badges: start -->
<!-- badges: end -->

<img src="man/figures/hexlogo.png" align="right" width="120" />

The goal of psymetrics is to provide tools for extracting and
visualizing psychometric model fit indices. It is compatible with models
created using packages like lavaan, psych, and mirt.
Expand All @@ -17,7 +19,7 @@ You can install the development version of psymetrics from

``` r
# install.packages("pak")
pak::pak("brianmsm/[email protected].3")
pak::pak("brianmsm/[email protected].4")
```

## Getting Fit Indices
Expand All @@ -28,7 +30,7 @@ created using lavaan.
``` r
library(psymetrics)
library(lavaan)
#> This is lavaan 0.6-18
#> This is lavaan 0.6-19
#> lavaan is FREE software! Please report any bugs.

# Define a simple CFA model
Expand Down Expand Up @@ -94,10 +96,10 @@ reports or web pages.
print(fit_table, format = "html")
```

| MODEL | NOBS | ESTIMATOR | NPAR | Chi2(24) | p (Chi2) | CFI | TLI | RMSEA | RMSEA CI | SRMR |
|-------|------|-----------|------|----------|----------|-------|-------|-------|------------------|-------|
| fit_1 | 301 | MLR | 21 | 87.132 | \< .001 | 0.925 | 0.888 | 0.093 | \[0.073, 0.115\] | 0.065 |
| fit_2 | 301 | ULSM | 21 | 90.600 | \< .001 | 0.931 | 0.897 | 0.096 | \[0.073, 0.120\] | 0.059 |
| MODEL | NOBS | ESTIMATOR | NPAR | Chi2(24) | p (Chi2) | CFI | TLI | RMSEA | RMSEA CI | SRMR |
|----|----|----|----|----|----|----|----|----|----|----|
| fit_1 | 301 | MLR | 21 | 87.132 | \< .001 | 0.925 | 0.888 | 0.093 | \[0.073, 0.115\] | 0.065 |
| fit_2 | 301 | ULSM | 21 | 90.600 | \< .001 | 0.931 | 0.897 | 0.096 | \[0.073, 0.120\] | 0.059 |

## Print the fit indices in Markdown format

Expand All @@ -112,3 +114,35 @@ print(fit_table, format = "markdown")
#> |:-----|:----:|:---------:|:----:|:--------:|:--------:|:-----:|:-----:|:-----:|:--------------:|:-----:|
#> |fit_1 | 301 | MLR | 21 | 87.132 | < .001 | 0.925 | 0.888 | 0.093 | [0.073, 0.115] | 0.065 |
#> |fit_2 | 301 | ULSM | 21 | 90.600 | < .001 | 0.931 | 0.897 | 0.096 | [0.073, 0.120] | 0.059 |

## Saving Fit Indices to Word

The `save_table()` function allows you to export the fit indices to a
Word document (.docx) with APA-style formatting and optional templates
for vertical or landscape orientation.

``` r
# Save the fit comparison table to Word
save_table(fit_table, path = "model_fit.docx", orientation = "landscape")
```

The exported document will have a clean and professional format that you
can directly include in reports or presentations.

## Plotting Factor Loadings

You can visualize the factor loadings of your model with the
`plot_factor_loadings()` function. This function creates a dot plot of
standardized factor loadings, with the option to display confidence
intervals for each loading.

``` r
plot_factor_loadings(fit)
```

<img src="man/figures/README-unnamed-chunk-8-1.png" width="100%" />

In this example, plot_factor_loadings() displays the factor loadings for
each item on the respective factors, with confidence intervals. The plot
can be adjusted to automatically scale the x-axis or group items by
factor.
Binary file added man/figures/README-unnamed-chunk-8-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/hexlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9a42e1a

Please sign in to comment.