Reputation: 93
I have the following data:
Days Total cases
1 3
2 3
3 5
4 6
5 28
6 30
7 31
8 34
9 39
10 48
11 63
12 70
13 82
14 91
15 107
16 112
17 127
18 146
19 171
20 198
21 258
22 334
23 403
24 497
25 571
26 657
27 730
28 883
29 1024
30 1139
31 1329
32 1635
33 2059
34 2545
35 3105
36 3684
37 4289
38 4778
39 5351
40 5916
41 6729
42 7600
43 8452
44 9210
45 10453
46 11484
47 12370
48 13431
49 14353
50 15724
51 17304
52 18543
53 20080
54 21372
I defined days as 'days' and total cases as 'cases1'. I run the following code:
exp.mod <- lm(log(cases1)~days)
I get a good model with reasonable residuals and p-value.
but when i run the following:
predict(exp.mod, data.frame(days=60))
I get the value of 11.66476, which doesnt seem to be correct.
I need to get the value and also include the predictive plot in the exponential model. Hope that clarifies the issue.
Upvotes: 0
Views: 316
Reputation: 567
I would do it like this:
# predictr cases from n days
exp(predict(exp.mod, list(days=60)))
to predict days to reach n cases, I would do
exp.mod <- lm(log(cases1) ~ days)
a <- exp(exp.mod$coefficients[1])
b <- exp.mod$coefficients[2]
# Prediction for - lets say - 1500 cases
(log(1500) - log(a)) / b
Upvotes: 0
Reputation: 1336
you should consider the EST
models from the forecast
package.
Below an example.
library(dplyr)
library(forecast)
ausair %>% ets() %>% forecast() %>% autoplot()
I suggest you to check the free book of the Prof. Rob J Hyndman and Prof George Athanasopoulos wrote (are the authors of the forecast package).
Upvotes: 1