Skip to content

Commit

Permalink
Merge pull request #103 from sfcheung/devel
Browse files Browse the repository at this point in the history
Update to 0.1.5.6
  • Loading branch information
sfcheung authored Oct 5, 2023
2 parents a38f028 + 471224c commit 13019da
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: semfindr
Title: Influential Cases in Structural Equation Modeling
Version: 0.1.5.5
Version: 0.1.5.6
Authors@R: c(
person(given = "Shu Fai",
family = "Cheung",
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# semfindr 0.1.5.5
# semfindr 0.1.5.6

- Fixed typos in the article on
multiple-group models. (0.1.5.1)
Expand All @@ -19,6 +19,8 @@
- Add `index_plot()` for generating
an index plot for an arbitrary
statistic. (0.1.5.5)
- Make plot functions to work with NAs.
(0.1.5.6)


# semfindr 0.1.5
Expand Down
8 changes: 8 additions & 0 deletions R/est_change_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ est_change_plot <- function(change,
}
x0$gcd <- NULL
x0$row_id <- as.integer(seq_len(nrow(change)))
x0 <- stats::na.omit(x0)
if (nrow(x0) == 0) {
stop("No cases have valid values.")
}
p <- ggplot2::ggplot(data = x0, ggplot2::aes(x = .data[["row_id"]],
y = .data[["change"]]))
p <- p + do.call(ggplot2::geom_point, point_aes)
Expand Down Expand Up @@ -379,6 +383,10 @@ est_change_gcd_plot <- function(change,
if (!missing(parameters)) {
x0 <- x0[x0$param %in% parameters, ]
}
x0 <- stats::na.omit(x0)
if (nrow(x0) == 0) {
stop("No cases have valid values.")
}
p <- ggplot2::ggplot(data = x0,
ggplot2::aes(x = .data[[gcd_name]],
y = .data[["change"]]))
Expand Down
5 changes: 5 additions & 0 deletions R/generic_index_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ index_plot <- function(object,
object <- object[, column, drop = TRUE]
}

object <- object[!is.na(object)]
if (length(object) == 0) {
stop("No cases have valid values.")
}

if (absolute) {
object <- abs(object)
}
Expand Down
15 changes: 15 additions & 0 deletions R/influence_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ gcd_plot <- function(influence_out,
} else {
gcd_label <- "Generalized Cook's Distance"
}
dat <- dat[!is.na(dat$gcd), ]
if (nrow(dat) == 0) {
stop("All cases have gCD missing.")
}
p <- ggplot2::ggplot(dat, ggplot2::aes(.data$row_id, .data$gcd))
p <- p + do.call(ggplot2::geom_point, point_aes)
p <- p + ggplot2::labs(title = gcd_label)
Expand Down Expand Up @@ -432,6 +436,11 @@ gcd_gof_plot <- function(influence_out,
gcd_label <- "Generalized Cook's Distance"
change_label <- "Change in Fit Measure"
}
dat <- dat[!is.na(dat$gcd) &
!is.na(dat$fm), ]
if (nrow(dat) == 0) {
stop("No cases have non-missing values.")
}

point_aes <- utils::modifyList(list(),
point_aes)
Expand Down Expand Up @@ -564,6 +573,12 @@ gcd_gof_md_plot <- function(influence_out,
gcd_label_short <- "gCD"
change_label <- "Change in Fit Measure"
}
dat <- dat[!is.na(dat$gcd) &
!is.na(dat$fm) &
!is.na(dat$md), ]
if (nrow(dat) == 0) {
stop("No cases have valid values.")
}

point_aes <- utils::modifyList(list(shape = 21,
alpha = .50,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![R-CMD-check](https://github.com/sfcheung/semfindr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sfcheung/semfindr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

(Version 0.1.5.5, updated on 2023-10-05, [release history](https://sfcheung.github.io/semfindr/news/index.html))
(Version 0.1.5.6, updated on 2023-10-05, [release history](https://sfcheung.github.io/semfindr/news/index.html))

# semfindr: Finding influential cases in SEM <img src="man/figures/logo.png" align="right" height="150" />

Expand Down
64 changes: 64 additions & 0 deletions tests/testthat/test-nonconvergence_plot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
skip_on_cran()
# Slow tests

library(testthat)
library(lavaan)

mod <-
'
f1 =~ x1 + x2 + x3
f2 =~ x4 + x5 + x6
'
set.seed(154151)
dat <- HolzingerSwineford1939[sample.int(301, 60), ]

fit <- suppressWarnings(lavaan::cfa(mod, dat))

fit_rerun <- lavaan_rerun(fit, to_rerun = 1:20, allow_inadmissible = TRUE, parallel = FALSE)

fit_rerun
out <- influence_stat(fit_rerun)

p <- gcd_plot(out)
test_that("NA in rerun", {
expect_equal(nrow(p$data), 19)
# expect_no_warning(print(p))
})

p <- md_plot(out)
test_that("NA in rerun", {
expect_equal(nrow(p$data), 20)
# expect_no_warning(print(p))
})

p <- gcd_gof_plot(out, "chisq")
test_that("NA in rerun", {
expect_equal(nrow(p$data), 19)
# expect_no_warning(print(p))
})

p <- gcd_gof_md_plot(out, "chisq", circle_size = 35)
test_that("NA in rerun", {
expect_equal(nrow(p$data), 19)
# expect_no_warning(print(p))
})

out <- est_change(fit_rerun)

p <- est_change_plot(out)
test_that("NA in rerun", {
expect_equal(nrow(p$data), 247)
# expect_no_warning(print(p))
})

p <- est_change_gcd_plot(out)
test_that("NA in rerun", {
expect_equal(nrow(p$data), 247)
# expect_no_warning(print(p))
})

p <- index_plot(out, "f1=~x3")
test_that("NA in rerun", {
expect_equal(nrow(p$data), 19)
# expect_no_warning(print(p))
})

0 comments on commit 13019da

Please sign in to comment.