Niko24 - 1 month ago 5x

R Question

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:

`library(rgl)`

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])

open3d()

points3d(D$x1, D$y1, D$y, size=3, col="red")

aspect3d()

axes3d()

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

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...

Source (Stackoverflow)

Comments