代码之家  ›  专栏  ›  技术社区  ›  Shubh

我正在尝试对R中的所有列进行ChISQUARE测试。

  •  1
  • Shubh  · 技术社区  · 7 年前

    我的数据:

    dependent <- c(1,0,1)
    Salutation <- c("MR","MR","MR")
    Gender <- c("MALE","MALE","MALE")
    Profession <- c("BUSINESS","OTHER","BUSINESS")
    Region <- c("South","West","Midwest")
    CUST_RES_CITY <- c("MUMBAI","BANGALORE","BANGALORE")
    Vertical_New <- c("AGENCY 1","AGENCY 1","AGENCY 2")
    VehicleMake  <-c ("SUZUKI","HONDA","VOLKS") 
    model<- c("SWIFT","MOBILIO","POLO")
    Segment <- c("5 to 10 Lacs","10 to 30 Lacs","5 to 10 Lacs")
    
    
    factor.cs <- data.frame(dependent, Salutation ,Gender ,Profession ,Region, CUST_RES_CITY,Vertical_New,VehicleMake ,model,Segment)
    

    以前我有这一块可以做卡方检验,并会从中返回统计数据。

    corr.factor <- factor.cs %>%
    summarise_each(funs(chisq.test(., 
                                   factor.cs[,dependent])$statistic), -one_of(dependent))
    

    现在,由于summary_each被改为summary_at,_all等,所以我试图修改代码

    corr.factor <- factor.cs %>%  
     summarise_all(funs(chisq.test(., factor.cs$dependent)$statistic))
     %>% select(-c("dependent"))
    

    我得到这个错误:

    Error in summarise_impl(.data, dots) : 
      Evaluation error: 'x' and 'y' must have at least 2 levels
    
    0 回复  |  直到 7 年前