[R] having a bit of regression trouble

David Winsemius dwinsemius at comcast.net
Thu Jan 26 03:46:06 CET 2012


On Jan 25, 2012, at 5:24 PM, Rampagegrl wrote:

> I got the code for how to do regression without an intercept out of  
> the back
> of my book and the next part of the homework asks me to do it with an
> intercept.  The problem is, Q1 disappears whenever I try.  Here is  
> my code:
>
> Without the intercept:
>
> load("tsa3.rda")
>>
>> Q=factor(rep(1:4,21))
>> reg=lm(log(jj)~0+trend+Q,na.action=NULL)
>> model.matrix(reg)
>    trend Q1 Q2 Q3 Q4
> 1  -10.00  1  0  0  0
> 2   -9.75  0  1  0  0
> 3   -9.50  0  0  1  0
> 4   -9.25  0  0  0  1
> 5   -9.00  1  0  0  0
> ...
>
> now, I'm supposed to add an intercept to the regression model.  I've  
> hit a
> bit of a problem.
>
>> reg=lm(log(jj)~trend+Q,na.action=NULL)
>> model.matrix(reg)
>   (Intercept)  trend Q2 Q3 Q4
> 1            1 -10.00  0  0  0
> 2            1  -9.75  1  0  0
> 3            1  -9.50  0  1  0
> 4            1  -9.25  0  0  1
> 5            1  -9.00  0  0  0
>
> Can you help me get Q1 back?  thanks.

No. You need to figure out why your instructor assigned you this Zen- 
like task and why the answer is as I stated.  And this is not a  
homework help line.

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list