Here's 2 more examples.
Simulate ARIMA(1,0,0) with constant
#===============================
library(gratis)
library(fpp3)
#===============================
# Simulate ARIMA(1,0,0) with constant
# -----------------------------------
# Y(t) = 150 + 0.7*Y(t-1) + eps(t)
# --------------------------------
constant <- 150.0
phi1 <- 0.7
mean <- (constant / (1.0 - phi1))
mean # unconditional mean (or isolating behaviour) as you look at the graph
#===============================
# Simulation
ar1 <- gratis::arima_model(p = 1, d = 0, q = 0,
  phi = phi1,
  constant = mean,
  sigma = 1
)
ar1_d0 <- gratis::generate(ar1, length = 200, nseries = 1)
ar1_d0
ar1_d0 |>
  autoplot(value) +
  labs(title="ARIMA(1,0,0)+c\nY(t) = 150 + 0.7*Y(t-1) + eps(t)")
tb_m <- ar1_d0
mean(tb_m$value)
# fit ARIMA (as the model is written down)
fit <- ar1_d0 |>
  model('ar1_d0_sim'= ARIMA( value ~ 1 + pdq(1, 0, 0),
                      fixed = list(ar1 = NA, constant = NA), 
                      transform.pars = FALSE,
                      method = "CSS-ML", optim.control = list(maxit = 1000))
  )	
fit
fit$ar1_d0_sim[[1]] # BOTH constant and mean
report(fit)
# estimated unconditional mean
mean_est <- (((fit[[1]][[1]]$fit$par$estimate[2]) / (1.0 - fit[[1]][[1]]$fit$par$estimate[1]))) 
mean_est
# Base R
sim.ts <- as.ts(ar1_d0)
sim.ts |>
  arima( order=c(1,0,0), include.mean = TRUE,
         fixed = list(ar1 = NA, intercept = NA), 
         transform.pars = FALSE,
         method = "CSS-ML", optim.control = list(maxit = 1000)
  )
# library(forecast)
sim.ts |>
  forecast::Arima( order=c(1,0,0), include.constant = TRUE,
                   fixed = list(ar1 = NA, mean = NA), 
                   transform.pars = FALSE,
                   method = "CSS-ML", optim.control = list(maxit = 1000)
  )
Simulate ARIMA(1,1,0) with constant
#===============================
library(gratis)
library(fpp3)
#===============================
# Simulate ARIMA(1,1,0)
# ---------------------
# d(Y(t)) = 150 + 0.7*d(Y(t-1)) + eps(t) See Brockwell Davis (2016) Introduction to Time Series and Forecasting 3rdEdn, p.158
# --------------------------------------
constant <- 150.0
phi1 <- 0.7
mean <- (constant / (1.0 - phi1))
mean # uncondtional mean (or isolating behaviour) as you look at the graph
#===============================
# Simulation
ari1 <- gratis::arima_model(p = 1, d = 1, q = 0,
  phi = phi1,
  constant = 0, # constant = 0
  sigma = 1
)
ari1_d1 <- gratis::generate(ari1, length = 200, nseries = 1) 
ari1_d1
ari1_d1 |>
  dplyr::mutate(value = value + mean) |> # mean is added onto value
  autoplot(value) +
  labs(title="ARIMA(1,1,0)+c\nd(Y(t)) = 150 + 0.7*d(Y(t-1)) + eps(t)\n(1−0.7*B)*y(t) = 150 + e(t), y(t) = Y(t)-Y(t-1)")
tb_m <- ari1_d1 + mean # mean is added onto value
mean(tb_m$value)
# fit ARIMA (as the model is written down)
fit <- ari1_d1 |>
  model('ari1_d1_sim'= ARIMA( value ~ 0 + pdq(1, 1, 0),
                              fixed = list(ar1 = NA), 
                              transform.pars = FALSE,
                              method = "CSS-ML", optim.control = list(maxit = 1000))
  )	
fit
fit$ari1_d1_sim[[1]] # BOTH constant and mean
report(fit)
# Base R
sim.ts <- as.ts(ari1_d1)
b.fit <- sim.ts |>
  stats::arima( order=c(1,1,0),
                fixed = list(ar1 = NA), 
                transform.pars = FALSE,
                method = "CSS-ML", optim.control = list(maxit = 1000)
  )
b.fit
# library(forecast)
f.fit <- sim.ts |>
  forecast::Arima( order=c(1,1,0),
                   fixed = list(ar1 = NA), 
                   transform.pars = FALSE,
                   method = "CSS-ML", optim.control = list(maxit = 1000)
  )
f.fit
The questions being
- Are they simulated correctly?
- Do I add on the mean after the simulation, therefore the constant is not estimated for ARIMA(1,1,0) with constant?
- Is the ARIMA(1,1,0) with constant written down correctly?