An open API service indexing awesome lists of open source software.

https://github.com/haziqj/lavaan.bingof

Limited Information Goodness of Fit Tests for Binary Factor Models
https://github.com/haziqj/lavaan.bingof

complex-samples composite-likelihood factor-analysis goodness-of-fit latent-variables pairwise psychometrics r simulation survey-weights

Last synced: 5 months ago
JSON representation

Limited Information Goodness of Fit Tests for Binary Factor Models

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(lavaan.bingof)
library(tidyverse)
```

# lavaan.bingof

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/haziqj/lavaan.bingof/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/haziqj/lavaan.bingof/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/haziqj/lavaan.bingof/branch/main/graph/badge.svg)](https://app.codecov.io/gh/haziqj/lavaan.bingof?branch=main)

![](https://raw.githubusercontent.com/haziqj/lavaan.bingof/main/inst/mult_bern_data.png)

This is the accompanying R package for the article

> Jamil, H., Moustaki, I., & Skinner, C. (2024). Pairwise likelihood estimation and limited-information goodness-of-fit test statistics for binary factor analysis models under complex survey sampling. *British Journal of Mathematical and Statistical Psychology*. (to appear)

This package contains the functions to compute the test statistics and conduct simulation studies described in the above manuscript.
Currently, the package implements the following tests based on univariate and bivariate residuals of a binary factor analysis model:

| | Name | R function | Remarks |
|---|-------------------------|---------------------|--------------------------------------------------|
| 1 | Wald test | `Wald_test()` | Described in Reiser (1996) |
| 2 | Wald test (diagonal) | `Wald_diag_test()` | A more efficient Wald test |
| 3 | Wald test (VCOV free) | `Wald_vcovf_test()` | Described in Maydeu-Olivares and Joe (2005,2006) |
| 4 | Pearson test | `Pearson_test()` | Moment matching approximation |
| 5 | Residual sum of squares | `RSS_test()` | Moment matching approximation |
| 6 | Multinomial test | `Multn_test()` | Moment matching approximation |

## Installation

Install this package from this GitHub repository:

```{r, eval = FALSE}
# install.packages("pak")
pak::pkg_install("haziqj/lavaan.bingof")
library(lavaan.bingof) # load package
```

## Usage

There are three main functionalities of this package:

1. Generate simulated data either from an infinite population or from a finite population using a complex sampling procedure.

2. Obtain the test statistic values, the degrees of freedom of these chi-square variates, and corresponding $p$-values to determine goodness-of-fit.

3. Wrap functions 1 and 2 in a convenient way to perform simulation studies for Type I errors and power.

### Create a simulated data set of ordinal binary responses

The true parameter values are according to the models specified in the research article.

```{r}
(dat <- gen_data_bin(n = 1000, seed = 123))
```

### Obtain the various test statistics and $p$-values

```{r}
# Fit lavaan model using PML estimation
(mod <- txt_mod(model_no = 1))
fit <- lavaan::sem(mod, dat, std.lv = TRUE, estimator = "PML")

# Test statistics
all_tests(fit)
```

### Test statistics under a complex sampling scheme

```{r}
# Simulate a two-stage stratified cluster sampling with 50 PSUs sampled per
# stratum, and 1 cluster sampled within each PSU.
(dat <- gen_data_bin_strcl(population = make_population(1), npsu = 50,
seed = 9423))

# Fit lavaan model and create survey object
fit0 <- lavaan::sem(mod, dat, std.lv = TRUE, estimator = "PML") # ignore wt
fit1 <- lavaan::sem(mod, dat, std.lv = TRUE, estimator = "PML",
sampling.weights = "wt")

# Compare with and without sampling weights
Wald_test(fit0)
Wald_test(fit1) # with sampling weights
```

### Simulation wrapper

```{r}
# Conduct a simulation study based on a 5 factor model (32 repetitions only for
# illustration). Data generated according to a stratified complex sample.
(pc <- parallel::detectCores()) # how many cores do we have?

res <- run_ligof_sims(model_no = 1, nsim = pc, ncores = pc - 2, samp = "strat",
simtype = "type1")
```

```{r}
res
```