1

I am performing a regression and I want to add a year as factor, but my year is just one year (2010) and when I run the equation I get an error:

contrasts<- (tmp, value = contr.funs[1 + isOF[nn]]) : 
contrasts can be applied only to factors with 2 or more levels

My equation:

Lanu <- lm(YFT ~ PR1*factor(DN1)*factor(NTM1)*factor(AÑO1))

All my factors have the same length, YFT is density and PR1 is depth, factor DN1 is two types of net, and NTM1 is three locations. I want to know if there is interaction in my factors.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 3
    You can't estimate an interaction with year if all your data is from the same year. Trying to include a factor that has exactly one level doesn't make any statistical sense in a regression model like this. – MrFlick Aug 06 '14 at 02:22
  • 1
    You are essentially asking "How do I compare 2010 to other years, when I only have data for 2010?" – thelatemail Aug 06 '14 at 02:30

1 Answers1

4

Since you only have 1 year, year would just be a constant. There would be no identifying variation, which is what @MrFlick is implying in his comment. That's why you get an error if you try a contrast or if you were to try putting it in the lm equation.

Realistically, you should not include year since you do not have any variation in years.

Technically, you could include it in your regression if you were to omit the default constant (commonly called "Beta naught") which is calculated as the mean response when all predictor values are zero. That would be the same as artifically setting your y-intercept to 2010.

It's hard to think of a scenario where that would be advantageous and even then you could not have interaction terms with a constant.

Here are your options:

  1. Forget about including year
  2. Get more years
  3. Use 2010 as your y-intercept: Lanu <- lm(YFT ~ 0 + PR1*factor(DN1)*factor(NTM1)*factor(AÑO1), offset=rep(2010, length(YFT))
  4. Use months, quarters, or some subdivision of the year instead of year

Note that adding 0 + or - 1 to the equation removes the normal intercept and offset creates the artificial year intercept.

Hack-R
  • 22,422
  • 14
  • 75
  • 131