0
$\begingroup$

Let's say I have the following lagged data frame and am trying to predict income for 9/10 using data from 9/09.

dat = data.frame(main_date=c("09/01/2013","09/02/2013","09/03/2013","09/04/2013","09/05/2013","09/06/2013",
                             "09/07/2013","09/08/2013","09/09/2013","09/10/2013"),
                 lag_date=c(NA,"09/01/2013","09/02/2013","09/03/2013","09/04/2013","09/05/2013","09/06/2013",
                              "09/07/2013","09/08/2013","09/09/2013"),
                 income=c(rnorm(10)), status=c(rnorm(10)), avg_temp=c(rnorm(10)))
dat

mod = lm(income ~ status + avg_temp, data=dat)
summary(mod)

(-0.00848) + (0.4272*(0.641)) + (-0.651*(-1.274))

I have my data frame and run a linear model. Then I grab estimates and july data points for my two predictors and calculate for Y manually. However, I was wonder if R had a built in process for generating predictions of this nature or could provide insights into finding an "automated" process for performing this task in R.

$\endgroup$
2
$\begingroup$

If I understand your question, what you're looking for is ?predict, or fitted(mod), depending on whether you have july datapoints or not.

$\endgroup$

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.