Difference between forecast and predict function in R -


is there difference between predict() , forecast() functions in r?

if yes, in specific cases should used?

intro

  • predict -- many kinds of r objects (models). part of base library.
  • forecast -- time series. part of forecast package. (see example).

example

#load training data trndata = read.csv("http://www.bodowinter.com/tutorial/politeness_data.csv")  model <- lm(frequency ~ attitude + scenario, trndata)  #create test data tstdata <- t(cbind(c("h1", "h", 2, "pol", 185),                    c("m1", "m", 1, "pol", 115),                    c("m1", "m", 1, "inf", 118),                    c("f1", "f", 3, "inf", 210)))  tstdata <- data.frame(tstdata,stringsasfactors = f) colnames(tstdata) <- colnames(trndata) tstdata[,3]=as.numeric(tstdata[,3]) tstdata[,5]=as.numeric(tstdata[,5])  cbind(obs=tstdata$frequency,pred=predict(model,newdata=tstdata))  #forecast x <- read.table(text='day       sum                     2015-03-04   44                                2015-03-05   46                                2015-03-06   48                                2015-03-07   48                                2015-03-08   58                                2015-03-09   58                                2015-03-10   66                                2015-03-11   68                                2015-03-12   85                                2015-03-13   94                                2015-03-14   98                                2015-03-15  102                                2015-03-16  102                                2015-03-17  104                                2015-03-18  114', header=true, stringsasfactors=false) library(xts) dates=as.date(x$day,"%y-%m-%d") xs=xts(x$sum,dates)  library("forecast") fit <- ets(xs) plot(forecast(fit)) forecast(fit, h=4) 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -