0

I am trying to simulate the forecast (rather than taking mean) using this code:

set.seed(100)
df <- data.frame("lower" = c(-1, 0.5, 0), "upper" = c(0, 2, 4), "mean" = c(-0.5, 1.2, 2.5))
df$simulation <- rnorm(1, df$mean, (df$upper - df$lower) / 2 / 1.96)
df
#  lower upper mean simulation
#1  -1.0     0 -0.5 -0.6281103
#2   0.5     2  1.2 -0.6281103
#3   0.0     4  2.5 -0.6281103

I get same value in the simulation column.

However, if I provide the vector in the n parameter I get result that looks better:

df$simulation <- rnorm(nrow(df), df$mean, (df$upper - df$lower) / 2 / 1.96)
df
#  lower upper mean simulation
#1  -1.0     0 -0.5 -0.6281103
#2   0.5     2  1.2  1.2503308
#3   0.0     4  2.5  2.4194724

Is the later solution is the right way of doing this?

Bulat
  • 6,869
  • 1
  • 29
  • 52

0 Answers0