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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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