I have daily data with logarithmic decreasing trend (around 30-days-data). enter image description here

In excel I'm calculating these data's trendline and with that trendline equation, I'm projecting these values to 365-days data. Then find the sumation of these 365 days' values.

Is there any ways to automize that in R by writing a function or using any package ?


  • $\begingroup$ I don't really understand what you are trying to do. But is it estimating the coefficient of a 30-day trend, then you can regress your data against a 30-day sequence, t<-seq(1,30), and then estimate the regression by $y=\beta_0+\beta_1 t^{-1} + \beta_2 x +\epsilon$ $\endgroup$ – fredrikhs Aug 16 '13 at 7:25
  • $\begingroup$ After I calculate the trend equation as shown in the picture, I would like to find all values with respect to that equation, by writing 31,32,33,...,364,365 into the 'x' and sum all these values. $\endgroup$ – CanCeylan Aug 16 '13 at 7:27

I understand you want to estimate the coefficient of the logarithm of a time trend, and predict the variable 335 days ahead after this. Your variable is $Y$ and the time trend is given by t<-seq(1,30), estimate


Y.predict<-predict(Y.lm, nstep=335)

is this what you want to do?


You can re-estimate the regression every time you have a new datapoint, extract the coefficient (from the intercept and time trend) and run the loop again. # day number n.

t <- seq(1,n)




y <- rep(0,n)

for (i in 1:n){

y[i]<-beta_0+beta_1*log(i) }

  • $\begingroup$ Thanks for your answer. I think your solution is correct, but I couldn't apply it to my problem. How should I assign the variable Y ? I'm reading my data with t <- scan("data.dat"). So that's my sequence, but what will be the predicted variable ? $\endgroup$ – CanCeylan Aug 16 '13 at 7:57
  • 2
    $\begingroup$ Is data.dat your dataset? Then you can just scan and call it Y or X or whatever. Or just import it to your workspace. But t is a time trend, so it has to be a sequence, t<-seq(1,30). You are regressing your dependent variable against a time trend to find the relationship between them. The predicted variable will be your independent variable, which you are scanning in data.dat. Right? $\endgroup$ – fredrikhs Aug 16 '13 at 8:04
  • $\begingroup$ I understand, thank you very much ! But I have, Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "c('double', 'numeric')" $\endgroup$ – CanCeylan Aug 16 '13 at 8:53
  • 1
    $\begingroup$ I just edited my answer, it's supposed to be predict(Y.lm...) did you try that? Sorry for the mistake. $\endgroup$ – fredrikhs Aug 16 '13 at 8:57
  • $\begingroup$ Thanks @fredrikhs, I tried it. One last question, when I printout the Y.predict, it only returns values till 30. How should I get all values until 365 ? $\endgroup$ – CanCeylan Aug 16 '13 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.