简体   繁体   中英

predict future values based on increasing trend in R

This is the numeric vector which follows an increasing trend (below). What if I want to predict the next 100 values based on this increasing trend? I want the predicted values numerically and not on a graph.

x[,2][1:500]
[1] 409341 409341 409341 409341 409341 409341 409341 411486 422035 422035 422035
[12] 422035 431658 431658 432432 432432 432432 434705 435179 443590 443590 443590
[23] 443590 443590 443590 452983 454948 454948 454948 454948 454948 457306 457306
[34] 458307 458307 458307 458307 458307 458307 458307 458307 458307 458307 458307
[45] 458307 458307 458307 458307 458307 458307 458307 458307 458307 458307 458307
[56] 458307 458307 458307 458307 458307 458307 458307 458307 458307 458307 458307
[67] 458307 458307 458307 458307 458307 458307 458307 458307 458873 458873 462334
[78] 462336 462336 462984 462984 462984 462984 462984 462984 462984 462984 464779
[89] 464779 464953 465905 465905 465905 465905 465905 465905 465905 465905 465905
[100] 465905 465905 465905 465905 465905 465905 465905 465905 465905 465905 465905
[111] 468325 468325 468325 469363 469539 469539 469585 471389 471389 471389 472006
[122] 472006 472431 472431 472431 472431 472431 472431 472431 472431 472431 472431
[133] 472431 472431 472431 472497 472497 472803 472803 473504 473504 473623 473623
[144] 473623 473623 473623 473623 473623 473623 473623 473623 477620 477620 477620
[155] 477620 477620 477620 477620 477620 477620 477620 477620 477620 477620 477620
[166] 479705 480350 482535 482535 482535 482535 482535 482535 482535 482535 482535
[177] 482535 482535 482535 482535 482535 482535 482535 482535 482535 482535 482535
[188] 482535 484568 484568 484568 484568 484568 488477 530816 530816 530816 530816
[199] 530816 530816 531817 531817 531817 531817 531817 531817 531817 531817 531817
[210] 531817 531817 531817 531817 531817 531817 531817 531817 531817 531817 531817
[221] 531817 531817 531817 531817 531817 531817 531817 531817 531817 531817 531817
[232] 531817 531817 531817 531817 531817 531817 531817 531817 531817 531817 531817
[243] 531817 531817 531817 531817 531817 532355 532355 535845 535846 535856 537961
[254] 537961 537961 537961 537961 537961 537961 537961 537961 538907 540396 540396
[265] 540396 540396 540396 541233 541233 541233 541233 541233 541233 541233 541233
[276] 541233 541233 541233 541233 541233 541233 541233 541233 541233 541233 541233
[287] 541233 541233 541233 541233 541233 541233 541233 541233 541233 541233 541233
[298] 541233 541233 541233 541233 541233 541233 541253 541253 541253 541253 541605
[309] 541605 541605 541605 541605 541605 541605 541605 541605 541605 541605 541605
[320] 541605 541745 541745 541745 541745 541745 541745 541745 541745 541745 542430
[331] 542430 542430 542430 542430 542430 542430 542549 542549 542549 542549 542549
[342] 542549 542549 542549 542549 542549 542549 542549 542549 542549 542549 542549
[353] 542549 542549 542549 542549 542549 542549 542549 542549 542549 542549 542549
[364] 542549 542549 542549 542549 542549 542549 542549 542549 542549 542549 542549
[375] 542549 542549 542549 542549 542549 542549 542549 542549 542549 542549 542549
[386] 542549 542549 543678 543678 543678 543678 543846 543846 549949 549949 549949
[397] 549949 549949 549949 549949 549949 549949 551494 551494 552870 552870 552870
[408] 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870
[419] 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870
[430] 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870
[441] 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870
[452] 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870 552870
[463] 552870 552870 552870 555274 555274 555274 555274 555274 555274 555274 555274
[474] 555274 555274 555274 555274 555274 555274 555274 555274 555274 563748 576624
[485] 576624 576624 576624 576624 576624 576624 576624 576624 576624 576624 576624
[496] 576624 576624 576624 590125 590125

If xdata <- x[,2][1:500] , and assuming that your data is time series data, you can use the forecast library which can fit a model in an automated way .

library(forecast)
xdata <- ts(xdata)
fit <- auto.arima(xdata)
# or `fit <- ets(xdata)`
pred_xdata <- forecast(fit, 100)

plot(forecast(fit, 100))

Where pred_xdata contains the next 100 points which you're after.

The plot will look as below:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM