Niko24 Niko24 - 1 year ago 94
R Question

Simulation of timeseries in R

I need to make a simulation in R of the following function:

y[t] = 4 + (9*x[t-1])*y[y-1]+r[t]

I also need to make a 3D plot. I'm new to R, and I therefore find it extremely difficult and hope that someone in here can help me.

This is what I've tried so far:

n <- 3000
x <- runif(n,-1,1)
r <- rnorm(n)
y <- rep(NA,n)
y[1] <- r[1]
for(t in 2:n){
y[t] <- 4 + (9*x[t-1])*y[t-1]+r[t]
D <- data.frame(y=y[-1], x1=x[-n],y1=y[-n])
points3d(D$x1, D$y1, D$y, size=3, col="red")

But I don't know if the simulation is done correctly, and nothing is shown when I plot the data points. I use the

Answer Source

you have y <- 4 + 9*x[t-1])*y[t-1] its rise like geometric progression 10^t ("9" coefficient) ... The problem in "9" and "4" coefficients. you would have "Inf" of "-Inf" most y. The rest 'y' would be huge...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download