在R中运行线性回归时的警告消息

时间:2019-02-05 22:19:42

标签: r

我正在尝试在R中运行线性回归,但是出现以下错误:

Warning messages:
1: In model.response(mf, "numeric") :
 using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors

代码是:

reg_ex1 <- lm(V45~TotalScore,data = Combineddatainprogresscsv)

值V45和TotalScore均为数字。 Google搜索产生了一个类似的问题,提示csv文件可能带有逗号。但是我不是专家,所以不知道如何检查吗?

谢谢!

共有1300行,所以这只是输出的最后一部分。让我知道您是否需要更多。

    "50", "60", "70", "80", "90", "Compared to others who may have taken this test, how well do you think you scored? - 1"
), class = "factor"), V46 = structure(c(23L, 6L, 4L, 22L, 
4L, 8L), .Label = c("", "0", "1", "10", "11", "12", "13", 
"14", "15", "16", "17", "18", "19", "2", "20", "3", "4", 
"5", "6", "7", "8", "9", "Score"), class = "factor"), TotalScore = c(0L, 
12L, 10L, 9L, 10L, 14L)), row.names = c(NA, 6L), class = "data.frame")

1 个答案:

答案 0 :(得分:0)

似乎您的响应变量V46是一个因素。您可以在粘贴的输出中看到它:V46 = structure(c(23L, 6L, 4L, 22L, 4L, 8L), .Label = c("", "0", "1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "2", "20", "3", "4", "5", "6", "7", "8", "9", "Score"), class = "factor")

我建议将V46转换为字符,然后转换为数字,最后过滤掉将由“得分”级别产生的缺失值。

您绝对应该听取评论中的内容,以便为您提供帮助:)