[R] Error in lm() function

David Winsemius dwinsemius at comcast.net
Wed Nov 11 15:25:13 CET 2009


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

>
> 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 :
>
>> lm(
> Error in model.frame.default(formula = dat[, 1] ~ dat[, -1],
> drop.unused.levels = TRUE) :
>  invalid type (list) for variable 'dat[, -1]'

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].)
>
> Can anyone please tell me what to do?

Better to post the output of str(dat) , or even better, the output of  
dput(dat).

>
> Best,
>
-- 

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list