Problems with ESA with R - findRows()

25 views
Skip to first unread message

Yannick Erb

unread,
Jan 3, 2025, 8:50:44 AMJan 3
to QCA with R
Hi all, 

First of all, I want to wish all of you a Happy New Year!
Second, thanks for accepting me in the group :)

For my current research project, I want to use fsQCA and chose to work with the R package. I have a data set with several conditions and outcome variables. I am running a separate analysis on the conditions for each outcome variable, not considering the other outcome variables. So far, I think I am doing reasonably well. I have managed to run the necessity analysis, create the truth tables, and run a standard sufficiency analysis for each outcome variable. 

I have now turned to ESA and tried to get it working with my data. However, I ran into problems with the findRows() function of the R package that I cannot resolve on my own or by relying on other answers in this group or similar forums. 
My understanding regarding ESA is that I must exclude the SA truth table's CSA, SSR, and INCOH rows before minimizing them. To do so, I can use the findRows() function. When I try to use the findRows() function in my R script, calling it with variables I stored previously (e.g., truth table object), I get the error message "Error: Unkown condition(s) in the expression." Suppose I, however, run it without relying on the stored variables, creating a new truth table based on the data object and a new input string for outcome and conditions. In that case, the function call succeeds and gets the row indexes for CSA, SSR, and INCOH.

As I have several outcome variables and their names might change, I do not want to copy and paste the code or "hardcode" variable names several times in function calls. I'd instead like to loop through my outcome variables and run ESA for each one (as done for the SA). Is this possible with the findRows() function, or am I missing something here?

I have prepared three (long) minimal examples that (hopefully) might help to track down the problem. Please note that I have attached an excerpt of altered input data I have uploaded so as not to disclose my actual data (the analysis results thus may be complete nonsense).

- Example_1: Code excerpt of the script I am running currently that includes a for loop to loop through the outcomes.  "Error: Unkown condition(s) in the expression.". I might have tracked down the error cause. I use temporary variables to create the truth tables that findRows() is called upon. These are stored in the $call element of the object truth table. If I do not store them into the temporary elements before calling findRows() again (line 84,85), I get yet another error stating that there is no currentOutcome and currentNonOutcomeNames element. I have modified the code not to use temporary elements. Now, I have a different error message I cannot understand. See code example 3.
- Example_2: Example of the code without relying on stored variables and "hardcoded" for one of the outcomes.
- Example_3: Example of the code with the second error message "Error in if (admisc::tilde1st(call$outcome)) { : Condition has length > 1". I do not know where I have a condition that is longer than 1. It may concern how I refer to the outcome variable while looping through the list of outcome variables. 

I have no fsQCA experience and only a little experience with R some while ago (
please excuse bad R code). My problems may be rooted in my limited knowledge of R's workings. If this is the case, I'd be happy if someone could point me in the right direction (so that I can solve the problem on my own) or name some material I could find help with.

Thanks to all of you for your help in advance!
Yannick
Example_Cases.csv
Example_3.R
Example_2.R
Example_1.R

Adrian Dușa

unread,
Jan 16, 2025, 4:08:16 AMJan 16
to QCA with R
Dear Yannick,

A bit late, only now having the chance to look at your files.
As far as I understand from your code, you're trying to do automatize the production of truth tables and ESA solutions for three different outcomes.
This is nice from an efficiency point of view, but as you can see it can consume a lot more time and effort to debug than running three separate analysis the classical way.

What happens is, when the truth tables are generated, the command registers the original command, which function findRows() uses to create the truth table for the negation of the outcome.
However, the command is part of a local environment in the function create_truthTables(), for instance:
conditions = currentNonOutcomeNames
and the object "currentNonOutcomeNames" is not available in function run_esa()

I see you're trying to get it from the truth table object:
currentNonOutcomeNames <- get(paste("tt", outcome_name, sep = ""))$call$conditions

but that assumes the (original) object "currentNonOutcomeNames" exists in the local scope, which defeats the command's purpose.

You can have the conditions' names **not** from the "call" component but from the "options" component:
currentNonOutcomeNames <- get(paste("tt", outcome_name, sep = ""))$options$conditions

and get past the findRows() functions, but then you will get an error when assigning "nam3" because you're trying to use an object called "conThreshold" which does not exist in the local scope of function run_esa(), simply because you've made a typo in the formal arguments of the function, calling it "conThreshhold" (note the double "h").

All in all, this kind of automatization might not worth the effort, seems like an unnecessary complication of a simple three separate analyses.

Hope this helps,
Adrian

Yannick Erb

unread,
Jan 17, 2025, 3:59:56 AMJan 17
to QCA with R
Dear Adrian,

Thank you very much for taking the time to look at my problem and the code examples!
You are correct in that I try to "automate" the creation of truth tables and run fsQCA analysis for several outcome variables (in the example, there are three). For our actual dataset, we have several more outcome variables that we want to check, and there are changing outcomes and condition names. Hence, I try to automate as much of the analysis as possible to minimize the effort of rerunning the analysis if we change/update/add/delete values, conditions, or outcomes in the data. 
I will check out your suggestions regarding the "options" component. Thank you also for pointing out the typo when assigning "nam3"!

However, I now see that the automatization I am trying to achieve may be more effort than re-running the analysis manually or recreating truth table objects for the ESA and not using existing ones, as their values may only exist in local environments.

Thank you very much for your helpful answer, the effort you have taken to create and maintain the R package, and your support for the community of its users!

Kind regards,
Yannick

Adrian Dușa

unread,
Jan 17, 2025, 8:45:09 AMJan 17
to Yannick Erb, QCA with R
You're welcome.
For what is worth, once I've modified "options" instead of "call", and corrected the typo, I was able to run the code without any more errors.
I am referring to example 1, did not have the time to go through all three.

Best,
Adrian
--
You received this message because you are subscribed to the Google Groups "QCA with R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qcawithr+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/qcawithr/c6e069c0-c4da-400f-9ae2-d553d39d78f7n%40googlegroups.com.

Christopher Swader

unread,
Jan 17, 2025, 11:19:15 AMJan 17
to Yannick Erb, QCA with R
Dear Yannick, 

If you want to see some extensive automation of this package within R, I have done so in order to create a kind of multiverse analysis using QCA (for robustness purposes). Perhaps some of the code, solutions that I found are useful for you:


Very best, Chris

Reply all
Reply to author
Forward
0 new messages