首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在R中生成fsqca分析的解表?

如何在R中生成fsqca分析的解表?
EN

Stack Overflow用户
提问于 2020-08-29 18:18:43
回答 1查看 277关注 0票数 0

我使用R.中的QCA包做了fsqca分析,我有精巧的,中间的解决方案,可信的。我想生成一个解决方案表,如下所示:

信贷:285573445

有关更多示例:谷歌图像搜索

你会怎么做?

下面是一个代码示例:

代码语言:javascript
复制
 # Test of conditions and their negations
  QCAfit(fuzzy_data[,2:8], fuzzy_data$AdoptionFuz, necessity = TRUE, names(fuzzy_data[, 2:8]))

  ## sufficiency analysis
  #Creation of the truth table
  TT <- truthTable(fuzzy_data, outcome = "AdoptionFuz",
                   conditions = c("Benefit_EfficiencyFuz", "Benefit_MKGFuz", "Benefit_MarketFuz", 
                                  "Barrier_TechnicsFuz", "Barrier_ConstraintOfferFuz", "Barrier_SuppliersFuz"),
                   incl.cut = 0.9,
                   n.cut = 3,
                   show.cases = TRUE,
                   complete = FALSE,
                   sort.by = c("incl", "n"))

  
  # parsimonious solution
  sol_ps <- minimize(TT, details = TRUE, include ="?")

  
  #intermediary solution
  sol_is <- minimize(TT, details = TRUE, show.cases = TRUE, include = "?", 
                     dir.exp = c("1", "-", "1", "0", "0", "-"))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-08 17:22:57

应用此方法:Ragin,C.C. & Fiss,Peer。(2008年)。净效应分析与构型分析:一个实证检验。重新设计社会调查:模糊集和超越。190-212。

代码语言:javascript
复制
"get_parsimonious_solutions" <- function(solution)
{
  sols <- character()
  for (solution in solution$solution)
    for (item in solution)
      sols <- append(sols, item)
    
    unique(sols)
}

"get_all_intermediary_solutions" <- function(intermediate_qca)
{
  sols <- character()
  for (solution in intermediate_qca$i.sol)
    for (item in solution$solution)
      sols <- append(sols, item)
    
    unique(sols)
}

"get_core_conditions" <-
  function(complete_solution, current_solution)
  {
    # RaginFiss2008
    
    core_conditions <- character()
    # get all possible core solutions
    core_solutions <- get_parsimonious_solutions(complete_solution)
    
    # the current solution is a complete solution, get the conditions
    complete_conditions <- get_conditions(current_solution)
    
    # for each core solutions
    for (core_solution in core_solutions)
    {
      # get core conditions
      core_conditions <- get_conditions(core_solution)
      
      # for each condition
      count <- 0
      for (core_condition in core_conditions)
      {
        # count found in complete condition
        if (core_condition %in% complete_conditions)
        {
          count <- count + 1
        }
      }
      
      # if all conditions found, return those core conditions
      if (count == length(core_conditions))
      {
        return(core_conditions)
      }
    }
    
    # if no core solution found it's a problem!
    errorCondition("No core solution found matching this solution")
  }

"get_conditions" <- function(solution)
{
  # RaginFiss2008
  
  unlist(strsplit(solution, "*", fixed = TRUE))
}

"is_negative_condition" <- function(condition)
{
  startsWith(condition, "~")
}

"get_absolute_condition" <- function(condition)
{
  if (is_negative_condition(condition))
  {
    substring(condition, 2)
  }
}

"make_solution_table" <- function(intermediate_qca)
{
  # RaginFiss2008
  
  # for all complete solutions
  complete_solutions <-
    get_all_intermediary_solutions(intermediate_qca)
  
  # prepare result df: rows are solutions
  header <- intermediate_qca[["tt"]][["options"]][["conditions"]]
  header <-
    append(header, c("Raw coverage", "Unique coverage", "Consistency"))
  solution_table <-
    as.data.frame(matrix(
      ,
      ncol = length(header),
      nrow = length(complete_solutions)
    ))
  names(solution_table) <- header
  row.names(solution_table) <- complete_solutions
  
  # process each complete solution item (can be more than 1)
  for (complete_solution_item in intermediate_qca$i.sol)
  {
    # for each item, process all the solutions
    for (i in 1:length(complete_solution_item$solution[[1]]))
    {
      solution <- complete_solution_item$solution[[1]][i]
      
      # find corresponding parsimonious core solution and its conditions
      core_conditions <-
        get_core_conditions(intermediate_qca, solution)
      
      # for all conditions
      for (condition in get_conditions(solution))
      {
        #print(condition)
        #print(is_negative_condition(condition))
        #print(condition %in% core_conditions)
        # X if neg core
        if ((is_negative_condition(condition)) &&
            (condition %in% core_conditions))
        {
          solution_table[solution, get_absolute_condition(condition)] <- "X"
        }
        # x if neg peripheral
        else if (is_negative_condition(condition))
        {
          solution_table[solution, get_absolute_condition(condition)] <- "x"
        }
        # O if core
        else if (condition %in% core_conditions)
        {
          solution_table[solution, condition] <- "O"
        }
        # o if peripheral
        else
        {
          solution_table[solution, condition] <- "o"
        }
        # (stays empty otherwise)
      }
      
      # add measures
      solution_table[solution, "Raw coverage"] <-
        complete_solution_item[["IC"]][["incl.cov"]][["covS"]][i]
      solution_table[solution, "Unique coverage"] <-
        complete_solution_item[["IC"]][["incl.cov"]][["covU"]][i]
      solution_table[solution, "Consistency"] <-
        complete_solution_item[["IC"]][["incl.cov"]][["inclS"]][i]
    }
  }
  
  # clean solution table, replace NA by empty strings
  solution_table[is.na(solution_table)] <- ""
  
  solution_table
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63650354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档