You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在R中使用航空乘客满意度数据集执行对应分析时遇参数错误求助

对应分析(CA)报错排查:"The value of the argument axes is incorrect. ", (tp.R#82): argument is of length zero

我在使用Airline Passenger Satisfaction数据集进行R语言对应分析(Correspondence Analysis)时,遇到如下错误:

The value of the argument axes is incorrect. ", (tp.R#82): argument is of length zero

使用的代码如下:

data <- read.csv("dataset3.csv")

columns_to_include <- c("Type.of.Travel", "Class", "Seat.Comfort", "Cleanliness", "Food.and.Drink", "In.flight.Service", "In.flight.Entertainment", "Baggage.Handling","Satisfaction")

# Subset the data to include only the specified columns
data <- data[1:100, columns_to_include]

cont_table <- table(data$Class, data$Baggage.Handling)
print("Contingency Table - Class vs Satisfaction:")
print(cont_table)

# Perform CA on contingency table
ca_result <- CA(cont_table)


# Visualize CA results
p6 <- fviz_ca_biplot(ca_result,
                     repel = TRUE,
                     title = "CA Biplot - Class vs Satisfaction")
print(p6)

更换变量后问题依然存在,求解决方法。


报错原因及解决方法

这个错误核心是列联表或分析参数不符合对应分析的运行要求,按以下步骤排查:

1. 清理列联表的全0行/列

对应分析不允许列联表存在完全无频数的行或列,先检查并清理:

# 检查全0行/列
row_sums <- rowSums(cont_table)
col_sums <- colSums(cont_table)

# 移除全0行和列
cont_table_clean <- cont_table[row_sums > 0, col_sums > 0]

用清理后的cont_table_clean重新执行CA()分析。

2. 确认依赖包加载正确

确保你用的是FactoMineR包的CA函数,同时加载factoextra以支持可视化:

library(FactoMineR)
library(factoextra)

如果未加载对应包,或误调用其他包的同名函数,会触发参数错误。

3. 检查子集数据的类别分布

你只取了前100行数据,可能导致某个类别在子集中完全缺失,进而生成异常列联表。先查看变量分布:

table(data$Class)
table(data$Baggage.Handling)

如果存在频数为0的类别,要么扩大样本量,要么合并/排除该类别后再生成列联表。

4. 显式指定可视化的坐标轴参数

部分情况下fviz_ca_biplot的默认参数会出问题,显式指定坐标轴维度:

p6 <- fviz_ca_biplot(ca_result,
                     repel = TRUE,
                     title = "CA Biplot - Class vs Satisfaction",
                     axes = c(1,2)) # 指定使用前两个维度
print(p6)

内容的提问来源于stack exchange,提问作者ConnorRK987

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 07:20:09