Write r functions for forecasting future values

Assignment Help Computer Engineering
Reference no: EM131009000

In this assignment, you will write R functions for forecasting future values of a time series, and apply them to observations on numbers of deaths and maximum temperatures in Houston, Texas. Doing this will provide more practice in basic R programming, and on the use of data frames and of subscripts that are numeric or logical vectors.

The data is derived from that distributed by the U.S. National Morbidity Mortality Air Pollution Study, NMMAPS, with some strangely missing temperature values filled in by reference to www.wunderground.com. I have provided data from 1994-01-01 to 2000-12-31 as a file on the course web page, which may be read as a data frame as follows:

houston <- read.table("https://www.cs.utoronto.ca/~radford/csc120/houston",head=TRUE)

The rows of this data frame have data for successive days, with the row names being the dates. The column names are as follows:

deaths Number of deaths in Houston that day tmax Maximum temperature that day, in degrees Farenheit day_of_year Day of the year, starting at 1 for January 1 day_of_week Day of the week, 1 to 7, with 1=Sunday month Month day is in, 1 to 12, with 1=January

We wish to forecast the number of deaths and the maximum temperature for each day, based only on data before that day, except that when forecasting the number of deaths on a day, we may use the maximum temperature for that day, as well as previous days. (Of course, if we actually wished to forecast the number of deaths beforehand using the same day's maximum temperature, we'd have to substitute a temperature forecast for the actual temperature, but we won't worry about that for this assignment.)

Once you have produced forecasts for each day, you will produce plots of the forecasts, the actual values, and the errors in the forecasts. You will also evaluate how good these forecasts were in terms of the average absolute value of the error.

You should write several functions for forecasting the value of some variable on a single day. All these functions should take as their first arguments a data frame, containing variables that may be used in making the forecast, and as their second argument a series of past values for the variable being forecast (which will have at least one past value, and for some functions will have to have more than one past value). This forecasting function should return a forecast for the next value in this series. The data frame will have at least as many rows as the length of the series plus one (so there will be values for the day for which the forecast is being made). The data frame may have additional rows, but they should not be looked at when making the forecast for this day.

You should write several forecasting functions of this sort, which make forecasts as follows:

forecast_previous The value for the immediately previous day forecast_week_ago The value seven days previous forecast_mean The average of all previous values forecast_mean14 The average of the values on the 14 previous days forecast_same_day_of_week Average of previous days that are the same day of the week forecast_same_month Average of previous days that are the same month forecast_similar_tmax For forecasting deaths only. The average of previous days for which the maximum temperature was no more than 4 degrees different from the maximum temperature this day

Note that the first four functions above (which should be very simple) will not actually look at the data frame that they are given as their first argument.

You should also write a function called predictions, which makes forecasts for all days from some start index to the last day for which data is provided. This function will take as its arguments a function to use for forecasting, a data frame with values that may be used for forecasting, the series of values for which forecasts are to be made, and the start point for making forecasts of this series. It should return a vector of forecasts for values in the series from the specified start point to the end.

These functions (plus the predictions2 function described below) should be defined in a script file that does nothing except define these functions, since these functions are of general use, perhaps for other data sets than the one we are using for this assignment.

In another script file, you should read in the Houston data (with the command shown above), and make forecasts for the numbers of deaths and maximum temperatures in Houston. You should start your forecasts at the beginning of the third year of the data provided, so that all forecasts will have at least two years of data available (though not all the forecasting functions above will use all this data). In other words, you should set the "start" argument for predictions to 365 + 365 + 1 (since 1994 and 1995 are not leap years); this should result in your making predictions for 1827 days.

You should make predictions for the numbers of deaths with each of the seven forecasting functions described above, and for maximum temperatures with the first six. For each of these 13 forecasts, you should produce (and hand in) a set of four plots - put together in one big plot, by using par(mfrow=c(2,2)) - which show the actual values versus time index, the forecasts of these values vesus time index, the errors in these forecasts versus time index, and the errors in these forecasts versus day of the year. These plots should have appropriate titles that identify what they show. You may find it convenient to write a function that calls predictions and makes these plots, which should be defined in this script file, not the one with general funtions definitions, since it is specific to this assignment.

You should also output the average absolute value of the error for each of these forecasts.

Finally, you should try a more elaborate forecasting method, in which you first make forecasts with some method, and then try to use another method to forecast the error in the first method. The idea is that if you can manage to forecast the error well, you can get a better forecast by just adding the forecasted error to the original prediction.

You should write a predictions2 function that does this. It should take two forecasting functions are arguments, along with a data frame of variable to use, a series of values to forecast, and two starting points, the second of which is later than the first. It should use the first forecasting function and the first starting point to make a first set of forecasts, then find the errors in these forecasts, and try to forecast these errors with the second forecasting function, starting at the second starting point. It should return forecasts (starting at the second starting point) that are equal to the first forecasts plus the forecast error in these forecasts.

You should try out predictions2 for predicting deaths, with the first forecasting function being forecast_same_month and the second being forecast_similar_tmax, and produce plots and output as for the other forecasts.Your email should have the following attachments:

The R script file containing your function definitions, called a2funs.r
The R script file that makes predictions for the houston data set, as described in the handout, called a2script.r
PDF files produced by the script, containing the set of four plots that the handout says to produce for each forecasting method and each quantity (deaths or tmax). You can attach 14 PDF files, or it's OK to attach one PDF file that has all the plots (created with pdf("a2plots.pdf"); stuff to make all plots; dev.off()). The text output of this script, which should give the average of the absolute value of the error for each of the forecasting methods. You may omit this if you show this information in the titles of the plots.

You can create a text file with the text output by creating a text file with File > New File > Text File in RStudio, then copying and pasting into it.

You can create a file with a plot using the Export menu in the RStudio plot window (choose "as PDF"). You can move back and forth between multiple plots using the left and right arrows in the plot window.

Attachment:- untitled.rar

Reference no: EM131009000

Questions Cloud

Problem regarding the snoring : According to the British United Provident Association (BUPA), a major health care provider in the U.K., snoring can be an indication of sleep apnea which can cause chronic illness if left untreated. In the U.S.A., the National Sleep Foundation rep..
Provide the accounting entry for the price variance : Compute the material price variance for Jan 15, 20XX - provide the accounting entry for the price variance.
Problem regarding the telemarketing : Telemarketers continue to attempt to reach consumers by calling landline phone numbers. According to estimates from a national 2003 survey,based on face-to-face interviews in 16,677 households, approximately 58.2% of U.S. adults have both a landli..
Problem regarding the employee benefits : Fifty-six percent of all American workers have a workplace retirement plan, 68% have health insurance, and 49% have both benefits. If we select a worker at random:
Write r functions for forecasting future values : you will write R functions for forecasting future values of a time series, and apply them to observations on numbers of deaths and maximum temperatures in Houston, Texas.
Garage and a pool independent events : Real estate, part 2. In the real estate research described in Exercise 29, 64% of homes for sale have garages, 21% have swimming pools, and 17% have both features. a) What is the probability that a home for sale has a garage, but not a pool?
Compare person-centered theory with maslow hierarchy of need : Write a 700- to 1050-word paper analyzing the humanistic approaches to personality. Your paper should cover the following areas: Compare person-centered theory with Maslow's Hierarchy of needs
International food survey : International food survey, part 2. Look again at the data from the Gf K Roper Worldwide survey on food attitudes in Exercise 45. a) If we select a respondent at random, what's the probability we choose a person between 13 and 19 years old who ag..
Brief description of the psychological test : Brief description of the psychological test that you were assigned. Then, explain one challenge to reliability and validity in using, interpreting or incorporating this psychological test in your future professional practice

Reviews

Write a Review

Computer Engineering Questions & Answers

  Design traffic light controller as a digital controller

In this assignment, you are asked to design, implement and demonstrate the Traffic Light Controller as a Digital controller as hardware (using remote lab or DSX kit).

  Identifying and describing how specific system used in an

writenbspa 700- to 1050-word paper identifying and describing how specific system used in an organization has

  What address would virtual address 1053 translate to

All numbers are decimal, everything is numbered starting from 0, and all addresses are memory byte addresses. The page size is 1024 bytes.

  Would it always be the result of one''s experience

How do you envision the ways program verification and performance tuning will be accomplished in the future? Will it still be a work of art? Will it always be the result of one's experience? Or do you forecast more and more automatic ways (algorit..

  Write and assemble the programs

Write down and assemble the following programs and include the start and end addresses for all memory addresses. Show results in following format.

  Give three best practices that operating systems designers

provide three best practices that operating systems designers and developers could use to decide on which cpu

  Implement an intrusion detection system in java

You are to implement an intrusion detection system in java - There are some files that you will work from. An example of each and the generic structure of each are provided

  Using outside resources to locate a recent criminal case

using outside resources to locate a recent criminal case dealing with technology and crime write a report that

  Questionwrite down a c program myls that functions like

questionwrite down a c program myls that functions like unix command ls.purposely myls is a program that displays file

  64-bit architecture

How would you design software to do this (Use a maximum of one to two paragraphs of 5-7 sentences each)?

  Get the cylinder class from the base circle class

Get the cylinder class from the base circle class

  Make use of a for loop to step through all 32 bits

The bitwise-manipulation operators perform simultaneous bit manipulations and enable programs to process large quantities of binary information well.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd