Hiding output printed by summary lavaan function.

195 views
Skip to first unread message

Alicia FRANCO MARTÍNEZ

unread,
Dec 24, 2019, 7:26:00 AM12/24/19
to lavaan
Hello everyone,

Recently I am trying to use cfa() and summary() functions within a large for loop, so it spends a significant part of the time printing the output from the summary() function. Is there any way to hide this output, without deleting the elements within the object sum?

sum <- summary(fit, standardized = TRUE, fit.measures=TRUE)

I have already tried with invisible(), but I am new in R and do not really know what other alternatives exist...

Thank you in advance!

Alicia.

car...@web.de

unread,
Dec 24, 2019, 8:19:46 AM12/24/19
to lav...@googlegroups.com
What exactly are you trying to achieve? Let's assume you want to extract the chi square value on each iteration, then you can save it into a simple vector and display the results after the loop. The way it is currently written down (sum <-...) won't help you at all, because after the loop sum only stores the results of the last iteration or am I making a mistake here?
Am 24.12.19, 13:26 schrieb "Alicia FRANCO MARTÍNEZ" <alic...@ucm.es>:
Hello everyone,

Recently I am trying to use  cfa() and summary() functions within a large for loop, so it spends a significant part of the time printing the output from the summary() function. Is there any way to hide this output, without  deleting the elements within the object sum ?

sum <- summary(fit, standardized = TRUE, fit.measures=TRUE)

I have already tried with invisible() , but I am new in R and do not really know what other alternatives exist...

Thank you in advance!

Alicia.

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/81692523-66ca-4e53-9ed1-046e76a7d863%40googlegroups.com.

Alicia FRANCO MARTÍNEZ

unread,
Dec 24, 2019, 8:57:59 AM12/24/19
to lavaan
Hello!

I am trying to take some of the values from sum object, correct. Sorry, the problem is not related to the loop structure, I only wrote that example to make it simpler. Actually, I just want to know how to hide the whole output from the console, and just extract each value. However, even if a use this line of code:

pvalue <- summary(fit, standardized = TRUE, fit.measures=TRUE)[["FIT"]][["pvalue"]]

It prints the whole summary. Any way to hide it and still capture the value?

Thanks,

Alicia.

El martes, 24 de diciembre de 2019, 14:19:46 (UTC+1), car...@web.de escribió:
What exactly are you trying to achieve? Let's assume you want to extract the chi square value on each iteration, then you can save it into a simple vector and display the results after the loop. The way it is currently written down (sum <-...) won't help you at all, because after the loop sum only stores the results of the last iteration or am I making a mistake here?
Am 24.12.19, 13:26 schrieb "Alicia FRANCO MARTÍNEZ" <alic...@ucm.es>:
Hello everyone,

Recently I am trying to use  cfa() and summary() functions within a large for loop, so it spends a significant part of the time printing the output from the summary() function. Is there any way to hide this output, without  deleting the elements within the object sum ?

sum <- summary(fit, standardized = TRUE, fit.measures=TRUE)

I have already tried with invisible() , but I am new in R and do not really know what other alternatives exist...

Thank you in advance!

Alicia.

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lav...@googlegroups.com.

Alicia FRANCO MARTÍNEZ

unread,
Dec 24, 2019, 9:11:08 AM12/24/19
to lavaan
Okay! I already found the solution!

quiet <- function(fit) { 
  sink(tempfile()) 
  on.exit(sink()) 
  invisible(summary(fit, standardized = TRUE, fit.measures=TRUE)) 
sum <- quiet(fit)

Thank you anyway, I hope this could help someone in the future!

Alicia.

car...@web.de

unread,
Dec 24, 2019, 9:28:15 AM12/24/19
to lav...@googlegroups.com
You do not need to pull this information from summary. That's probably not what this is for. pvalue <- fitMeasures(fit, "pvalue") does the job much more elegantly. For parameters there is the function parameterEstimates and so on.
Am 24.12.19, 14:57 schrieb "Alicia FRANCO MARTÍNEZ" <alic...@ucm.es>:
Hello!

I am trying to take some of the values from sum object, correct. Sorry, the problem is not related to the loop structure, I only wrote that example to make it simpler. Actually, I just want to know how to hide the whole output from the console, and just extract each value. However, even if a use this line of code:

pvalue <- summary(fit, standardized = TRUE, fit.measures=TRUE)[["FIT"]][["pvalue"]]

It prints the whole summary. Any way to hide it and still capture the value?

Thanks,

Alicia.

El martes, 24 de diciembre de 2019, 14:19:46 (UTC+1), car...@web.de escribió:
What exactly are you trying to achieve? Let's assume you want to extract the chi square value on each iteration, then you can save it into a simple vector and display the results after the loop. The way it is currently written down (sum <-...) won't help you at all, because after the loop sum only stores the results of the last iteration or am I making a mistake here?
Am 24.12.19, 13:26 schrieb "Alicia FRANCO MARTÍNEZ" < alic...@ucm.es>:
Hello everyone,

Recently I am trying to use  cfa() and summary() functions within a large for loop, so it spends a significant part of the time printing the output from the summary() function. Is there any way to hide this output, without  deleting the elements within the object sum ?

sum <- summary(fit, standardized = TRUE, fit.measures=TRUE)

I have already tried with invisible() , but I am new in R and do not really know what other alternatives exist...

Thank you in advance!

Alicia.

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lav...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/81692523-66ca-4e53-9ed1-046e76a7d863%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/fb6b8350-25cb-4ac3-b9ab-6113c541f39d%40googlegroups.com.

Alicia FRANCO MARTÍNEZ

unread,
Dec 24, 2019, 11:24:01 AM12/24/19
to lavaan
Wow, you have just saved me half the lines in the code!

Thank you very very much!

Alicia.
Reply all
Reply to author
Forward
0 new messages