Skip to content
Prev 155185 / 398503 Next

lm and time series.

That is the thing. As a new comer to 'R' I don't understand how to write a formula when all I have is a time series. I don't know how to express the independent and dependent variables in a formula when the object is a time series. So please just solve this simple example and I will extrapolate from there.

Say the units of the time series is days and the value at each point is the response. If I wanted to fit a straiight line through the following time series:

y <- 4:7
t <- ts(y)

So this is saying to me something like 4 units were sold on the first day, 5 on the second, 6 on the third, and 7 on the fourth.

So given the time series t I want to find the slope and inercept:

y = m*x + b

with x in days and the respoinse would be the number of units sold. I need to find 'm' and 'b'. If all I have is t (the time series above) then what would be the formula, and for that matter the arguments to lm to give the desired result?

fit <- lm(???)

Thank you.

Kevin
---- stephen sefick <ssefick at gmail.com> wrote: