Question
Write a function in R to generate a series of length T, i.e. from the model x i = x i-1 + w i .
Write a function in R to generate a series of length T, i.e. from the model xi = xi-1 + wi. You can enter the parameter directly and we only have on fixed parameter . Also, the index i should start from 2.
This will be similar to:
randomwalk=function(sigsq,T){ x=rep(0,T) w=rnorm(T,sd=sqrt(sigsq)) for ( i in 2:T){ x[i]=x[i-1]+w[i] } x }
AND
masim=function(thetas, sigsq, T){ q=length(thetas) noise=rnorm(T+q, sd=sqrt(sigsq)) x=c(noise[1:q],rep(0,T)) #put the initial noise terms in and set the rest to zero for (i in (q+1):(T+q)){ #this loop generates the MA series x[i]=thetas %*% noise[i-(1:q)] +noise[i] } x=x[(q+1):(T+q)] #throw away those initial starting points x }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started