Skip to content

Commit dc8666d

Browse files
committed
test lavaan fit interp
1 parent 7de0cc0 commit dc8666d

File tree

3 files changed

+29
-133
lines changed

3 files changed

+29
-133
lines changed

R/interpret_cfa_fit.R

Lines changed: 15 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@
8484
#' dem60 =~ y1 + y2 + y3
8585
#' dem60 ~ ind60 "
8686
#' model <- lavaan::sem(structure, data = PoliticalDemocracy)
87-
#' # interpret(model) # Not working until new performance is up
87+
#' interpret(model)
8888
#' }
89+
#'
8990
#' @references
9091
#' - Awang, Z. (2012). A handbook on SEM. Structural equation modeling.
9192
#'
@@ -246,137 +247,19 @@ interpret.lavaan <- function(x, ...) {
246247
#' @rdname interpret_gfi
247248
#' @export
248249
interpret.performance_lavaan <- function(x, ...) {
249-
table <- data.frame(Name = c(), Value = c(), Interpretation = c(), Threshold = c())
250-
251-
# GFI
252-
if ("GFI" %in% names(x)) {
253-
table <- rbind(
254-
table,
255-
data.frame(
256-
Name = "GFI",
257-
Value = x$GFI,
258-
Interpretation = interpret_gfi(x$GFI),
259-
Threshold = 0.95
260-
)
261-
)
262-
}
263-
264-
# AGFI
265-
if ("AGFI" %in% names(x)) {
266-
table <- rbind(
267-
table,
268-
data.frame(
269-
Name = "AGFI",
270-
Value = x$AGFI,
271-
Interpretation = interpret_agfi(x$AGFI),
272-
Threshold = 0.90
273-
)
274-
)
275-
}
276-
277-
# NFI
278-
if ("NFI" %in% names(x)) {
279-
table <- rbind(
280-
table,
281-
data.frame(
282-
Name = "NFI",
283-
Value = x$NFI,
284-
Interpretation = interpret_nfi(x$NFI, rules = "byrne1994"),
285-
Threshold = 0.90
286-
)
287-
)
288-
}
289-
290-
# NNFI
291-
if ("NNFI" %in% names(x)) {
292-
table <- rbind(
293-
table,
294-
data.frame(
295-
Name = "NNFI",
296-
Value = x$NNFI,
297-
Interpretation = interpret_nnfi(x$NNFI, rules = "byrne1994"),
298-
Threshold = 0.90
299-
)
300-
)
301-
}
302-
303-
# CFI
304-
if ("CFI" %in% names(x)) {
305-
table <- rbind(
306-
table,
307-
data.frame(
308-
Name = "CFI",
309-
Value = x$CFI,
310-
Interpretation = interpret_cfi(x$CFI),
311-
Threshold = 0.90
312-
)
313-
)
314-
}
315-
316-
# RMSEA
317-
if ("RMSEA" %in% names(x)) {
318-
table <- rbind(
319-
table,
320-
data.frame(
321-
Name = "RMSEA",
322-
Value = x$RMSEA,
323-
Interpretation = interpret_rmsea(x$RMSEA),
324-
Threshold = 0.05
325-
)
326-
)
327-
}
328-
329-
# SRMR
330-
if ("SRMR" %in% names(x)) {
331-
table <- rbind(
332-
table,
333-
data.frame(
334-
Name = "SRMR",
335-
Value = x$SRMR,
336-
Interpretation = interpret_srmr(x$SRMR),
337-
Threshold = 0.08
338-
)
339-
)
340-
}
341-
342-
# RFI
343-
if ("RFI" %in% names(x)) {
344-
table <- rbind(
345-
table,
346-
data.frame(
347-
Name = "RFI",
348-
Value = x$RFI,
349-
Interpretation = interpret_rfi(x$RFI),
350-
Threshold = 0.90
351-
)
352-
)
353-
}
354-
355-
# IFI
356-
if ("IFI" %in% names(x)) {
357-
table <- rbind(
358-
table,
359-
data.frame(
360-
Name = "IFI",
361-
Value = x$IFI,
362-
Interpretation = interpret_ifi(x$IFI),
363-
Threshold = 0.90
364-
)
365-
)
366-
}
367-
368-
# IFI
369-
if ("PNFI" %in% names(x)) {
370-
table <- rbind(
371-
table,
372-
data.frame(
373-
Name = "PNFI",
374-
Value = x$PNFI,
375-
Interpretation = interpret_pnfi(x$PNFI),
376-
Threshold = 0.50
377-
)
250+
mfits <- c("GFI", "AGFI", "NFI", "NNFI",
251+
"CFI", "RMSEA", "SRMR", "RFI",
252+
"IFI", "PNFI")
253+
mfits <- intersect(names(x), mfits)
254+
255+
table <- lapply(mfits, function(ind_name) {
256+
.interpret_ind <- match.fun(paste0("interpret_", tolower(ind_name)))
257+
data.frame(
258+
Name = ind_name,
259+
Value = x[[ind_name]],
260+
Interpretation = .interpret_ind(x[[ind_name]])
378261
)
379-
}
262+
})
380263

381-
table
264+
do.call(rbind, table)
382265
}

man/interpret_gfi.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-interpret.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@ if (require("testthat") && require("effectsize")) {
199199
expect_error(interpret_pnfi(0.6, "DUPA"))
200200
expect_error(interpret_rmsea(0.6, "DUPA"))
201201
expect_error(interpret_srmr(0.6, "DUPA"))
202+
203+
skip_on_cran()
204+
skip_if_not_installed("lavaan")
205+
skip_if_not_installed("performance", minimum_version = "0.8.0.1")
206+
207+
structure <- " ind60 =~ x1 + x2 + x3
208+
dem60 =~ y1 + y2 + y3
209+
dem60 ~ ind60 "
210+
model <- lavaan::sem(structure, data = lavaan::PoliticalDemocracy)
211+
int <- interpret(model)
212+
expect_equal(int$Name, c("GFI", "AGFI", "NFI", "NNFI", "CFI", "RMSEA", "SRMR", "RFI", "IFI", "PNFI"))
213+
expect_equal(int$Value,c(0.9666, 0.9124, 0.9749, 1.0001, 1, 0, 0.0273, 0.9529, 1.0001, 0.5199), tolerance = 0.001)
202214
})
203215

204216
test_that("interpret_icc", {

0 commit comments

Comments
 (0)