Skip to content

Error in lm() function

3 messages · Christofer Bogaso, Mohamed Lajnef, David Winsemius

#
Hi all,

I wanted to have a seasonality study like whether a particular month has
significant effect as compared to others. Here is my data :

0.10499	0	0	1	0	0	0	0	0	0	0	0
0.00259	0	0	0	1	0	0	0	0	0	0	0
-0.06015	0	0	0	0	1	0	0	0	0	0	0
0.10721	0	0	0	0	0	1	0	0	0	0	0
0.03597	0	0	0	0	0	0	1	0	0	0	0
0.10584	0	0	0	0	0	0	0	1	0	0	0
0.02063	0	0	0	0	0	0	0	0	1	0	0
-0.03509	0	0	0	0	0	0	0	0	0	1	0
-0.03485	0	0	0	0	0	0	0	0	0	0	1
0.01632	0	0	0	0	0	0	0	0	0	0	0
0.06844	1	0	0	0	0	0	0	0	0	0	0
-0.01766	0	1	0	0	0	0	0	0	0	0	0
0.00989	0	0	1	0	0	0	0	0	0	0	0
0.11673	0	0	0	1	0	0	0	0	0	0	0
0.01789	0	0	0	0	1	0	0	0	0	0	0
-0.00323	0	0	0	0	0	1	0	0	0	0	0
0.06811	0	0	0	0	0	0	1	0	0	0	0
-0.01292	0	0	0	0	0	0	0	1	0	0	0
-0.12244	0	0	0	0	0	0	0	0	1	0	0
-0.06645	0	0	0	0	0	0	0	0	0	1	0
-0.03355	0	0	0	0	0	0	0	0	0	0	1
0.02308	0	0	0	0	0	0	0	0	0	0	0
-0.11711	1	0	0	0	0	0	0	0	0	0	0
0.06116	0	1	0	0	0	0	0	0	0	0	0
0.02832	0	0	1	0	0	0	0	0	0	0	0
0.01441	0	0	0	1	0	0	0	0	0	0	0
-0.04412	0	0	0	0	1	0	0	0	0	0	0
0.05558	0	0	0	0	0	1	0	0	0	0	0
0.08363	0	0	0	0	0	0	1	0	0	0	0
-0.01063	0	0	0	0	0	0	0	1	0	0	0

i.e. all explanatory variables here are dichotomous. However once I run lm()
i got following error :
Error in model.frame.default(formula = dat[, 1] ~ dat[, -1],
drop.unused.levels = TRUE) : 
  invalid type (list) for variable 'dat[, -1]'

Can anyone please tell me what to do?

Best,
#
Hi Bogaso,

Try this
 vecnames<-names(test[,2:11])
 fmla <- as.formula(paste("test[,1] ~ ", paste(vecnames, collapse= "+")))
res<-lm(fmla)

Regards
M


Bogaso a ?crit :

  
    
#
On Nov 11, 2009, at 7:14 AM, Bogaso wrote:

            
Assuming that dat really is a data.frame, then the error message is  
saying you have attempted to pass most of it (since it is a list)  to  
the rhs of the formula and the lm procedure was expecting a vector or  
vectors. What do you get with:

lm( dat[,1]~. , data = dat)

(It would be preferable for readability and possibly even for code  
correctness to refer to the column name for data[,1].)
Better to post the output of str(dat) , or even better, the output of  
dput(dat).