Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R linear regression issue : lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)

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)

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...

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

na.action=na.omit

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

like image 357
S12000 Avatar asked Dec 19 '12 18:12

S12000


1 Answers

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

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.

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.

like image 120
Didzis Elferts Avatar answered Oct 06 '22 00:10

Didzis Elferts