Question

In: Statistics and Probability

I have questions on how to do this in R/Rstudio or smoothing methods. I have been...

I have questions on how to do this in R/Rstudio or smoothing methods. I have been struggling with using the codes. I have been practicing and tryign to do it, but I am really unsure at where I am with it. Just need something to compare it too! I don't understand why there isn't any information under the demand section!

(1) A memo written to the Chief Operations Officer of Transantiago that describes the model and method and presents the 3-day forecast (March 22, 23 and 24) at 15-minute intervals in as non-technical language as possible.

(2) A technical appendix to your memo that includes:

the name of the model/combination of model used

a description of the method or combination

all estimated equations, etc. associated with constructing the forecasts

the MAPE and MAE for the training period and the validation period

forecasts for the future period (March 22-24) at 15-minute intervals

a graph showing the fit of the final model for the entire period (including training, validation and future), fitted using the combined training and validation data

any additional information that would be useful in understanding or recreating your forecast

a list of any references consulting in preparing your answer

DATE TIME DEMAND
22-Mar-05 6:30
22-Mar-05 6:45
22-Mar-05 7:00
22-Mar-05 7:15
22-Mar-05 7:30
22-Mar-05 7:45
22-Mar-05 8:00
22-Mar-05 8:15
22-Mar-05 8:30
22-Mar-05 8:45
22-Mar-05 9:00
22-Mar-05 9:15
22-Mar-05 9:30
22-Mar-05 9:45
22-Mar-05 10:00
22-Mar-05 10:15
22-Mar-05 10:30
22-Mar-05 10:45
22-Mar-05 11:00
22-Mar-05 11:15
22-Mar-05 11:30
22-Mar-05 11:45
22-Mar-05 12:00
22-Mar-05 12:15
22-Mar-05 12:30
22-Mar-05 12:45
22-Mar-05 13:00
22-Mar-05 13:15
22-Mar-05 13:30
22-Mar-05 13:45
22-Mar-05 14:00
22-Mar-05 14:15
22-Mar-05 14:30
22-Mar-05 14:45
22-Mar-05 15:00
22-Mar-05 15:15
22-Mar-05 15:30
22-Mar-05 15:45
22-Mar-05 16:00
22-Mar-05 16:15
22-Mar-05 16:30
22-Mar-05 16:45
22-Mar-05 17:00
22-Mar-05 17:15
22-Mar-05 17:30
22-Mar-05 17:45
22-Mar-05 18:00
22-Mar-05 18:15
22-Mar-05 18:30
22-Mar-05 18:45
22-Mar-05 19:00
22-Mar-05 19:15
22-Mar-05 19:30
22-Mar-05 19:45
22-Mar-05 20:00
22-Mar-05 20:15
22-Mar-05 20:30
22-Mar-05 20:45
22-Mar-05 21:00
22-Mar-05 21:15
22-Mar-05 21:30
22-Mar-05 21:45
22-Mar-05 22:00
23-Mar-05 6:30
23-Mar-05 6:45
23-Mar-05 7:00
23-Mar-05 7:15
23-Mar-05 7:30
23-Mar-05 7:45
23-Mar-05 8:00
23-Mar-05 8:15
23-Mar-05 8:30
23-Mar-05 8:45
23-Mar-05 9:00
23-Mar-05 9:15
23-Mar-05 9:30
23-Mar-05 9:45
23-Mar-05 10:00
23-Mar-05 10:15
23-Mar-05 10:30
23-Mar-05 10:45
23-Mar-05 11:00
23-Mar-05 11:15
23-Mar-05 11:30
23-Mar-05 11:45
23-Mar-05 12:00
23-Mar-05 12:15
23-Mar-05 12:30
23-Mar-05 12:45
23-Mar-05 13:00
23-Mar-05 13:15
23-Mar-05 13:30
23-Mar-05 13:45
23-Mar-05 14:00
23-Mar-05 14:15
23-Mar-05 14:30
23-Mar-05 14:45
23-Mar-05 15:00
23-Mar-05 15:15
23-Mar-05 15:30
23-Mar-05 15:45
23-Mar-05 16:00
23-Mar-05 16:15
23-Mar-05 16:30
23-Mar-05 16:45
23-Mar-05 17:00
23-Mar-05 17:15
23-Mar-05 17:30
23-Mar-05 17:45
23-Mar-05 18:00
23-Mar-05 18:15
23-Mar-05 18:30
23-Mar-05 18:45
23-Mar-05 19:00
23-Mar-05 19:15
23-Mar-05 19:30
23-Mar-05 19:45
23-Mar-05 20:00
23-Mar-05 20:15
23-Mar-05 20:30
23-Mar-05 20:45
23-Mar-05 21:00
23-Mar-05 21:15
23-Mar-05 21:30
23-Mar-05 21:45
23-Mar-05 22:00
24-Mar-05 6:30
24-Mar-05 6:45
24-Mar-05 7:00
24-Mar-05 7:15
24-Mar-05 7:30
24-Mar-05 7:45
24-Mar-05 8:00
24-Mar-05 8:15
24-Mar-05 8:30
24-Mar-05 8:45
24-Mar-05 9:00
24-Mar-05 9:15
24-Mar-05 9:30
24-Mar-05 9:45
24-Mar-05 10:00
24-Mar-05 10:15
24-Mar-05 10:30
24-Mar-05 10:45
24-Mar-05 11:00
24-Mar-05 11:15
24-Mar-05 11:30
24-Mar-05 11:45
24-Mar-05 12:00
24-Mar-05 12:15
24-Mar-05 12:30
24-Mar-05 12:45
24-Mar-05 13:00
24-Mar-05 13:15
24-Mar-05 13:30
24-Mar-05 13:45
24-Mar-05 14:00
24-Mar-05 14:15
24-Mar-05 14:30
24-Mar-05 14:45
24-Mar-05 15:00
24-Mar-05 15:15
24-Mar-05 15:30
24-Mar-05 15:45
24-Mar-05 16:00
24-Mar-05 16:15
24-Mar-05 16:30
24-Mar-05 16:45
24-Mar-05 17:00
24-Mar-05 17:15
24-Mar-05 17:30
24-Mar-05 17:45
24-Mar-05 18:00
24-Mar-05 18:15
24-Mar-05 18:30
24-Mar-05 18:45
24-Mar-05 19:00
24-Mar-05 19:15
24-Mar-05 19:30
24-Mar-05 19:45
24-Mar-05 20:00
24-Mar-05 20:15
24-Mar-05 20:30
24-Mar-05 20:45
24-Mar-05 21:00
24-Mar-05 21:15
24-Mar-05 21:30
24-Mar-05 21:45
24-Mar-05 22:00

Solutions

Expert Solution

The data that you have provided is insufficient, you need to have the demand column fully populated with numbers then only you can go ahead.

And the problem is from the concept called time series analysis.

As in your case "demand" is the dependent variable so you need to have some prior information about it then only you can go ahead with further analysis or you can say forecasting the demand for future.

I am giving you the R-Code for time series analysis.

Just run that code once you get your demand column populated with "numbers".

R-Code:

#Checking presence of trend:

install.packages("devtools")

library(devtools)

#installing trendseason package from github

install_github("abhishekumrawal/trendseason")

library(trendseason)

plot(con_exp, type= "l")

ro.test(con_exp$Consumption..C.)

#Fitting linear trend

model <- lm(con_exp$Consumption..C.~ con_exp$Year, data = con_exp)

abline(lm(con_exp$Consumption..C.~ con_exp$Year, data = con_exp))

model <- lm(con_exp$Consumption..C.~con_exp$Year, data = con_exp)

abline(a = model$coefficients[1], b = model$coefficients[2])

model$coefficients

LSE_trend <- model$fitted.values

#Detrending

detrended <- con_exp$Consumption..C. - LSE_trend

plot(detrended, type = "l")

#Forecasting

X <- c(2001,2002,2003,2004,2005)

model_forecast<- model$coefficients[1] + model$coefficients[2]*X

model_forecast

#2.

case2 <- read.csv("case2.csv")

#i. trending Gross National Income (GNI) per capita based on Purchasing

#Power Parity (PPP) Exchange Rates (ER) measured in current USD

#testing presence of trend:

plot(case2$X.GNI.per.capita..PPP..current.international...., type = "l")

ro.test(case2$X.GNI.per.capita..PPP..current.international....)

#Fitting linear trend:

model <- lm(case2$X.GNI.per.capita..PPP..current.international....

~as.ts(case2$Series.Name), data = case2)

abline(a = model$coefficients[1], b = model$coefficients[2])

LSE_trend <- model$fitted.values

LSE_trend

#Detrending

detrended <- case2$X.GNI.per.capita..PPP..current.international.... - model$fitted.values

detrended2 <- case2$X.GNI.per.capita..PPP..current.international.... - LSE_trend

plot(detrended2, type = "l")

#ii. Population Total

#testing presence of trend:

ro.test(case2$X.Population..total.)

plot(case2$X.Population..total. , type = "l")

#Fitting linear trend:

model <- lm(case2$X.Population..total.

~as.ts(case2$Series.Name), data = case2)

abline(a = model$coefficients[1], b = model$coefficients[2])

LSE_trend <- model$fitted.values

LSE_trend

#Detrending

detrended <- case2$X.Population..total. - model$fitted.values

plot(detrended, type = "l")

#iii. Gross Domestic Product (GDP) (current USD)

#testing presence of trend:

ro.test(case2$GDP..current.US..)

plot(case2$GDP..current.US.. , type = "l")

#Fitting linear trend:

model <- lm(case2$GDP..current.US..

~as.ts(case2$Series.Name), data = case2)

abline(a = model$coefficients[1], b = model$coefficients[2])

LSE_trend <- model$fitted.values

LSE_trend

#Detrending

detrended <- case2$GDP..current.US.. - model$fitted.values

plot(detrended, type = "l")

#iv. iv. Gross Domestic Product (GDP) Growth (annual %)

#testing presence of trend:

ro.test(case2$GDP.growth..annual...)

plot(case2$GDP.growth..annual... , type = "l")

#v.v. Life Expectancy at birth (years)

#testing presence of trend:

case2$X.Life.expectancy.at.birth..total..years..[9] <- NA

y <- as.vector(case2[c(1:8),6])

ro.test(y)

plot(y, type = "l")

#Fitting linear trend:

model <- lm(y ~as.ts(case2[c(1:8),1]), data = case2)

model$coefficients

abline(a = model$coefficients[1], b = model$coefficients[2])

LSE_trend <- model$fitted.values

LSE_trend

#Detrending

detrended <- c(64,64,65,65,65,66,66,66) - LSE_trend

plot(detrended, type = "l")

#3.

#reading data

case3 <- read.csv("case3.csv")

#testing for the presence of trend

ro.test(case3$Sales..in.million.dollars.)

plot(case3, type="l")

plot(MA_trend, type = "l")

#trend estimation using moving average

library(TTR)

MA_trend<-SMA(case3$Sales..in.million.dollars.,5)

?SMA

#detrending

detrended <- case3$Sales..in.million.dollars.- MA_trend

plot(detrended, type = "l")

#forecasting

require(forecast)

plot(forecast(case3$Sales..in.million.dollars., h = 3))

#4.

case4 <- read.csv("case4,5,7.csv")

y <- ts(case4$No..of.Airline.Passangers.in.Thousands,

start = c(1949,1), end = c(1960,12), frequency = 12)

#testing presence of trend

ro.test(y)

plot(y, type = "l")

#Fitting

MA_trend<-SMA(y, 12)

#detrending

detrended <- y- MA_trend

plot(detrended, type = "l")

#Seasonality

library(trendseason)

friedman.test(detrended,12)

#decomposition using OLSE

month <- seasonaldummy(y)

LM <- lm(y~time(y)+month)

plot(LM$fitted.values, type = "l")

plot(forecast(LM$fitted.values, h=5))

#5.

case5 <- read.csv("case4,5,7.csv")

y <- ts(case5$No..of.Airline.Passangers.in.Thousands,

start = c(1949,1), end = c(1960,12), frequency = 12)

#testing presence of trend

ro.test(y)

plot(y, type = "l")

#Fitting

MA_trend<-SMA(y, 12)

#detrending

detrended <- y- MA_trend

plot(detrended, type = "l")

#Seasonality

#library(trendseason)

friedman.test(detrended,12)

#decomposition

decomp <- stl(y, s.window = 12, t.window = 12)

plot(decomp)

#forecasting

#require(forecast)

plot(forecast(decomp, h = 5))

#6.

case6 <- read.csv("case8.csv")

y <- ts(case6$Demand..in.thousand.units.,

start = c(2001,1), end = c(2005,4), frequency = 4)

#testing presence of trend

ro.test(y)

plot(y, type = "l")

#Seasonality

#library(trendseason)

friedman.test(detrended,12)

#decomposition

decomp <- stl(y, s.window = 12, t.window = 12)

plot(decomp)

#forecasting

#require(forecast)

plot(forecast(decomp, h = 2))

#7.

case7 <- read.csv("case4,5,7.csv")

y <- ts(case7$No..of.Airline.Passangers.in.Thousands,

start = c(1949,1), end = c(1960,12), frequency = 12)

#testing presence of trend

ro.test(y)

plot(y, type = "l")

#Fitting

MA_trend<-SMA(y, 12)

#detrending

detrended <- y- MA_trend

plot(detrended, type = "l")

#Seasonality

#library(trendseason)

friedman.test(detrended,12)

#decomposition

decomp <- decompose(y, type = "additive")

plot(decomp)

#forecasting

#require(forecast)

plot(forecast(decomp$x, h = 5))

#8.

case8 <- read.csv("case6.csv")

y <- ts(case8[c(116:1),2],

start = c(2005,4), end = c(2014,11), frequency = 12)

#testing presence of trend

ro.test(y)

plot(y, type = "l")

#Seasonality

#library(trendseason)

friedman.test(detrended,12)

#decomposition

decomp <- decompose(y, type = "additive")

plot(decomp)

#forecasting

#require(forecast)

plot(forecast(decomp$x, h = 5))

Just change my variables to your variables once you get the data !!!


Related Solutions

I have an assignment that must be done on R/R studio R/RStudio - Chapter 4- Correlation...
I have an assignment that must be done on R/R studio R/RStudio - Chapter 4- Correlation and Regression Step 1 – Download and Install the R/RStudio software on your computer. The link and instructions to do that are on Blackboard under Course Information. Step 2 – Access the Data Sets in MyLab through StatCrunch. In chapter 4, a data set called “Used BMW prices 2017” is what we’ll use. Step 3 – When you open the data set in StatCrunch,...
How can I do one-way ANOVA in RStudio?
How can I do one-way ANOVA in RStudio?
How is this done in R-studio? I have been trying to figure it out but I...
How is this done in R-studio? I have been trying to figure it out but I am getting more and more confused. While imprisoned by the Germans during World War II, the English mathematician John Kerrich tossed a coin 10,000 times and obtained 5067 heads. Let p be the probability of a head on a single toss. We wish to check if the data are consistent with the hypothesis that the coin was fair. a) Set up the hypotheses. Why...
I want to cover Quantitative Forecasting Methods linear regression the moving averages smoothing techniques How are...
I want to cover Quantitative Forecasting Methods linear regression the moving averages smoothing techniques How are these used and do they prediction the future
I want to use R markdown to do the following questions and render a pdf for...
I want to use R markdown to do the following questions and render a pdf for all the answers!!! Q1. Suppose we toss 4 coins (each having heads probability = (1/2). Let X denote the random variable: (number of heads) - (number of tails). (a) What is the range of X? (give exact upper and lower bounds along with a line of explanation) (b) What is the probability mass function of (c) What is the cumulative density function of X...
I need to answer these questions in rstudio - Continuous Probability Distributions Question 4: A printer...
I need to answer these questions in rstudio - Continuous Probability Distributions Question 4: A printer manufacturer determines that the time to failure of one of their ink cartridges is an approximately normally distributed random variable with a mean of 5570 pages and a standard deviation of 237 pages. For marketing purposes they wish to offer a warranty to purchasers, but to protect profitability of the company, they wish to set the warranty period so that at most 2% of...
How do you know if a currency is overvalued or undervalued I have 2 questions with...
How do you know if a currency is overvalued or undervalued I have 2 questions with answers that don't seem to be matching: If real exchange rate qUS/qforeign is more than 1, then US currency is said to be undervalued correct? Question 1: You are given the following information. The current dollar-pound exchange rate is $2 per pound. A U.S basket that costs $100 would cost $120 in the United Kingdom. For the next year, the Fed is predicted to...
PYTHON-- how do i change these linkedlist methods into doublylinkedlist methods? A doublylinked list is the...
PYTHON-- how do i change these linkedlist methods into doublylinkedlist methods? A doublylinked list is the same as a linked list, except that each node has a reference to the node after it(next) and the node before it(prev). #adds item to the head of list. def add(self, item): node = Node(item, self.head) self.head = node if self.size == 0: self.tail = node self.size += 1 #appends item to tail of list def append(self, item): node = Node(item) tail = self.head...
Do the assignment in R/RStudio. Copy or compile your results into Word, write any explanations and...
Do the assignment in R/RStudio. Copy or compile your results into Word, write any explanations and turn in the hard copy. You conduct a survey of New Yorkers. The survey uses a stratified sample of 100 employed college graduates and 100 employed high school graduates. Your survey concludes that 70% of college graduates are happy with their job compared to only 60% of high school graduates. a. What is the standard error and margin of error of the estimate for...
I need to figure this out in rstudio how to calculate this for Binomial and Poisson...
I need to figure this out in rstudio how to calculate this for Binomial and Poisson Distributions Type 2 diabetes is becoming increasingly prevalent among the American adult population. Currently, 9.4% of American adults have diabetes (Centers for Disease Control and Prevention News Release, July 18, 2017). Suppose that 1000 American adults are randomly chosen and tested for Type 2 diabetes. Use R to find the following probabilities, assuming that the rate of type 2 diabetes is 9.4%. Your R...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT