[R] multiple regression with dummy variables

franc Li avelox12 at yahoo.com
Fri Aug 27 01:13:19 CEST 2004


Hi I'm a beginner in R, please help...

I'm trying to do regression analysis on a categorical
data to find b's of each Xi.  Essentially, f(x) is the
output, and two independent variables Xd (days of week
(1,2,...,7) and Xwk (week of month
(1,2,...,6)including partial wks).  

So the data looks like this:
f(x) Xd  Xwk
0.03  1   2
0.06  3   1
:
:

I use factor() and contrasts() to produce I.matrix as
such
  2 3 4 5 6 7
1 0 0 0 0 0 0
2 1 0 0 0 0 0
3 0 1 0 0 0 0
4 0 0 1 0 0 0
5 0 0 0 1 0 0
6 0 0 0 0 1 0
7 0 0 0 0 0 1

  2 3 4 5 6
1 0 0 0 0 0
2 1 0 0 0 0
3 0 1 0 0 0
4 0 0 1 0 0
5 0 0 0 1 0
6 0 0 0 0 1

However, when I tried to regress with:

summary(lm(log(y1)~ I(daydum==1) + I(weekdum==1)),
contrast=T)

Error in model.frame(formula, rownames, variables,
varnames, extras, extranames,  : 
        variable lengths differ 

I'm trying to find pairwise regression in order to
find each bi.  Can anyone hlep?  Thanks so much in
advance.

franc




More information about the R-help mailing list