本文介绍了R线性回归问题:lm.fit(x,y,offset = offset,singular.ok = singular.ok,...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用R进行回归.我有以下代码,导入CSV文件没有问题

I try a regression with R.I have the following code with no problem in importing the CSV file

    dat <- read.csv('http://pastebin.com/raw.php?i=EWsLjKNN',sep=";")
dat # OK Works fine
Regdata <- lm(Y~.,na.action=na.omit, data=dat)
summary(Regdata)

但是,当我尝试回归时,它不起作用.我收到一条错误消息:

However when I try a regression it's not working. I get an error message:

Erreur dans lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  aucun cas ne contient autre chose que des valeurs manquantes (NA)

我所有的CSV文件都是数字,如果单元格"为空,则为"NA"值.某些列不是空的,而另一些行有时是空的,没有NA值...

All my CSV file are numbers and if a "cell" is empty I have the "NA" value. Some column are not empty and some other row are sometimes empty witht the NA value...

所以,即使使用:p,我也不明白为什么会显示错误消息.

So, I don't understand why I get an error message even with :

na.action=na.omit

PS:CSV的数据可在以下位置获得: http://pastebin.com/EWsLjKNN

PS:Data of the CSV are available at:http://pastebin.com/EWsLjKNN

推荐答案

您会收到此错误消息,因为所有数据框行都包含至少一个缺失值.例如,可以使用以下代码进行检查:

You get this error message because all your data frame rows contain al least one missing value. It can be checked for example with this code:

 apply(data,1,function(x) sum(is.na(x)))
 [1] 128 126  82  78  73  65  58  34  31  30  28  30  20  21  12  20  17  16  12  42  50 128

因此,当您使用lm()na.action=na.omit运行回归时,将删除数据框的所有行,并且没有适合回归的数据.

So when you run regression wit lm() and na.action=na.omit all lines of data frame are removed and there are no data to fit regression.

但这不是主要问题.如果提供的数据包含您拥有的所有信息,那么您将尝试仅使用22个观测值并使用165个自变量(X变量)进行回归.自变量的数量必须小于观测值的数量.

But this is not the main problem. If your provided data contains all information you have, then you are trying to apply regression with 165 independent variables (X variables) while having only 22 observations. Number of independent variables have to be less than number of observations.

这篇关于R线性回归问题:lm.fit(x,y,offset = offset,singular.ok = singular.ok,...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 16:02