Instruction: This is the last exam in BMB 620. Complete the following questions in RMarkdown and submitted the generated PDF on Classes by the deadline. Make sure to show both the input and output. 1....

1 answer below »

View more »
Answered Same DayDec 21, 2021

Answer To: Instruction: This is the last exam in BMB 620. Complete the following questions in RMarkdown and...

Subhanbasha answered on Dec 21 2021
125 Votes
BMB 620
BMB 620
## calling packages
library(dplyr)
##
## Attaching package: ’dplyr’
## The following objects are masked from ’package:stats’:
##
## filter, lag
## The following objects are masked from ’package:base’:
##
## intersect, setdiff, setequal, union
library(stringr)
library(tidyr)
library(lubridate)
##
## Attaching package: ’lubr
idate’
## The following objects are masked from ’package:base’:
##
## date, intersect, setdiff, union
library(ggplot2)
library(pwr)
## Warning: package ’pwr’ was built under R version 4.1.2
Question 1
a)
library(forecast)
## Registered S3 method overwritten by ’quantmod’:
## method from
## as.zoo.data.frame zoo
1
## Reading data into R
gg <- gas
# Starting Month data
gg[seq(1, length(gg), by = 12)]
## [1] 1709 1751 1773 1730 1762 1804 1868 1910 1889 1962 1910 1994
## [13] 1994 2057 3345 5919 7778 11569 11704 12354 13260 15117 17243 18839
## [25] 21433 27730 30715 26138 28801 32494 31239 32791 35567 37541 40459 35592
## [37] 38963 37059 39975 41600
# Ending Month data
gg[seq(12, length(gg), by = 12)]
## [1] 1825 1878 1910 1910 2026 1984 2015 2057 2142 2110 2205 2247
## [13] 2384 3461 6288 8154 10829 12253 13116 14312 16498 18488 19795 21930
## [25] 25248 32445 28729 30234 34514 32142 34879 37958 39995 42528 36016 38698
## [37] 39606 43736 38410
# Frequency of data
frequency(gg)
## [1] 12
b).
# Plotting time series data
plot(gas)
2
Time
ga
s
1960 1970 1980 1990
0
20
00
0
40
00
0
60
00
0
#By observing the above plot of time series there it presents the trend component there is no seasonality in
the data and also cyclic variations.
c).
# Smoothing the time series data
plot(smooth(gas,kind = c("3RS3R")))
3
Time
sm
oo
th
(g
as
, k
in
d
=
c
("
3R
S
3R
")
)
1960 1970 1980 1990
0
20
00
0
40
00
0
60
00
0
d).
# Decomposing the data
plot(decompose(gas))
4
0
30
00
0
ob
se
rv
ed
10
00
0
40
00
0
tr
en
d

40
00
0
40
00
se
as
on
al

10
00
0
0
10
00
0
1960 1970 1980 1990
ra
nd
om
Time
Decomposition of additive time series
From the decomposition of the time series data there is present the trend which is from some
year it has going up. There is also presence of random fluctuations as well
Question 2
a)
tay_dat <- taylor
# Plotting the time series data
plot(taylor)
5
Time
ta
yl
or
2 4 6 8 10 12
20
00
0
25
00
0
30
00
0
35
00
0
By observing the above plot of time series there it presents the trend, seasonality and random
component there is no cyclical variation in the data need to normalize the data that means
difference the data as to get the formatted data.
b).
# single exponential smoothing
ses.goog <- ses(tay_dat, h = 100)
# printing result
plot(ses.goog)
6
Forecasts from Simple exponential smoothing
2 4 6 8 10 12
10
00
0
20
00
0
30
00
0
40
00
0
#The single exponential method is used here and from the above plot the model was builed and forsacted for
the future but those are not actual predictions it is giving single line of forecast need to go advance methods.
c).
# forecasting the data
fore <- forecast(ses.goog,10)
plot(fore)
7
Forecasts from Simple exponential smoothing
2 4 6 8 10 12
10
00
0
20
00
0
30
00
0
40
00
0
d)
# holtwinters method
taylorforecasts <- HoltWinters(tay_dat, beta=FALSE, gamma=FALSE)
print(taylorforecasts)
## Holt-Winters exponential smoothing without trend and without seasonal component.
##
## Call:
## HoltWinters(x = tay_dat, beta = FALSE,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here
April
January
February
March
April
May
June
July
August
September
October
November
December
2025
2025
2026
2027
SunMonTueWedThuFriSat
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30