How to obtain precise p-values in R when using Lavaan for CFA?

Hey everyone! I’m new to R and I’m trying to do a Confirmatory Factor Analysis (CFA) with the Lavaan package. Everything’s going well, but I’ve hit a snag. The p-value in my output is showing up as .000, but I really need the exact value (like .0000009 or whatever it might be).

I’ve already tried a couple things:

format.pval(p, digits=6)
options(digits=10)

But no luck - my output didn’t change. Here’s the code I’m using for the CFA:

my_model <- cfa(model_spec, data = my_dataset, estimator = "WLSMV")
summary(my_model, fit.measures = TRUE, standardized = TRUE)

Any ideas on how to get that full p-value? I’d really appreciate the help! Thanks in advance!

Hey Jack27! I totally get your frustration with those pesky p-values. Have you tried digging into the internals of the lavaan object? There’s a neat trick I stumbled upon recently.

Try this out:

pchisq(my_model@test$stat, df = my_model@test$df, lower.tail = FALSE)

This directly calculates the p-value from the test statistic and degrees of freedom. It’s like peeking under the hood of your CFA model!

What kind of model are you testing, by the way? I’m always curious to hear about different applications of CFA. Maybe your specific model structure has something to do with the p-value precision?

Oh, and pro tip: if you’re doing a lot of CFAs, you might want to look into the semTools package. It has some cool functions for extracting and formatting various fit indices. Could be handy for your future analyses!

hey jack, i had the same issue! try using the ‘fitMeasures()’ function instead of summary(). it gives more precise values. something like:

fitMeasures(my_model, ‘pvalue’)

this should give u the exact p-value ur looking for. hope it helps!

I’ve encountered this problem before, and there’s a solution that worked for me. Instead of using the summary() function, you can access the exact p-value through the lavaan object directly. Try this:

my_model@test$pvalue

This should give you the precise p-value you’re looking for. If you need to format it, you can then use sprintf() or format() to control the number of decimal places. For example:

sprintf(‘%.10f’, my_model@test$pvalue)

This approach bypasses any rounding that might occur in the summary output. Let me know if this helps with your analysis!