Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me out a little bit? I am trying to understand this code a little better. Please, walk me through the code and

Can you help me out a little bit? I am trying to understand this code a little better.

Please, walk me through the code and explain what is happening.

#A=0.2 set.seed(1234) w = rnorm(1000,0,sqrt(20)) s1 = c(0.2*cos((2*pi*(1:1000))/50 +.6*pi)) x1 = s1+w plot.ts(x1, main="A=0.2")

#A=2 w = rnorm(1000,0,sqrt(20)) s2 = c(2*cos((2*pi*(1:1000))/50 +.6*pi)) x2 = s2+w plot.ts(x2, main="A=2")

ii acf_x1=acf(x1, main="acf A=0.2") acf_x1$acf[1:10] acf_x2=acf(x2, main="acf A=2") acf_x2$acf[1:10]

#A=.2 fit = lm(x1~time(x1), na.action=NULL) #regress x1 on time par(mfrow=c(3,1)) # plot ACFs acf(x1, 10, main="A=.2") acf(resid(fit), 10, main="detrended") acf(diff(x1), 10, main="first difference")

Problem 2 i) library(astsa) plot.ts(gas, main="oil and gas") lines(oil, col="blue")

ii) n = length(gas) gas1 = gas[1:n/2] gas2 = gas[(n/2+1):n] data.frame(FirstHalf = var(gas1), SecondHalf = var(gas2))

n = length(oil) oil1 = oil[1:n/2] oil2 = oil[(n/2+1):n] data.frame(FirstHalf = var(oil1), SecondHalf = var(oil2)) plot.ts(log(gas), main="log-transformed data") lines(log(oil),col="blue") par(mfrow=c(2,1)) acf(log(gas), main="log-transformed acf gas") acf(log(oil), main="log-transformed acf oil")

iii) ccf(log(gas),log(oil), ylab='CCF(log(gas),log(oil))')

iv) lag.plot(gas, lag=3) lag.plot(oil, lag=3)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The How And Why Of One Variable Calculus

Authors: Amol Sasane

1st Edition

1119043417, 9781119043416

More Books

Students also viewed these Mathematics questions