I have a chunk of R code produced below to simulate data series on two variables with a specified data generating process. There are 1006 observations in each simulation for each variable - 1000 observations for each variable and 3 lags of each variable. The code does generate a data series for two variables but each series has NaNs after the 14th observation or so and the value of the variables increases very fast as the number of observations increases. I want to use the generated data series for further analysis and hence do not want NaNs in the simulated data. Any help to improve this code so that NaNs are avoided would be greatly appreciated.
N <- 100
A1_sequence <- seq(from=0.5,to=1.5,length.out = N)
A1 <- array(data = A1_sequence, dim=c(2,2,100))
A2 <- matrix(c(0.2,1.1,-0.6,0.2), nrow=2, ncol=2)
A2
#> [,1] [,2]
#> [1,] 0.2 -0.6
#> [2,] 1.1 0.2
A3 <- matrix(c(-0.8,1.2,-0.4,0.4), nrow=2, ncol=2)
A4 <- matrix(c(-0.01, 0.02,-0.03,0.05), nrow=2, ncol=2)
p <- 3 # Number of lags
N1 <- 1000+2*p # Number of observations in each simulation
k <- 2 #Number of endogenous variables
x <- matrix(0, k, N1)
myeps1 <- 0.25*rnorm(k)
for( i in (p+1):N1){
for (j in 1:N){
x[,i] <- A1[,,j]%*%x[,i-1] - A2%*%x[,i-2] - A3%*%x[,i-3] - A4%*%((x[,i-1])^3) + myeps1
}
}
If you want to remove the entire row:
If you want to just remove the points and replace them with something like zero:
You can use the
micepackage to impute values, based on others in the column, as well. It won't work forInfor infinite values though.