I am currently looking at if there are annual trends in my data. I am doing linear regressions between R and year, and H and Year, as well as between R and H.
However, when I do a linear regression of R against year where year, I get a NA F and P value. When year is y the code works, but I would like to know why the linear model only works one way, and if year as y is valid in this instance for data analysis? Thank you in advance.
DATA:
| year | R | H |
|---|---|---|
| 2000 | 160 | 140 |
| 2001 | 178 | 153 |
| 2002 | 149 | 138 |
| 2003 | 161 | 149 |
| 2004 | 180 | 173 |
| 2005 | 150 | 142 |
| 2006 | 158 | 130 |
| 2007 | 149 | 190 |
| 2008 | 167 | 200 |
| 2009 | 172 | 204 |
Code:
#this has lots of NA outputs
linearmodel<-lm(data$R ~ data$year)
linearmodel
summary(linearmodel)
#this gives output statistics
linearmodel<-lm(data$year ~ data$R)
linearmodel
summary(linearmodel)
Thank you again.
str(data)? If year is a factor then it is not possible to run lm with year as dependent variable - Basti