Skip to content

Instantly share code, notes, and snippets.

@jmg
Last active October 10, 2017 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmg/40ba43abdc514db6ebc9fe1528726441 to your computer and use it in GitHub Desktop.
Save jmg/40ba43abdc514db6ebc9fe1528726441 to your computer and use it in GitHub Desktop.
library(quantreg)
airq <- airquality
#fit the quantile regression with Ozone formula
fit <- rq(Ozone ~ ., data=airquality)
#create a new dataframe with the values to forecast the Ozone
newdata <- data.frame(Solar.R=201:203, Wind=8:10, Temp=82:84, Month=9, Day=20:22)
#newdata is the parameter to tell the predict function to use the values for making the forecast
fore <- predict(fit, newdata=newdata)
#add the forecasted to the initial dataframe
newdata$Ozone <- fore
fore_newdata <- rbind(airq, newdata)
#show forecast tables
show(fore_newdata)
show(newdata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment